aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php
diff options
context:
space:
mode:
authorzotlabs <root@sillystring.adeis.uow.edu.au>2017-03-14 09:09:05 +1100
committerzotlabs <root@sillystring.adeis.uow.edu.au>2017-03-14 09:09:05 +1100
commit6c641b1834539c65edb35dd43a6afa7620e73e1c (patch)
treef01fdc61f8728153478524908cf83f45e6083688 /vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php
parentfc533107ed49735aad5ba39bf02b87ed7ac870b6 (diff)
downloadvolse-hubzilla-6c641b1834539c65edb35dd43a6afa7620e73e1c.tar.gz
volse-hubzilla-6c641b1834539c65edb35dd43a6afa7620e73e1c.tar.bz2
volse-hubzilla-6c641b1834539c65edb35dd43a6afa7620e73e1c.zip
move oauth2 to vendor
Diffstat (limited to 'vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php')
-rw-r--r--vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php b/vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php
new file mode 100644
index 000000000..2d901b501
--- /dev/null
+++ b/vendor/bshaffer/oauth2-server-php/test/OAuth2/Storage/AuthorizationCodeTest.php
@@ -0,0 +1,106 @@
+<?php
+
+namespace OAuth2\Storage;
+
+class AuthorizationCodeTest extends BaseTest
+{
+ /** @dataProvider provideStorage */
+ public function testGetAuthorizationCode(AuthorizationCodeInterface $storage)
+ {
+ if ($storage instanceof NullStorage) {
+ $this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
+
+ return;
+ }
+
+ // nonexistant client_id
+ $details = $storage->getAuthorizationCode('faketoken');
+ $this->assertFalse($details);
+
+ // valid client_id
+ $details = $storage->getAuthorizationCode('testtoken');
+ $this->assertNotNull($details);
+ }
+
+ /** @dataProvider provideStorage */
+ public function testSetAuthorizationCode(AuthorizationCodeInterface $storage)
+ {
+ if ($storage instanceof NullStorage) {
+ $this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
+
+ return;
+ }
+
+ // assert code we are about to add does not exist
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertFalse($code);
+
+ // add new code
+ $expires = time() + 20;
+ $success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEUSERID', 'http://example.com', $expires);
+ $this->assertTrue($success);
+
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertNotNull($code);
+ $this->assertArrayHasKey('authorization_code', $code);
+ $this->assertArrayHasKey('client_id', $code);
+ $this->assertArrayHasKey('user_id', $code);
+ $this->assertArrayHasKey('redirect_uri', $code);
+ $this->assertArrayHasKey('expires', $code);
+ $this->assertEquals($code['authorization_code'], 'newcode');
+ $this->assertEquals($code['client_id'], 'client ID');
+ $this->assertEquals($code['user_id'], 'SOMEUSERID');
+ $this->assertEquals($code['redirect_uri'], 'http://example.com');
+ $this->assertEquals($code['expires'], $expires);
+
+ // change existing code
+ $expires = time() + 42;
+ $success = $storage->setAuthorizationCode('newcode', 'client ID2', 'SOMEOTHERID', 'http://example.org', $expires);
+ $this->assertTrue($success);
+
+ $code = $storage->getAuthorizationCode('newcode');
+ $this->assertNotNull($code);
+ $this->assertArrayHasKey('authorization_code', $code);
+ $this->assertArrayHasKey('client_id', $code);
+ $this->assertArrayHasKey('user_id', $code);
+ $this->assertArrayHasKey('redirect_uri', $code);
+ $this->assertArrayHasKey('expires', $code);
+ $this->assertEquals($code['authorization_code'], 'newcode');
+ $this->assertEquals($code['client_id'], 'client ID2');
+ $this->assertEquals($code['user_id'], 'SOMEOTHERID');
+ $this->assertEquals($code['redirect_uri'], 'http://example.org');
+ $this->assertEquals($code['expires'], $expires);
+
+ // add new code with scope having an empty string value
+ $expires = time() + 20;
+ $success = $storage->setAuthorizationCode('newcode', 'client ID', 'SOMEUSERID', 'http://example.com', $expires, '');
+ $this->assertTrue($success);
+ }
+
+ /** @dataProvider provideStorage */
+ public function testExpireAccessToken(AccessTokenInterface $storage)
+ {
+ if ($storage instanceof NullStorage) {
+ $this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
+
+ return;
+ }
+
+ // create a valid code
+ $expires = time() + 20;
+ $success = $storage->setAuthorizationCode('code-to-expire', 'client ID', 'SOMEUSERID', 'http://example.com', time() + 20);
+ $this->assertTrue($success);
+
+ // verify the new code exists
+ $code = $storage->getAuthorizationCode('code-to-expire');
+ $this->assertNotNull($code);
+
+ $this->assertArrayHasKey('authorization_code', $code);
+ $this->assertEquals($code['authorization_code'], 'code-to-expire');
+
+ // now expire the code and ensure it's no longer available
+ $storage->expireAuthorizationCode('code-to-expire');
+ $code = $storage->getAuthorizationCode('code-to-expire');
+ $this->assertFalse($code);
+ }
+}