得到在Rest Assured测试中的401响应代码

huangapple go评论69阅读模式
英文:

Getting 401 response code in rest assured tests

问题

我正在尝试修复我的Rest Assured测试,因为在我添加以下依赖后:

<dependency>
    <groupId>de.ruedigermoeller</groupId>
    <artifactId>fst</artifactId>
    <version>3.0.4-jdk17</version>
</dependency>

现在在每个测试中都出现以下错误:

java.lang.AssertionError:
Expected :200
Actual   :401

我正在使用以下依赖:

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>5.1.1</version>
    <scope>test</scope>
</dependency>

我传递了所需的每个标头,包括使用用户名和密码编码的授权标头。此标头如下:

new Header("Authorization", "Basic XXXXYYYYXXSDSDDS=");

我将非常感谢任何帮助。谢谢。

英文:

Im trying to fix my rest assured test, because after i added

    &lt;dependency&gt;
        &lt;groupId&gt;de.ruedigermoeller&lt;/groupId&gt;
        &lt;artifactId&gt;fst&lt;/artifactId&gt;
        &lt;version&gt;3.0.4-jdk17&lt;/version&gt;
&lt;/dependency&gt;

And now in every single test i get:

> java.lang.AssertionError:
Expected :200
Actual :401

Im using:

 &lt;dependency&gt;
        &lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
        &lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
        &lt;version&gt;5.1.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;

Im passing every header needed including Authorization header with username and password encoded. This header is like this:

new Header(&quot;Authorization&quot;, &quot;Basic XXXXYYYYXXSDSDDS=&quot;);

I will be grateful for any help. Thanks.

答案1

得分: 0

似乎有某些内容覆盖了您的标头。
您可以在 RestAssured 调用中添加 log().all(),以便查看请求标头中是否包含授权标头。
这是解决问题的第一步。

或者,您可以使用以下代码来强制使用预先授权的基本身份验证:

given().auth()
  .preemptive()
  .basic("user1", "user1Pass")
英文:

It looks like something is overriding your headers.
Can you add log().all() to the RestAssured calls so that you can see if you have the Authorization header as part of the request headers?
Thats the first step to solve the issue.

Alternatively you can use this for forcing preemtive basic auth.

given().auth()
  .preemptive()
  .basic(&quot;user1&quot;, &quot;user1Pass&quot;)

huangapple
  • 本文由 发表于 2023年3月7日 23:12:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663767.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定