salilbc / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

auth().basic() not working? #202

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I use auth().basic() to send a basic Authorization header
2. post()
3. 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 reported on code.google.com by dwoldr...@gmail.com on 4 Nov 2012 at 8:45

GoogleCodeExporter commented 9 years ago
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.

Original comment by johan.ha...@gmail.com on 5 Nov 2012 at 5:38

GoogleCodeExporter commented 9 years ago
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

Original comment by dwoldr...@gmail.com on 11 Nov 2012 at 12:15

GoogleCodeExporter commented 9 years ago
Thanks :)

Original comment by johan.ha...@gmail.com on 11 Nov 2012 at 10:37