diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-07-16 20:35:56 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-07-16 20:35:56 -0400 |
commit | ede1f1d9b0c06a05845f4125d59c97c29b6d9842 (patch) | |
tree | 2fc9f21c586501d43440dace17e71bfb40618bfc /tests/units | |
parent | 12036aa21f4308aca4d816864b357f9627a0f437 (diff) |
Refactoring of Github authentication (oauth url change)
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/AclTest.php | 2 | ||||
-rw-r--r-- | tests/units/OAuth2Test.php | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php index 72c897c0..05e8561e 100644 --- a/tests/units/AclTest.php +++ b/tests/units/AclTest.php @@ -39,6 +39,8 @@ class AclTest extends Base $this->assertFalse($acl->isPublicAction('board', 'show')); $this->assertTrue($acl->isPublicAction('feed', 'project')); $this->assertTrue($acl->isPublicAction('feed', 'user')); + $this->assertTrue($acl->isPublicAction('oauth', 'github')); + $this->assertTrue($acl->isPublicAction('oauth', 'google')); } public function testAdminActions() diff --git a/tests/units/OAuth2Test.php b/tests/units/OAuth2Test.php new file mode 100644 index 00000000..0275f426 --- /dev/null +++ b/tests/units/OAuth2Test.php @@ -0,0 +1,43 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Core\OAuth2; + +class OAuth2Test extends Base +{ + public function testAuthUrl() + { + $oauth = new OAuth2($this->container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + $this->assertEquals('D?response_type=code&client_id=A&redirect_uri=C&scope=f+g', $oauth->getAuthorizationUrl()); + } + + public function testAuthHeader() + { + $oauth = new OAuth2($this->container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + + $oauth->setAccessToken('foobar', 'BeaRer'); + $this->assertEquals('Authorization: Bearer foobar', $oauth->getAuthorizationHeader()); + + $oauth->setAccessToken('foobar', 'unknown'); + $this->assertEquals('', $oauth->getAuthorizationHeader()); + } + + public function testAccessToken() + { + $oauth = new OAuth2($this->container); + $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); + $oauth->getAccessToken('something'); + + $data = $this->container['httpClient']->getData(); + $this->assertEquals('something', $data['code']); + $this->assertEquals('A', $data['client_id']); + $this->assertEquals('B', $data['client_secret']); + $this->assertEquals('C', $data['redirect_uri']); + $this->assertEquals('authorization_code', $data['grant_type']); + + $this->assertEquals('E', $this->container['httpClient']->getUrl()); + } +} |