From 0055ab7ad05258b6739f505515aaa04dd630d1cb Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:31:38 -0400 Subject: [feature/oauth] Initial token storage tests PHPBB3-11673 --- tests/auth/fixtures/oauth_tokens.xml | 24 +++++++ tests/auth/provider_oauth_token_storage_test.php | 85 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/auth/fixtures/oauth_tokens.xml create mode 100644 tests/auth/provider_oauth_token_storage_test.php (limited to 'tests/auth') diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml new file mode 100644 index 0000000000..6bf6d22172 --- /dev/null +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -0,0 +1,24 @@ + + + + user_id + session_id + provider + oauth_token + + 1 + foobar + foobar + $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ + 0 + 0 + example@example.com + 0 + 0 + + + + + +
+
\ No newline at end of file diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php new file mode 100644 index 0000000000..ba3a8a65f5 --- /dev/null +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -0,0 +1,85 @@ +db = $this->new_dbal(); + $this->user = $this->getMock('phpbb_user'); + $service_name = 'auth.provider.oauth.service.testing'; + $token_storage_table = 'phpbb_oauth_tokens'; + + // Give the user a session_id that we will remember + $this->session_id = '12345'; + $this->user->data['session_id'] = $this->session_id; + + // Set the user id to anonymous + $this->user->data['user_id'] = ANONYMOUS; + + $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $service_name, $token_storage_table); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/oauth_tokens.xml'); + } + + public function test_retrieveAccessToken() + { + + } + + public function test_storeAccessToken() + { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($token); + + // Confirm that the token is cached + $extraParams = $this->token_storage->retrieveAccessToken()->getExtraParams(); + $this->assertEquals( 'param', $extraParams['extra'] ); + $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() ); + + // Test that the token is stored in the database + $sql = 'SELECT oauth_token FROM phpbb_oauth_tokens + WHERE session_id = \'' . $this->session_id . '\''; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // The token is serialized before stored in the database + $this->assertEquals(serialize($token), $row['oauth_token']); + } + + public function test_hasAccessToken() + { + + } + + public function test_clearToken() + { + + } + + public function test_set_user_id() + { + + } +} \ No newline at end of file -- cgit v1.2.1 From a72951b79902d6512a1e769e23c394395e930870 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:46:08 -0400 Subject: [feature/oauth] Token Storage retrieve access token test PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 39 +++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index ba3a8a65f5..e86d1359d9 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -12,8 +12,10 @@ use OAuth\OAuth2\Token\StdOAuth2Token; class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_case { protected $db; + protected $service_name; protected $session_id; protected $token_storage; + protected $token_storage_table; protected $user; protected function setup() @@ -24,8 +26,8 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->db = $this->new_dbal(); $this->user = $this->getMock('phpbb_user'); - $service_name = 'auth.provider.oauth.service.testing'; - $token_storage_table = 'phpbb_oauth_tokens'; + $this->service_name = 'auth.provider.oauth.service.testing'; + $this->token_storage_table = 'phpbb_oauth_tokens'; // Give the user a session_id that we will remember $this->session_id = '12345'; @@ -34,7 +36,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c // Set the user id to anonymous $this->user->data['user_id'] = ANONYMOUS; - $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $service_name, $token_storage_table); + $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); } public function getDataSet() @@ -42,9 +44,38 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/oauth_tokens.xml'); } - public function test_retrieveAccessToken() + public static function retrieveAccessToken_data() { + return array( + array(null, new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')), null), + array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ), null, null), + array(null, null, 'OAuth\Common\Storage\Exception\TokenNotFoundException'), + ); + } + /** + * @dataProvider retrieveAccessToken_data + */ + public function test_retrieveAccessToken($cache_token, $db_token, $exception) + { + if ($db_token) + { + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); + $temp_storage->storeAccessToken($db_token); + unset($temp_storage); + $token = $db_token; + } + + if ($cache_token) + { + $this->token_storage->storeAccessToken($cache_token); + $token = $cache_token; + } + + $this->setExpectedException($exception); + + $stored_token = $this->token_storage->retrieveAccessToken(); + $this->assertEquals($token, $stored_token); } public function test_storeAccessToken() -- cgit v1.2.1 From 229d4f2fd6e067f95a5766c90e34578d1baaddb8 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:47:06 -0400 Subject: [feature/oauth] Replace spaces with tabs PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index e86d1359d9..2a161bb9cc 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -74,8 +74,8 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->setExpectedException($exception); - $stored_token = $this->token_storage->retrieveAccessToken(); - $this->assertEquals($token, $stored_token); + $stored_token = $this->token_storage->retrieveAccessToken(); + $this->assertEquals($token, $stored_token); } public function test_storeAccessToken() @@ -85,13 +85,13 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c // Confirm that the token is cached $extraParams = $this->token_storage->retrieveAccessToken()->getExtraParams(); - $this->assertEquals( 'param', $extraParams['extra'] ); - $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() ); + $this->assertEquals( 'param', $extraParams['extra'] ); + $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() ); - // Test that the token is stored in the database - $sql = 'SELECT oauth_token FROM phpbb_oauth_tokens - WHERE session_id = \'' . $this->session_id . '\''; - $result = $this->db->sql_query($sql); + // Test that the token is stored in the database + $sql = 'SELECT oauth_token FROM phpbb_oauth_tokens + WHERE session_id = \'' . $this->session_id . '\''; + $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); -- cgit v1.2.1 From e2ea641cc4301d7fb591da88430b640cc41022c0 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:51:54 -0400 Subject: [feature/oauth] Token storage test set_user_id() PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 2a161bb9cc..fc4a9af741 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -88,12 +88,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals( 'param', $extraParams['extra'] ); $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() ); - // Test that the token is stored in the database - $sql = 'SELECT oauth_token FROM phpbb_oauth_tokens - WHERE session_id = \'' . $this->session_id . '\''; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); + $row = $this->get_token_row_by_session_id($this->session_id); // The token is serialized before stored in the database $this->assertEquals(serialize($token), $row['oauth_token']); @@ -111,6 +106,25 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c public function test_set_user_id() { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($token); + + $new_user_id = ANONYMOUS + 1; + $this->token_storage->set_user_id($new_user_id); + + $row = $this->get_token_row_by_session_id($this->session_id); + $this->assertEquals($new_user_id, $row['user_id']); + } + + protected function get_token_row_by_session_id($session_id) + { + // Test that the token is stored in the database + $sql = 'SELECT * FROM phpbb_oauth_tokens + WHERE session_id = \'' . $session_id . '\''; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + return $row; } } \ No newline at end of file -- cgit v1.2.1 From 69d8149a8f9bf5ea6f88a3221cedf8307d88dadf Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:52:52 -0400 Subject: [feature/oauth] Clean up oauth_tokens test fixture PHPBB3-11673 --- tests/auth/fixtures/oauth_tokens.xml | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml index 6bf6d22172..9f757af715 100644 --- a/tests/auth/fixtures/oauth_tokens.xml +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -5,20 +5,5 @@ session_id provider oauth_token - - 1 - foobar - foobar - $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ - 0 - 0 - example@example.com - 0 - 0 - - - - - \ No newline at end of file -- cgit v1.2.1 From d1f0ecca453cb80509ba145863195816d8978f41 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 15:56:52 -0400 Subject: [feature/oauth] Has Access Token test PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index fc4a9af741..eb489410c7 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -94,9 +94,26 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals(serialize($token), $row['oauth_token']); } - public function test_hasAccessToken() + public static function hasAccessToken_data() { + return array( + array(null, false), + array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ), true), + ); + } + + /** + * @dataProvider hasAccessToken_data + */ + public function test_hasAccessToken($token, $expected) + { + if ($token) + { + $this->token_storage->storeAccessToken($token); + } + $has_access_token = $this->token_storage->hasAccessToken(); + $this->assertEquals($expected, $has_access_token); } public function test_clearToken() -- cgit v1.2.1 From c5d2b75022f177ea04dfd0528cd54cd5d95ee16a Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 16:00:18 -0400 Subject: [feature/oauth] Clear token storage test PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index eb489410c7..1d5505ee8e 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -118,7 +118,14 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c public function test_clearToken() { + $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); + $this->token_storage->storeAccessToken($token); + $this->token_storage->clearToken(); + + $this->assertFalse($this->token_storage->hasAccessToken()); + $row = $this->get_token_row_by_session_id($this->session_id()); + $this->assertFalse($row); } public function test_set_user_id() -- cgit v1.2.1 From f8dbaa148dccb105133b5a91d58686d79f020afe Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 16:02:33 -0400 Subject: [feature/oauth] Fixes for problems found by tests PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 1d5505ee8e..fced3184df 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -151,4 +151,4 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c return $row; } -} \ No newline at end of file +} -- cgit v1.2.1 From 5052b80456972a56ef6c631cd61afbe127f47cab Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 24 Jul 2013 16:04:07 -0400 Subject: [feature/oauth] Refactor clear token test to get more useful output first PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index fced3184df..789b642ed5 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -122,10 +122,13 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->token_storage->storeAccessToken($token); $this->token_storage->clearToken(); - - $this->assertFalse($this->token_storage->hasAccessToken()); - $row = $this->get_token_row_by_session_id($this->session_id()); + + // Check that the database has been cleared + $row = $this->get_token_row_by_session_id($this->session_id); $this->assertFalse($row); + + // Check that the token is no longer in memory + $this->assertFalse($this->token_storage->hasAccessToken()); } public function test_set_user_id() -- cgit v1.2.1 From 17d774af8ed8895c0f9b77d57c218f0d01d761e3 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Mon, 29 Jul 2013 14:32:11 -0400 Subject: [feature/oauth] Add tests for the new token methods PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 789b642ed5..a0a8a36f47 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -78,6 +78,32 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals($token, $stored_token); } + /** + * @dataProvider retrieveAccessToken_data + */ + public function test_retrieve_access_token_by_session($cache_token, $db_token, $exception) + { + if ($db_token) + { + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); + $temp_storage->storeAccessToken($db_token); + unset($temp_storage); + $token = $db_token; + } + + if ($cache_token) + { + $this->token_storage->storeAccessToken($cache_token); + $token = $cache_token; + } + + $this->setExpectedException($exception); + + $stored_token = $this->token_storage->retrieve_access_token_by_session(); + $this->assertEquals($token, $stored_token); + } + + public function test_storeAccessToken() { $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); @@ -116,6 +142,20 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals($expected, $has_access_token); } + /** + * @dataProvider hasAccessToken_data + */ + public function test_has_access_token_by_session($token, $expected) + { + if ($token) + { + $this->token_storage->storeAccessToken($token); + } + + $has_access_token = $this->token_storage->has_access_token_by_session(); + $this->assertEquals($expected, $has_access_token); + } + public function test_clearToken() { $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); -- cgit v1.2.1 From 381e7c347b0d7cfc0f02d677aa61b92701606504 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Thu, 1 Aug 2013 21:44:51 -0400 Subject: [feature/oauth] Forgot new line character PHPBB3-11673 --- tests/auth/fixtures/oauth_tokens.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml index 9f757af715..9bfb5a4422 100644 --- a/tests/auth/fixtures/oauth_tokens.xml +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -6,4 +6,5 @@ provider oauth_token - \ No newline at end of file + + -- cgit v1.2.1 From 2bf97a01ce24d7e8fc789c4e29e8dd4d3b2780a2 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 14 Aug 2013 23:42:50 -0400 Subject: [feature/oauth] Refactor test to provide for easier to read tests PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 29 ++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index a0a8a36f47..f47f3652b6 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -47,25 +47,16 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c public static function retrieveAccessToken_data() { return array( - array(null, new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')), null), - array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ), null, null), - array(null, null, 'OAuth\Common\Storage\Exception\TokenNotFoundException'), + array(new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')), null), + array(null, 'OAuth\Common\Storage\Exception\TokenNotFoundException'), ); } /** * @dataProvider retrieveAccessToken_data */ - public function test_retrieveAccessToken($cache_token, $db_token, $exception) + public function test_retrieveAccessToken($cache_token, $exception) { - if ($db_token) - { - $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); - $temp_storage->storeAccessToken($db_token); - unset($temp_storage); - $token = $db_token; - } - if ($cache_token) { $this->token_storage->storeAccessToken($cache_token); @@ -78,6 +69,20 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals($token, $stored_token); } + public function test_retrieveAccessToken_from_db() + { + $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); + + // Store a token in the database + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); + $temp_storage->storeAccessToken($expected_token); + unset($temp_storage); + + // Test to see if the token can be retrieved + $stored_token = $this->token_storage->retrieveAccessToken(); + $this->assertEquals($expected_token, $stored_token); + } + /** * @dataProvider retrieveAccessToken_data */ -- cgit v1.2.1 From 83515cd3d42486b7411ac5e817cb5c2378b75fe8 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Thu, 15 Aug 2013 01:14:37 -0400 Subject: [feature/oauth] Fix remaining issues with token storage PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index f47f3652b6..026a539285 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -86,16 +86,8 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c /** * @dataProvider retrieveAccessToken_data */ - public function test_retrieve_access_token_by_session($cache_token, $db_token, $exception) + public function test_retrieve_access_token_by_session($cache_token, $exception) { - if ($db_token) - { - $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); - $temp_storage->storeAccessToken($db_token); - unset($temp_storage); - $token = $db_token; - } - if ($cache_token) { $this->token_storage->storeAccessToken($cache_token); @@ -108,6 +100,19 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals($token, $stored_token); } + public function test_retrieve_access_token_by_session_from_db() + { + $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); + + // Store a token in the database + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); + $temp_storage->storeAccessToken($expected_token); + unset($temp_storage); + + // Test to see if the token can be retrieved + $stored_token = $this->token_storage->retrieve_access_token_by_session(); + $this->assertEquals($expected_token, $stored_token); + } public function test_storeAccessToken() { @@ -122,7 +127,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $row = $this->get_token_row_by_session_id($this->session_id); // The token is serialized before stored in the database - $this->assertEquals(serialize($token), $row['oauth_token']); + $this->assertEquals($this->token_storage->json_encode_token($token), $row['oauth_token']); } public static function hasAccessToken_data() -- cgit v1.2.1 From 4348fd83501a56338c1584d96da91b1d6945b93b Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Mon, 2 Sep 2013 15:32:42 -0400 Subject: [feature/oauth] Make token storage service ignorant PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 026a539285..223d4dfb93 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -36,7 +36,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c // Set the user id to anonymous $this->user->data['user_id'] = ANONYMOUS; - $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); + $this->token_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->token_storage_table); } public function getDataSet() @@ -59,13 +59,13 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { if ($cache_token) { - $this->token_storage->storeAccessToken($cache_token); + $this->token_storage->storeAccessToken($this->service_name, $cache_token); $token = $cache_token; } $this->setExpectedException($exception); - $stored_token = $this->token_storage->retrieveAccessToken(); + $stored_token = $this->token_storage->retrieveAccessToken($this->service_name); $this->assertEquals($token, $stored_token); } @@ -74,12 +74,12 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); // Store a token in the database - $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); - $temp_storage->storeAccessToken($expected_token); + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->token_storage_table); + $temp_storage->storeAccessToken($this->service_name, $expected_token); unset($temp_storage); // Test to see if the token can be retrieved - $stored_token = $this->token_storage->retrieveAccessToken(); + $stored_token = $this->token_storage->retrieveAccessToken($this->service_name); $this->assertEquals($expected_token, $stored_token); } @@ -90,13 +90,13 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { if ($cache_token) { - $this->token_storage->storeAccessToken($cache_token); + $this->token_storage->storeAccessToken($this->service_name, $cache_token); $token = $cache_token; } $this->setExpectedException($exception); - $stored_token = $this->token_storage->retrieve_access_token_by_session(); + $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name); $this->assertEquals($token, $stored_token); } @@ -105,24 +105,24 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); // Store a token in the database - $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->service_name, $this->token_storage_table); - $temp_storage->storeAccessToken($expected_token); + $temp_storage = new phpbb_auth_provider_oauth_token_storage($this->db, $this->user, $this->token_storage_table); + $temp_storage->storeAccessToken($this->service_name, $expected_token); unset($temp_storage); // Test to see if the token can be retrieved - $stored_token = $this->token_storage->retrieve_access_token_by_session(); + $stored_token = $this->token_storage->retrieve_access_token_by_session($this->service_name); $this->assertEquals($expected_token, $stored_token); } public function test_storeAccessToken() { $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); - $this->token_storage->storeAccessToken($token); + $this->token_storage->storeAccessToken($this->service_name, $token); // Confirm that the token is cached - $extraParams = $this->token_storage->retrieveAccessToken()->getExtraParams(); + $extraParams = $this->token_storage->retrieveAccessToken($this->service_name)->getExtraParams(); $this->assertEquals( 'param', $extraParams['extra'] ); - $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken()->getAccessToken() ); + $this->assertEquals( 'access', $this->token_storage->retrieveAccessToken($this->service_name)->getAccessToken() ); $row = $this->get_token_row_by_session_id($this->session_id); @@ -145,10 +145,10 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { if ($token) { - $this->token_storage->storeAccessToken($token); + $this->token_storage->storeAccessToken($this->service_name, $token); } - $has_access_token = $this->token_storage->hasAccessToken(); + $has_access_token = $this->token_storage->hasAccessToken($this->service_name); $this->assertEquals($expected, $has_access_token); } @@ -159,32 +159,32 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { if ($token) { - $this->token_storage->storeAccessToken($token); + $this->token_storage->storeAccessToken($this->service_name, $token); } - $has_access_token = $this->token_storage->has_access_token_by_session(); + $has_access_token = $this->token_storage->has_access_token_by_session($this->service_name); $this->assertEquals($expected, $has_access_token); } public function test_clearToken() { $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); - $this->token_storage->storeAccessToken($token); + $this->token_storage->storeAccessToken($this->service_name, $token); - $this->token_storage->clearToken(); + $this->token_storage->clearToken($this->service_name); // Check that the database has been cleared $row = $this->get_token_row_by_session_id($this->session_id); $this->assertFalse($row); // Check that the token is no longer in memory - $this->assertFalse($this->token_storage->hasAccessToken()); + $this->assertFalse($this->token_storage->hasAccessToken($this->service_name)); } public function test_set_user_id() { $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param') ); - $this->token_storage->storeAccessToken($token); + $this->token_storage->storeAccessToken($this->service_name, $token); $new_user_id = ANONYMOUS + 1; $this->token_storage->set_user_id($new_user_id); -- cgit v1.2.1 From ae18f921ea61b20b026c4679b5b27cf40825f5dd Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Mon, 2 Sep 2013 16:52:24 -0400 Subject: [feature/oauth] More small fixes PHPBB3-11673 --- tests/auth/provider_oauth_token_storage_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 223d4dfb93..401f049405 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -197,7 +197,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { // Test that the token is stored in the database $sql = 'SELECT * FROM phpbb_oauth_tokens - WHERE session_id = \'' . $session_id . '\''; + WHERE session_id = \'' . $this->db->sql_escape($session_id) . '\''; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); -- cgit v1.2.1