Skip to content

Commit

Permalink
Fixed bug in basic auth.
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Lewis <jason.lewis1991@gmail.com>
  • Loading branch information
jasonlewis committed Dec 1, 2014
1 parent 0f1384d commit def08e5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Auth/BasicProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function authenticate(Request $request, Route $route)
{
$this->validateAuthorizationHeader($request);

if (is_null($response = $this->auth->onceBasic($this->identifier, $request)) || $response->getStatusCode() === 401) {
if (($response = $this->auth->onceBasic($this->identifier, $request)) && $response->getStatusCode() === 401) {
throw new UnauthorizedHttpException('Basic', 'Invalid authentication credentials.');
}

Expand Down
15 changes: 1 addition & 14 deletions tests/Auth/BasicProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,11 @@ public function testInvalidBasicCredentialsThrowsException()
}


/**
* @expectedException \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public function testNullResponseFromAuthManagerThrowsException()
{
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);

$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(null);

$this->provider->authenticate($request, new Route(['GET'], '/', []));
}


public function testValidCredentialsReturnsUser()
{
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);

$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(new Response('', 200));
$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(null);
$this->auth->shouldReceive('user')->once()->andReturn('foo');

$this->assertEquals('foo', $this->provider->authenticate($request, new Route(['GET'], '/', [])));
Expand Down

0 comments on commit def08e5

Please sign in to comment.