Skip to content

Commit

Permalink
Merge pull request #43 from Hywan/auth_basic_incomplete_credentials
Browse files Browse the repository at this point in the history
`getCredentials` returns null if incomplete
  • Loading branch information
evert committed Mar 30, 2015
2 parents 2b3214a + 4b149f0 commit 42db5f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Auth/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ function getCredentials() {
return null;
}

return explode(':',base64_decode(substr($auth, 6)), 2);
$credentials = explode(':',base64_decode(substr($auth, 6)), 2);

if (2 !== count($credentials)) {
return null;
}

return $credentials;

}

Expand Down
12 changes: 12 additions & 0 deletions tests/HTTP/Auth/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ function testGetCredentials() {

}

function testGetInvalidCredentialsColonMissing() {

$request = new Request('GET','/',array(
'Authorization' => 'Basic ' . base64_encode('userpass')
));

$basic = new Basic('Dagger', $request, new Response());

$this->assertNull($basic->getCredentials($request));

}

function testGetCredentialsNoheader() {

$request = new Request('GET','/',array());
Expand Down

0 comments on commit 42db5f4

Please sign in to comment.