Check basic auth

I want to check my main copyrighted pages. The tamper test works fine. But I am struggling with an authorized login, because I do not know how to set the headers in the test.

I could not find any tips on how to set the headers on $this->call() . The only information I could find was:

 $this->call($method, $uri, $parameters, $cookies, $files, $server, $content); 

and missing headers.

How to easily check basic auth on laravel. Specific: how to set the main auth header for a test request?

I currently have:

 class ExampleTest extends TestCase { public function test401UnauthorizedOnMe() { $response = $this->call('GET', '/api/me'); $this->assertResponseStatus( 401); } public function testCorrectLoginOnMe() { // http://shortrecipes.blogspot.de/2009/12/testing-basic-http-authentication-using.html //send header with correct user and password ie ////YWRtaW46YWRtaW4xMg== is equal to base64_encode( "admin:admin12") $this->request->setHeader( 'Authorization','Basic YWRtaW46YWRtaW4xMg=='); $response = $this->call('GET', '/api/me'); $this->assertResponseStatus(200); } } 

I tried $this->$request->setHeader(); but with this I get an error:

 1) ExampleTest::testCorrectLoginOnMe ErrorException: Undefined property: ExampleTest::$request 
+5
source share
1 answer

Found a solution with HTTP authentication using PHP . This can be used in the $server $this->call() parameter.

Here is my working function:

 public function testCorrectLoginOnMe() { // call( $method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) $this->call('GET', '/api/me', [], [], [], ['PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => 'admin12']); $this->assertResponseStatus( 200 ); } 
+8
source

All Articles