繁体   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