Rest-assured: auth().basic() not working?

Created on 21 Jul 2015  路  6Comments  路  Source: rest-assured/rest-assured

_From [email protected] on November 04, 2012 09:45:53_

What steps will reproduce the problem? 1. I use auth().basic() to send a basic Authorization header

  1. post()
  2. rest assured doesn't send the header What is the expected output? What do you see instead? I expect an Authorization header, but none is sent What version of the product are you using? On what operating system? Rest Assured 1.7, Windows 7 64-bit, Sun JDK 1.6.0_35 Please provide any additional information below. Here's a part of my little unit test:

String httpResponse =
given()
.auth().basic("dave", "password")
.param("folderName", "myFolder")
.param("unpublished", true)
.expect()
.statusCode(200)
.when()
.post("http://localhost:8080/test"
.getBody().asString();

and on the server side, I never receive the Authorization header.

My work around is to roll my own header and that does show up in the request on the server:

String authCookie = ("dave" + ":" + "password");
String authCookieEncoded =
new String(Base64.encodeBase64(authCookie.getBytes()));

String httpResponse =
given()
.header("Authorization", "Basic " + authCookieEncoded)
.param("folderName", "myFolder")
.param("unpublished", true)
.expect()
.statusCode(200)
.when()
.post("http://localhost:8080/test"
.getBody().asString();

_Original issue: http://code.google.com/p/rest-assured/issues/detail?id=202_

Priority-Medium imported bug invalid

Most helpful comment

_From [email protected] on November 04, 2012 21:38:25_

Hi,

auth().basic() expects the server to challenge with a basic auth request. What you're looking for is probably preemptive basic auth which adds the header without being challenged. So use

auth(). preemptive().basic("username", "password") instead.

Status: Invalid

All 6 comments

_From [email protected] on November 04, 2012 21:38:25_

Hi,

auth().basic() expects the server to challenge with a basic auth request. What you're looking for is probably preemptive basic auth which adds the header without being challenged. So use

auth(). preemptive().basic("username", "password") instead.

Status: Invalid

_From [email protected] on November 10, 2012 16:15:36_

Ah, I see. I never knew there was a challenge version of basic authentication, you learn something new every day.

Thanks, web services (and testing them) has never been so easy because of you.

Cheers,
Dave Woldrich

_From [email protected] on November 11, 2012 02:37:14_

Thanks :)

Thanks @johanhaleby

@johanhaleby #951 Seeing multiple HTTP packet in post request.. I have raised this issue.
I am attaching the snapshot of the postman request packet capture
working

shout out to @johanhaleby. I was having issues with Spring Rest Docs not being able to find the Authorization header, adding preemptive() did the trick!

Was this page helpful?
0 / 5 - 0 ratings