From 2422d8ac7aa142da2633a4d1b199e566a687e61d Mon Sep 17 00:00:00 2001 From: samizdam Date: Wed, 13 Dec 2017 22:06:40 +0300 Subject: [PATCH 1/2] Add whitelist to phpunit config for enable coverage calculation. --- phpunit.xml.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fc9d411..fc54db1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,4 +15,9 @@ test/ + + + src + + From dfbc399db0441357c692221ce2da7b74b3745b17 Mon Sep 17 00:00:00 2001 From: samizdam Date: Wed, 13 Dec 2017 22:23:10 +0300 Subject: [PATCH 2/2] Add ClientJwtAuthenticator with tests. --- src/Authentication/ClientJwtAuthenticator.php | 63 +++++++++++++++++++ test/Peer/ClientTest.php | 21 +++++++ 2 files changed, 84 insertions(+) create mode 100644 src/Authentication/ClientJwtAuthenticator.php diff --git a/src/Authentication/ClientJwtAuthenticator.php b/src/Authentication/ClientJwtAuthenticator.php new file mode 100644 index 0000000..653e70b --- /dev/null +++ b/src/Authentication/ClientJwtAuthenticator.php @@ -0,0 +1,63 @@ +jwt = $jwt; + $this->authId = $authid; + } + + /** + * Get AuthID + * + * @return mixed + */ + public function getAuthId() + { + return $this->authId; + } + + /** + * Set AuthID + * + * @param mixed $authid + */ + public function setAuthId($authid) + { + $this->authId = $authid; + } + + /** + * Get list supported authentication method + * + * @return array + */ + public function getAuthMethods() + { + return ['jwt']; + } + + /** + * Get authentication message from challenge message + * + * @param ChallengeMessage $msg + * @return AuthenticateMessage + */ + public function getAuthenticateFromChallenge(ChallengeMessage $msg) + { + return new AuthenticateMessage($this->jwt); + } +} \ No newline at end of file diff --git a/test/Peer/ClientTest.php b/test/Peer/ClientTest.php index d96de98..cdf1703 100644 --- a/test/Peer/ClientTest.php +++ b/test/Peer/ClientTest.php @@ -3,6 +3,8 @@ namespace Thruway\Peer; use React\EventLoop\Factory; +use Thruway\Authentication\ClientJwtAuthenticator; +use Thruway\Authentication\ClientWampCraAuthenticator; use Thruway\Transport\ClientTestTransportProvider; class ClientTest extends \PHPUnit_Framework_TestCase @@ -26,4 +28,23 @@ public function testClientSendsHelloMessage() $client->addTransportProvider(new ClientTestTransportProvider()); } + + public function testAddAuthenticators() + { + $client = new Client('some.realm', Factory::create()); + + $this->assertEmpty($client->getAuthMethods()); + + $client->addClientAuthenticator(new ClientJwtAuthenticator('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoaWQiOiJhZG1pbiIsImF1dGhyb2xlcyI6WyJhZG1pbiJdfQ.rgRR61pbyg-qimH1zdh_naLwHz3UOoYRaJA0JPuutC4', + 'someId')); + + $this->assertContains('jwt', $client->getAuthMethods()); + $this->assertNotContains('wampcra', $client->getAuthMethods()); + + $client->addClientAuthenticator(new ClientWampCraAuthenticator('someId')); + + $this->assertContains('jwt', $client->getAuthMethods()); + $this->assertContains('wampcra', $client->getAuthMethods()); + } + } \ No newline at end of file