Campoie / rest-assured

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

Basic Authentication Not Being Put in Header #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by tyler.sc...@gmail.com on 25 Jul 2011 at 8:49

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

Original comment by johan.ha...@gmail.com on 2 Aug 2011 at 5:43

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

Original comment by neali...@gmail.com on 15 Jul 2014 at 5:32

GoogleCodeExporter commented 9 years ago
Great this topic save me time investigation what's wrong with basic auth. 

Original comment by TomasLuc...@gmail.com on 6 Jan 2015 at 10:11