-
-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup JWTProvider, added and updated tests
- Loading branch information
Nicolas Cabot
committed
Jul 12, 2014
1 parent
d7e7c46
commit 1dce62e
Showing
13 changed files
with
237 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
phpunit.xml | ||
build | ||
vendor | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,15 +174,31 @@ lexik_jwt_authentication: | |
In your functional tests, create an authenticated client : | ||
|
||
``` php | ||
protected function createAuthenticatedClient($username = '[email protected]') | ||
/** | ||
* Create a client with a default Authorization header. | ||
* | ||
* @param string $username | ||
* @param string $password | ||
* | ||
* @return \Symfony\Bundle\FrameworkBundle\Client | ||
*/ | ||
protected function createAuthenticatedClient($username = 'user', $password = 'password') | ||
{ | ||
$client = static::createClient(); | ||
$client->request( | ||
'POST', | ||
'/login_check', | ||
array( | ||
'username' => $username, | ||
'password' => $password, | ||
) | ||
); | ||
$jwt = $client->getContainer()->get('lexik_jwt_authentication.jwt_encoder')->encode([ | ||
'username' => $username, | ||
]); | ||
$response = $client->getResponse(); | ||
$data = json_decode($response->getContent(), true); | ||
$client->setServerParameter('HTTP_Authorization', sprintf('Bearer %s', $jwt->getTokenString())); | ||
$client = static::createClient(); | ||
$client->setServerParameter('HTTP_Authorization', sprintf('Bearer %s', $data['token'])); | ||
return $client; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,4 +120,4 @@ protected function getEvent() | |
|
||
return $event; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
/** | ||
* JWTEntryPointTest | ||
* | ||
* @author Jérémie Augustin <[email protected]> | ||
*/ | ||
class JWTEntryPointTest extends \PHPUnit_Framework_TestCase | ||
|
@@ -15,11 +16,9 @@ class JWTEntryPointTest extends \PHPUnit_Framework_TestCase | |
public function testStart() | ||
{ | ||
$entryPoint = new JWTEntryPoint(); | ||
|
||
$this->assertInstanceOf('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface', $entryPoint); | ||
|
||
$response = $entryPoint->start($this->getRequest()); | ||
|
||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); | ||
$this->assertEquals(401, $response->getStatusCode(), 'status code should be 401'); | ||
} | ||
|
Oops, something went wrong.