簡體   English   中英

其余保證表身份驗證不起作用

[英]Rest-Assured form Authentication not working

我正在嘗試對我的應用程序使用放心的問題,問題是我無法進行身份驗證。

以下是我正在嘗試的代碼

baseURI = "http://localhost:8080/api";
given()
        .auth().form("admin", "admin", new FormAuthConfig("/authentication/", "j_username", "j_password"))
.when()
        .get("/formAuth")
        .then()
        .log().all()
        .statusCode(200);

我也嘗試過以下選項,以下代碼以上沒有任何錯誤401

form("admin", "admin", new FormAuthConfig("/", "j_username", "j_password"))

以下選項不起作用,顯示“無法解析登錄頁面”。 在登錄頁面上檢查錯誤或指定FormAuthConfig。 錯誤

.auth().form("admin", "admin", formAuthConfig().withAutoDetectionOfCsrf())

以下是表格的代碼

<form class="form ng-pristine ng-valid" role="form" ng-submit="login($event)">
                <div class="form-group">
                    <label for="username" translate="global.form.username" class="ng-scope">Login</label>
                    <input type="text" class="form-control ng-pristine ng-valid ng-touched" id="username" placeholder="Your login" ng-model="username" autocomplete="off">
                </div>
                <div class="form-group">
                    <label for="password" translate="login.form.password" class="ng-scope">Password</label>
                    <input type="password" class="form-control ng-pristine ng-untouched ng-valid" id="password" placeholder="Your password" ng-model="password">
                </div>
                <div class="form-group">
                    <label for="rememberMe">
                        <input type="checkbox" id="rememberMe" ng-model="rememberMe" checked="" class="ng-pristine ng-untouched ng-valid">
                        <span translate="login.form.rememberme" class="ng-scope">Automatic Login</span>
                    </label>
                </div>
                <button type="submit" class="btn btn-primary ng-scope" translate="login.form.button">Authenticate</button>
            </form>

以下是使用PostMan的捕獲輸出

URL: http://localhost:8080/api/authentication?cacheBuster=1485280599118
parameter:  j_username:admin
j_password:admin

在v3中似乎有些問題。 從com.jayway.restassured 2.8.0移至io.restassured 3.0.5時,我今天遇到了同樣的問題。 我只是回滾了升級,然后又恢復工作了:/

我相信您需要提供有關如何進行身份驗證調用的更多信息。

當您定義new FormAuthConfig("/authentication/", "j_username", "j_password") ,您要告訴Rest Assured,它應該使用最后兩個參數作為表單參數對/authentication端點進行POST調用。

通常,HTML <form>元素具有一個action屬性,該屬性指示向其發出POST請求的端點,而<input>標記中的name屬性指示應使用的表單參數的鍵。

在您的情況下,HTML表單沒有提供有關如何進行調用的太多信息,因為它可能是使用Javascript處理的。

順便提一句,在定義FormAuthConfig時,啟用日志記錄通常很有用,如下所示:

given().auth()
  .form(
    "admin",
    "admin",
    new FormAuthConfig("/authentication", "j_username", "j_password")
      .withLoggingEnabled())
  // ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM