Rest-assured: Basic Authentication Not Being Put in Header

Created on 20 Jul 2015  路  3Comments  路  Source: rest-assured/rest-assured

_From [email protected] on July 25, 2011 22:49:46_

Running:

@Test
public void testGetProcedureRunsInvalidPassword() {
authentication = basic("jetty", "jetty");
try {
expect().statusCode(200).when().get("http://localhost:10321");
} finally {
RestAssured.reset();
}
}

I would expect the request header to contain an "Authorization" entry with the username and password being colon separated in base64 encoding (Authorization $username:$password.inBase64();) The localhost:10321 bit is for the Eclipse TCP/IP monitor.

The header that gets sent is this instead:

GET / HTTP/1.1
Accept: _/_
Host: localhost:8080
Connection: Keep-Alive
Accept-Encoding: gzip,deflate What version of the product are you using? On what operating system? Rest Assured 1.2.2.2

Mac OS X 10.6.7

Eclipse Helios

Manually adding headers with "given().headers("key", "value") works as expected

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

Priority-Medium imported bug invalid

Most helpful comment

_From [email protected] on August 01, 2011 22:43:39_

It only adds the header when challenged for authentication by the server. If you want to force it to add the header you need to use preemptive basic auth. E.g.

given().auth().preemptive().basic("x", "y"). ..

or

RestAssured.authentication = preemptive().basic("x", "y"). ..

This will add the correct headers to the request even though the server has never challenged.

Status: Invalid

All 3 comments

_From [email protected] on August 01, 2011 22:43:39_

It only adds the header when challenged for authentication by the server. If you want to force it to add the header you need to use preemptive basic auth. E.g.

given().auth().preemptive().basic("x", "y"). ..

or

RestAssured.authentication = preemptive().basic("x", "y"). ..

This will add the correct headers to the request even though the server has never challenged.

Status: Invalid

_From [email protected] on July 15, 2014 10:32:19_

i spent hours trying to get basic auth to work. Thanks to this post on preemptive and my determination, I was able to solve the problem.

_From [email protected] on January 06, 2015 02:11:59_

Great this topic save me time investigation what's wrong with basic auth.

Was this page helpful?
0 / 5 - 0 ratings