Skip to content

Commit def08e5

Browse files
committed
Fixed bug in basic auth.
Signed-off-by: Jason Lewis <[email protected]>
1 parent 0f1384d commit def08e5

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

src/Auth/BasicProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function authenticate(Request $request, Route $route)
4747
{
4848
$this->validateAuthorizationHeader($request);
4949

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

tests/Auth/BasicProviderTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,11 @@ public function testInvalidBasicCredentialsThrowsException()
3737
}
3838

3939

40-
/**
41-
* @expectedException \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
42-
*/
43-
public function testNullResponseFromAuthManagerThrowsException()
44-
{
45-
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
46-
47-
$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(null);
48-
49-
$this->provider->authenticate($request, new Route(['GET'], '/', []));
50-
}
51-
52-
5340
public function testValidCredentialsReturnsUser()
5441
{
5542
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
5643

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

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

0 commit comments

Comments
 (0)