简体   繁体   English

其余保证表身份验证不起作用

[英]Rest-Assured form Authentication not working

I am trying to use rest-assured for one of my application the problem is I am not able to authenticate. 我正在尝试对我的应用程序使用放心的问题,问题是我无法进行身份验证。

Following is the code I am trying 以下是我正在尝试的代码

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);

I have tried following options as well, nothing works out 401 error for following and above code 我也尝试过以下选项,以下代码以上没有任何错误401

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

following option is not working, shows Failed to parse login page. 以下选项不起作用,显示“无法解析登录页面”。 Check for errors on the login page or specify FormAuthConfig. 在登录页面上检查错误或指定FormAuthConfig。 error 错误

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

Following is the code for form 以下是表格的代码

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

And following is the captures output using PostMan 以下是使用PostMan的捕获输出

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

Something seems broken in v3. 在v3中似乎有些问题。 I had same issue today when moving from com.jayway.restassured 2.8.0 to io.restassured 3.0.5. 从com.jayway.restassured 2.8.0移至io.restassured 3.0.5时,我今天遇到了同样的问题。 I just rolled back the upgrade and it worked again :/ 我只是回滚了升级,然后又恢复工作了:/

I believe you need to provide more information on how the authentication call is carried out. 我相信您需要提供有关如何进行身份验证调用的更多信息。

When you defined the new FormAuthConfig("/authentication/", "j_username", "j_password") , you're telling Rest Assured that it should make a POST call to an /authentication endpoint using the two last parameters as form params. 当您定义new FormAuthConfig("/authentication/", "j_username", "j_password") ,您要告诉Rest Assured,它应该使用最后两个参数作为表单参数对/authentication端点进行POST调用。

Usually, the HTML <form> element has an action attribute indicating the endpoint to which it will make the POST request and the name attribute in the <input> tags indicate the keys of the form params that should be used. 通常,HTML <form>元素具有一个action属性,该属性指示向其发出POST请求的端点,而<input>标记中的name属性指示应使用的表单参数的键。

In your case, the HTML form doesn't provide much information about how the call is being made, since it's probably handled with Javascript. 在您的情况下,HTML表单没有提供有关如何进行调用的太多信息,因为它可能是使用Javascript处理的。

By the way, just a side note, it's often useful enable logging when defining the FormAuthConfig as follows: 顺便提一句,在定义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