From 80e2d65399e7dcf9b53dada4929d7194275721ad Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Mon, 24 Jun 2013 12:05:29 -0400 Subject: [feature/auth-refactor] Initial auth unit test provider_db Initial work on a unit test for the provider_db login function. Does not work currently. PHPBB3-9734 --- tests/auth/fixtures/user.xml | 33 +++++++++++++++++++++++++++++++++ tests/auth/provider_db_test.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/auth/fixtures/user.xml create mode 100644 tests/auth/provider_db_test.php (limited to 'tests/auth') diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml new file mode 100644 index 0000000000..34584babbf --- /dev/null +++ b/tests/auth/fixtures/user.xml @@ -0,0 +1,33 @@ + + + + user_id + username + username_clean + user_password + user_passchg + user_pass_convert + user_email + user_type + user_login_attempts + user_permissions + user_sig + user_occ + user_interests + + 1 + foobar + foobar + $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ + 0 + 0 + example@example.com + 0 + 0 + + + + + +
+
diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php new file mode 100644 index 0000000000..c6355ae7f9 --- /dev/null +++ b/tests/auth/provider_db_test.php @@ -0,0 +1,40 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + public function test_login() + { + global $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + $config = new phpbb_config(array( + 'ip_login_limit_max' => 0, + 'ip_login_limit_use_forwarded' => 0, + 'max_login_attempts' => 0, + )); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + $provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => '', + ); + $this->assertEquals($expected, $provider->login('example', 'example')); + } +} -- cgit v1.2.1 From 8e1a503f4437eb38de6a349a841db75648a81678 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 13:22:56 -0400 Subject: [feature/auth-refactor] Finish provider_db unit test for login Finishes the provider_db unit test for login. The test currently passes. PHPBB3-9734 --- tests/auth/provider_db_test.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index c6355ae7f9..d876683f84 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -33,8 +33,18 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $expected = array( 'status' => LOGIN_SUCCESS, 'error_msg' => false, - 'user_row' => '', + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + 'user_login_attempts' => '0', + ), ); - $this->assertEquals($expected, $provider->login('example', 'example')); + + $this->assertEquals($expected, $provider->login('foobar', 'example')); } } -- cgit v1.2.1 From 91c80dfc8eed6ed3cfa90732087741c8433acabf Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 13:34:43 -0400 Subject: [feature/auth-refactor] Skeleton of provider_apache_test Creates a skeleton of the tests for provider_apache. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/auth/provider_apache_test.php (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php new file mode 100644 index 0000000000..d552c4131e --- /dev/null +++ b/tests/auth/provider_apache_test.php @@ -0,0 +1,49 @@ +new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $this->provider = new phpbb_auth_provider_apache($db, $config, $request, $user, $phpbb_root_path, $phpEx); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + public function test_init() + { + $this->markTestIncomplete(); + } + + public function test_login() + { + $this->markTestIncomplete(); + } + + public function test_validate_session() + { + $this->markTestIncomplete(); + } +} -- cgit v1.2.1 From e5de05d8dbbcf0a38aa5c1c2a872765b163ccb31 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:05:40 -0400 Subject: [feature/auth-refactor] Test for init on provider_apache Provides a test for the init() method of provider_apache. Appears to be failing due to an error with the mock request class. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index d552c4131e..1530dcb746 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -12,6 +12,8 @@ require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; class phpbb_auth_provider_apache_test extends phpbb_database_test_case { protected $provider; + protected $user; + protected $request; protected function setup() { @@ -21,10 +23,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $db = $this->new_dbal(); $config = new phpbb_config(array()); - $request = $this->getMock('phpbb_request'); - $user = $this->getMock('phpbb_user'); + $this->request = $this->getMock('phpbb_request'); + $this->user = $this->getMock('phpbb_user'); - $this->provider = new phpbb_auth_provider_apache($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() @@ -32,9 +34,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); } + /** + * Test to see if a user is identified to Apache. Expects false if they are. + */ public function test_init() { - $this->markTestIncomplete(); + $this->user->data['username'] = 'foobar'; + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + + $this->assertFalse($this->provider->init()); } public function test_login() -- cgit v1.2.1 From 307dd9777b67e8a7628bb74eeba8cc55ab6a8f58 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:12:31 -0400 Subject: [feature/auth-refactor] Test login() for provider_apache Provides a test for the login() method for provider_apache. Appears to be failing due to an issue with the mock phpBB request class. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 1530dcb746..4773e4fdc3 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -47,7 +47,26 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_login() { - $this->markTestIncomplete(); + $username = 'foobar'; + $password = 'example'; + + $this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER); + $this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + ), + ); + + $this->assertEquals($expected, $this->provider->login($username, $password)); } public function test_validate_session() -- cgit v1.2.1 From 9e04328545c933aa801c52c1567efd3d2e06fcf3 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:24:47 -0400 Subject: [feature/auth-refactor] Test autologin() on provider_apache Provides a test for the autologin() method of provider_apache that assumes the user already exists in the database. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 4773e4fdc3..6cfd676fc2 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -69,6 +69,34 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->assertEquals($expected, $this->provider->login($username, $password)); } + public function test_autologin() + { + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'username_clean' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + 'user_login_attempts' => '0', + 'user_permission' => '', + 'user_sig' => '', + 'user_occ' => '', + 'user_interests' => '', + ), + ); + + $this->assertEquals($expected, $this->provider->autologin()); + } + public function test_validate_session() { $this->markTestIncomplete(); -- cgit v1.2.1 From 5444e5b6831d5ce87ff2adaf1f7b0e4788592bc3 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:28:16 -0400 Subject: [feature/auth-refactor] Test validate_session on provider_apache Provides a test for the validate_session() method of provider_apache. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 6cfd676fc2..092b90bea3 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -99,6 +99,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_validate_session() { - $this->markTestIncomplete(); + $user = $this->getMock('phpbb_user'); + $user->data['username'] = 'foobar'; + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + + $this->assertTrue($this->provider->validate_session($user)); } } -- cgit v1.2.1 From 5f3ed197e73550e78b37dd38496210737cf3f39d Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 16:25:45 -0400 Subject: [feature/auth-refactor] Fix auth tests to use mock objects correctly PHPBB3-9734 --- tests/auth/provider_apache_test.php | 148 ++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 25 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 092b90bea3..0ca6ef763e 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -40,7 +40,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_init() { $this->user->data['username'] = 'foobar'; - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); $this->assertFalse($this->provider->init()); } @@ -50,8 +58,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $username = 'foobar'; $password = 'example'; - $this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER); - $this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); $expected = array( 'status' => LOGIN_SUCCESS, @@ -71,27 +90,96 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_autologin() { - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); - $this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); $expected = array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => array( - 'user_id' => '1', - 'username' => 'foobar', - 'username_clean' => 'foobar', - 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', - 'user_passchg' => '0', - 'user_pass_convert' => '0', - 'user_email' => 'example@example.com', - 'user_type' => '0', - 'user_login_attempts' => '0', - 'user_permission' => '', - 'user_sig' => '', - 'user_occ' => '', - 'user_interests' => '', - ), + 'user_id' => '1', + 'user_type' => '0', + 'group_id' => '3', + 'user_permissions' => '', + 'user_perm_from' => '0', + 'user_ip' => '', + 'user_regdate' => '0', + 'username' => 'foobar', + 'username_clean' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_email_hash' => '0', + 'user_birthday' => '', + 'user_lastvisit' => '0', + 'user_lastmark' => '0', + 'user_lastpost_time' => '0', + 'user_lastpage' => '', + 'user_last_confirm_key' => '', + 'user_last_search' => '0', + 'user_warnings' => '0', + 'user_last_warning' => '0', + 'user_login_attempts' => '0', + 'user_inactive_reason' => '0', + 'user_inactive_time' => '0', + 'user_posts' => '0', + 'user_lang' => '', + 'user_timezone' => 'UTC', + 'user_dateformat' => 'd M Y H:i', + 'user_style' => '0', + 'user_rank' => '0', + 'user_colour' => '', + 'user_new_privmsg' => '0', + 'user_unread_privmsg' => '0', + 'user_last_privmsg' => '0', + 'user_message_rules' => '0', + 'user_full_folder' => '-3', + 'user_emailtime' => '0', + 'user_topic_show_days' => '0', + 'user_topic_sortby_type' => 't', + 'user_topic_sortby_dir' => 'd', + 'user_post_show_days' => '0', + 'user_post_sortby_type' => 't', + 'user_post_sortby_dir' => 'a', + 'user_notify' => '0', + 'user_notify_pm' => '1', + 'user_notify_type' => '0', + 'user_allow_pm' => '1', + 'user_allow_viewonline' => '1', + 'user_allow_viewemail' => '1', + 'user_allow_massemail' => '1', + 'user_options' => '230271', + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '0', + 'user_avatar_height' => '0', + 'user_sig' => '', + 'user_sig_bbcode_uid' => '', + 'user_sig_bbcode_bitfield' => '', + 'user_from' => '', + 'user_icq' => '', + 'user_aim' => '', + 'user_yim' => '', + 'user_msnm' => '', + 'user_jabber' => '', + 'user_website' => '', + 'user_occ' => '', + 'user_interests' => '', + 'user_actkey' => '', + 'user_newpasswd' => '', + 'user_form_salt' => '', + 'user_new' => '1', + 'user_reminded' => '0', + 'user_reminded_time' => '0', ); $this->assertEquals($expected, $this->provider->autologin()); @@ -99,9 +187,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_validate_session() { - $user = $this->getMock('phpbb_user'); - $user->data['username'] = 'foobar'; - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $user = array( + 'username' => 'foobar', + 'user_type' + ); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); $this->assertTrue($this->provider->validate_session($user)); } -- cgit v1.2.1 From da2752e4004b296ae5acdd08b7c0a758d8f61e9d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 13:30:52 -0400 Subject: [ticket/11700] Modify all code to use the new interface names PHPBB3-11700 --- tests/auth/provider_apache_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 0ca6ef763e..9aa5f676d1 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -43,7 +43,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + phpbb_request_request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') @@ -61,7 +61,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + phpbb_request_request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -93,7 +93,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + phpbb_request_request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -194,7 +194,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_interface::SERVER) + phpbb_request_request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') -- cgit v1.2.1 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 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- tests/auth/provider_apache_test.php | 16 ++++++++-------- tests/auth/provider_db_test.php | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 9aa5f676d1..e135a1f002 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -22,11 +22,11 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case global $phpbb_root_path, $phpEx; $db = $this->new_dbal(); - $config = new phpbb_config(array()); - $this->request = $this->getMock('phpbb_request'); - $this->user = $this->getMock('phpbb_user'); + $config = new \phpbb\config\config(array()); + $this->request = $this->getMock('\phpbb\request\request'); + $this->user = $this->getMock('\phpbb\user'); - $this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); + $this->provider = new \phpbb\auth\provider\apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() @@ -43,7 +43,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') @@ -61,7 +61,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -93,7 +93,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->at(1)) ->method('server') @@ -194,7 +194,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->request->expects($this->once()) ->method('is_set') ->with('PHP_AUTH_USER', - phpbb_request_request_interface::SERVER) + \phpbb\request\request_interface::SERVER) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('server') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index d876683f84..140a28cd3d 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -21,14 +21,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case global $phpbb_root_path, $phpEx; $db = $this->new_dbal(); - $config = new phpbb_config(array( + $config = new \phpbb\config\config(array( 'ip_login_limit_max' => 0, 'ip_login_limit_use_forwarded' => 0, 'max_login_attempts' => 0, )); - $request = $this->getMock('phpbb_request'); - $user = $this->getMock('phpbb_user'); - $provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $request = $this->getMock('\phpbb\request\request'); + $user = $this->getMock('\phpbb\user'); + $provider = new \phpbb\auth\provider\db($db, $config, $request, $user, $phpbb_root_path, $phpEx); $expected = array( 'status' => LOGIN_SUCCESS, -- cgit v1.2.1 From 2472271bc0cd7c15c77783c86ccaac643ab1756a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 16 Sep 2013 02:41:03 +0200 Subject: [ticket/11700] Fix tests after merging new develop code PHPBB3-11700 --- tests/auth/provider_oauth_token_storage_test.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 401f049405..fdc08833a3 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -25,7 +25,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c global $phpbb_root_path, $phpEx; $this->db = $this->new_dbal(); - $this->user = $this->getMock('phpbb_user'); + $this->user = $this->getMock('\phpbb\user'); $this->service_name = 'auth.provider.oauth.service.testing'; $this->token_storage_table = 'phpbb_oauth_tokens'; @@ -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->token_storage_table); + $this->token_storage = new \phpbb\auth\provider\oauth\token_storage($this->db, $this->user, $this->token_storage_table); } public function getDataSet() @@ -74,7 +74,7 @@ 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->token_storage_table); + $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); @@ -105,7 +105,7 @@ 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->token_storage_table); + $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); @@ -196,7 +196,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c 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 + $sql = 'SELECT * FROM phpbb_oauth_tokens WHERE session_id = \'' . $this->db->sql_escape($session_id) . '\''; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); -- cgit v1.2.1 From 356f3eef0760f85b947cbffbf87918544e0f6c9d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 2 Oct 2013 13:28:38 +0200 Subject: [feature/passwords] Inject passwords manager into auth providers The passwords manager will replace the old method of using the functions phpbb_hash() and phpbb_check_hash(). PHPBB3-11610 --- tests/auth/provider_apache_test.php | 18 +++++++++++++++++- tests/auth/provider_db_test.php | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index e135a1f002..5388ae0b0d 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -25,8 +25,24 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $config = new \phpbb\config\config(array()); $this->request = $this->getMock('\phpbb\request\request'); $this->user = $this->getMock('\phpbb\user'); + $driver_helper = new phpbb\passwords\driver\helper($config); + $passwords_drivers = array( + 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + ); + + foreach ($passwords_drivers as $key => $driver) + { + $driver->set_name($key); + } + + $passwords_helper = new phpbb\passwords\helper; + // Set up passwords manager + $passwords_manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); - $this->provider = new \phpbb\auth\provider\apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); + $this->provider = new \phpbb\auth\provider\apache($db, $config, $passwords_manager, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 140a28cd3d..74615a01ed 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -28,7 +28,24 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case )); $request = $this->getMock('\phpbb\request\request'); $user = $this->getMock('\phpbb\user'); - $provider = new \phpbb\auth\provider\db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $driver_helper = new phpbb\passwords\driver\helper($config); + $passwords_drivers = array( + 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + ); + + foreach ($passwords_drivers as $key => $driver) + { + $driver->set_name($key); + } + + $passwords_helper = new phpbb\passwords\helper; + // Set up passwords manager + $passwords_manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + + $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); $expected = array( 'status' => LOGIN_SUCCESS, -- cgit v1.2.1 From 93531e7fb0df7d9cd2de04ca06aa9eb6a847a1c4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 2 Oct 2013 23:45:32 +0200 Subject: [feature/passwords] Add prepending backslash to class namespaces PHPBB3-11610 --- tests/auth/provider_apache_test.php | 14 +++++++------- tests/auth/provider_db_test.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 5388ae0b0d..8f65e8ad39 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -25,12 +25,12 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $config = new \phpbb\config\config(array()); $this->request = $this->getMock('\phpbb\request\request'); $this->user = $this->getMock('\phpbb\user'); - $driver_helper = new phpbb\passwords\driver\helper($config); + $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( - 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), - 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), - 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), - 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); foreach ($passwords_drivers as $key => $driver) @@ -38,9 +38,9 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $driver->set_name($key); } - $passwords_helper = new phpbb\passwords\helper; + $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager - $passwords_manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); $this->provider = new \phpbb\auth\provider\apache($db, $config, $passwords_manager, $this->request, $this->user, $phpbb_root_path, $phpEx); } diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 74615a01ed..b979ab34c5 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -28,12 +28,12 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case )); $request = $this->getMock('\phpbb\request\request'); $user = $this->getMock('\phpbb\user'); - $driver_helper = new phpbb\passwords\driver\helper($config); + $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( - 'passwords.driver.bcrypt' => new phpbb\passwords\driver\bcrypt($config, $driver_helper), - 'passwords.driver.bcrypt_2y' => new phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), - 'passwords.driver.salted_md5' => new phpbb\passwords\driver\salted_md5($config, $driver_helper), - 'passwords.driver.phpass' => new phpbb\passwords\driver\phpass($config, $driver_helper), + 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), + 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), + 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); foreach ($passwords_drivers as $key => $driver) @@ -41,9 +41,9 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $driver->set_name($key); } - $passwords_helper = new phpbb\passwords\helper; + $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager - $passwords_manager = new phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); -- cgit v1.2.1 From bb836b65e3c16fadf5c13510cce73daf432f7ad8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 25 Oct 2013 15:21:09 +0200 Subject: [feature/passwords] Integrate convert_flag with db auth provider PHPBB3-11610 --- tests/auth/fixtures/user.xml | 15 +++++++++++++++ tests/auth/provider_apache_test.php | 4 ++-- tests/auth/provider_db_test.php | 7 ++++++- 3 files changed, 23 insertions(+), 3 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml index 34584babbf..6d475930a4 100644 --- a/tests/auth/fixtures/user.xml +++ b/tests/auth/fixtures/user.xml @@ -18,6 +18,21 @@ 1 foobar foobar + $2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i + 0 + 0 + example@example.com + 0 + 0 + + + + + + + 2 + foobar2 + foobar2 $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ 0 0 diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 8f65e8ad39..4c09af33e5 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -94,7 +94,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_row' => array( 'user_id' => '1', 'username' => 'foobar', - 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', 'user_passchg' => '0', 'user_email' => 'example@example.com', 'user_type' => '0', @@ -130,7 +130,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_regdate' => '0', 'username' => 'foobar', 'username_clean' => 'foobar', - 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', 'user_passchg' => '0', 'user_pass_convert' => '0', 'user_email' => 'example@example.com', diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index b979ab34c5..a6fe636edd 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -53,7 +53,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'user_row' => array( 'user_id' => '1', 'username' => 'foobar', - 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', 'user_passchg' => '0', 'user_pass_convert' => '0', 'user_email' => 'example@example.com', @@ -63,5 +63,10 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case ); $this->assertEquals($expected, $provider->login('foobar', 'example')); + + // Check if convert works + $login_return = $provider->login('foobar2', 'example'); + $password_start = (version_compare(PHP_VERSION, '5.3.7', '<')) ? '$2a$10$' : '$2y$10$'; + $this->assertStringStartsWith($password_start, $login_return['user_row']['user_password']); } } -- cgit v1.2.1 From 760f148a2ba581df61a25d3efd0e438b5ea77e7b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 27 Oct 2013 13:22:53 +0100 Subject: [feature/passwords] Fix tests on PHP < 5.3.3 again PHPBB3-11610 --- tests/auth/fixtures/user_533.xml | 48 +++++++++++++++++++++++++++++++++++++ tests/auth/provider_apache_test.php | 22 ++++++++++++++--- tests/auth/provider_db_test.php | 19 +++++++++++++-- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 tests/auth/fixtures/user_533.xml (limited to 'tests/auth') diff --git a/tests/auth/fixtures/user_533.xml b/tests/auth/fixtures/user_533.xml new file mode 100644 index 0000000000..c2a86ea0f9 --- /dev/null +++ b/tests/auth/fixtures/user_533.xml @@ -0,0 +1,48 @@ + + + + user_id + username + username_clean + user_password + user_passchg + user_pass_convert + user_email + user_type + user_login_attempts + user_permissions + user_sig + user_occ + user_interests + + 1 + foobar + foobar + $2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi + 0 + 0 + example@example.com + 0 + 0 + + + + + + + 2 + foobar2 + foobar2 + $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ + 0 + 0 + example@example.com + 0 + 0 + + + + + +
+
diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 4c09af33e5..34da8e1dab 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -42,12 +42,28 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case // Set up passwords manager $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + if (version_compare(PHP_VERSION, '5.3.7', '<')) + { + $this->password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; + } + else + { + $this->password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; + } + $this->provider = new \phpbb\auth\provider\apache($db, $config, $passwords_manager, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + if ((version_compare(PHP_VERSION, '5.3.7', '<'))) + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml'); + } + else + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } } /** @@ -94,7 +110,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_row' => array( 'user_id' => '1', 'username' => 'foobar', - 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', + 'user_password' => $this->password_hash, 'user_passchg' => '0', 'user_email' => 'example@example.com', 'user_type' => '0', @@ -130,7 +146,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_regdate' => '0', 'username' => 'foobar', 'username_clean' => 'foobar', - 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', + 'user_password' => $this->password_hash, 'user_passchg' => '0', 'user_pass_convert' => '0', 'user_email' => 'example@example.com', diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index a6fe636edd..c46d115da8 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -13,7 +13,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + if ((version_compare(PHP_VERSION, '5.3.7', '<'))) + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user_533.xml'); + } + else + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } } public function test_login() @@ -46,6 +53,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); + if (version_compare(PHP_VERSION, '5.3.7', '<')) + { + $password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; + } + else + { + $password_hash = '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i'; + } $expected = array( 'status' => LOGIN_SUCCESS, @@ -53,7 +68,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'user_row' => array( 'user_id' => '1', 'username' => 'foobar', - 'user_password' => '$2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i', + 'user_password' => $password_hash, 'user_passchg' => '0', 'user_pass_convert' => '0', 'user_email' => 'example@example.com', -- cgit v1.2.1 From 5193b3279cfcd4f7f5d656ec806b87e971c5523f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 27 Oct 2013 14:18:02 +0100 Subject: [feature/passwords] Pass list of default types to passwords manager This list is in the order of how the driver types would be used. If a driver is not supported we will try the subsequent one. PHPBB3-11610 --- tests/auth/provider_apache_test.php | 4 ++-- tests/auth/provider_db_test.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 34da8e1dab..b4322922b8 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -27,8 +27,8 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->user = $this->getMock('\phpbb\user'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( - 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); @@ -40,7 +40,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager - $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); if (version_compare(PHP_VERSION, '5.3.7', '<')) { diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index c46d115da8..32c2a82710 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -37,8 +37,8 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $user = $this->getMock('\phpbb\user'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( - 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), + 'passwords.driver.bcrypt' => new \phpbb\passwords\driver\bcrypt($config, $driver_helper), 'passwords.driver.salted_md5' => new \phpbb\passwords\driver\salted_md5($config, $driver_helper), 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); @@ -50,7 +50,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager - $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, 'passwords.driver.bcrypt_2y'); + $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); if (version_compare(PHP_VERSION, '5.3.7', '<')) -- cgit v1.2.1 From d589696827d25aa0287f984a32a3295028d2f062 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 4 Dec 2013 14:13:59 +0100 Subject: [ticket/12056] Fix "Call to undefined function ...\utf8_clean_string()" PHPBB3-12056 --- tests/auth/provider_db_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 140a28cd3d..45a893220b 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -7,7 +7,8 @@ * */ -require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; class phpbb_auth_provider_db_test extends phpbb_database_test_case { -- cgit v1.2.1 From ffc24a507da5bbc0988a740bd00617bf7d413a3e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 4 Dec 2013 14:16:10 +0100 Subject: [ticket/12056] Fix "Call to undefined function ...\utf8_normalize_nfc()" PHPBB3-12056 --- tests/auth/provider_apache_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index e135a1f002..d7509a72bf 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -7,7 +7,8 @@ * */ -require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; class phpbb_auth_provider_apache_test extends phpbb_database_test_case { -- cgit v1.2.1 From 292961a2771c9237197b9770b23a2a14a981c329 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Feb 2014 14:09:09 +0100 Subject: [feature/passwords] Get rid of set_name/get_name methods for passwords drivers PHPBB3-11610 --- tests/auth/provider_apache_test.php | 5 ----- tests/auth/provider_db_test.php | 5 ----- 2 files changed, 10 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index dbd98d9a66..1231c16a4c 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -34,11 +34,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); - foreach ($passwords_drivers as $key => $driver) - { - $driver->set_name($key); - } - $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index b18b6a1ae2..91ffcdc2a7 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -44,11 +44,6 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'passwords.driver.phpass' => new \phpbb\passwords\driver\phpass($config, $driver_helper), ); - foreach ($passwords_drivers as $key => $driver) - { - $driver->set_name($key); - } - $passwords_helper = new \phpbb\passwords\helper; // Set up passwords manager $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); -- cgit v1.2.1 From bbada27ee9e797c7f6ce997152bc1efb8c8f125d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 21:45:59 +0100 Subject: [ticket/12115] Also port user interests to profile fields PHPBB3-12115 --- tests/auth/fixtures/user.xml | 6 ------ tests/auth/fixtures/user_533.xml | 6 ------ tests/auth/provider_apache_test.php | 2 -- 3 files changed, 14 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml index 6d475930a4..77f707bab3 100644 --- a/tests/auth/fixtures/user.xml +++ b/tests/auth/fixtures/user.xml @@ -12,8 +12,6 @@ user_login_attempts user_permissions user_sig - user_occ - user_interests 1 foobar @@ -26,8 +24,6 @@ 0 - - 2 @@ -41,8 +37,6 @@ 0 - - diff --git a/tests/auth/fixtures/user_533.xml b/tests/auth/fixtures/user_533.xml index c2a86ea0f9..b64f376e5b 100644 --- a/tests/auth/fixtures/user_533.xml +++ b/tests/auth/fixtures/user_533.xml @@ -12,8 +12,6 @@ user_login_attempts user_permissions user_sig - user_occ - user_interests 1 foobar @@ -26,8 +24,6 @@ 0 - - 2 @@ -41,8 +37,6 @@ 0 - - diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 1231c16a4c..ad4171cd81 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -200,8 +200,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_msnm' => '', 'user_jabber' => '', 'user_website' => '', - 'user_occ' => '', - 'user_interests' => '', 'user_actkey' => '', 'user_newpasswd' => '', 'user_form_salt' => '', -- cgit v1.2.1 From 6bee91c42915dd613e9714016006b25fa51cb24a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Feb 2014 15:00:49 +0100 Subject: [ticket/12169] Convert user_from to profile field location Missing changes on memberlist view due to missing functionality PHPBB3-12169 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index ad4171cd81..ac5377f2f6 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -193,7 +193,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', - 'user_from' => '', 'user_icq' => '', 'user_aim' => '', 'user_yim' => '', -- cgit v1.2.1 From 76409388afcd6389b5a29bc54b49faaf6bc4b4a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Feb 2014 15:11:17 +0100 Subject: [ticket/12234] Replace ICQ with custom profile field PHPBB3-12234 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index ac5377f2f6..bdf9259ddd 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -193,7 +193,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', - 'user_icq' => '', 'user_aim' => '', 'user_yim' => '', 'user_msnm' => '', -- cgit v1.2.1 From 5b1fbfb2f2c901b89bb1163503b0468e11bbc307 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Mar 2014 20:01:19 +0100 Subject: [ticket/12187] Remove user_website functionality PHPBB3-12187 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index bdf9259ddd..51b2ba5ec9 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -197,7 +197,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_yim' => '', 'user_msnm' => '', 'user_jabber' => '', - 'user_website' => '', 'user_actkey' => '', 'user_newpasswd' => '', 'user_form_salt' => '', -- cgit v1.2.1 From 83a7e632b9b21fed88a3dbea679580d0740664f7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 Mar 2014 10:19:08 +0100 Subject: [ticket/12235] Convert WLM to custom profile field PHPBB3-12235 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 51b2ba5ec9..84abd41bca 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -195,7 +195,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_sig_bbcode_bitfield' => '', 'user_aim' => '', 'user_yim' => '', - 'user_msnm' => '', 'user_jabber' => '', 'user_actkey' => '', 'user_newpasswd' => '', -- cgit v1.2.1 From 2e5106aae1bfe83ad8b2336a6d519da5aabc59d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 Mar 2014 11:22:55 +0100 Subject: [ticket/12237] Convert yahoo messanger to custom profile field PHPBB3-12237 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 84abd41bca..c584c3ecbe 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -194,7 +194,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', 'user_aim' => '', - 'user_yim' => '', 'user_jabber' => '', 'user_actkey' => '', 'user_newpasswd' => '', -- cgit v1.2.1 From f2059f52f3f8f430888366b70aa07c534abb35a1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Mar 2014 22:13:22 +0100 Subject: [ticket/12236] Move AOL Instant Messanger field to custom profile field PHPBB3-12236 --- tests/auth/provider_apache_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index c584c3ecbe..23d6910843 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -193,7 +193,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', - 'user_aim' => '', 'user_jabber' => '', 'user_actkey' => '', 'user_newpasswd' => '', -- cgit v1.2.1 From 959e9beedcfb099e408b2987a7bfd316e3e253db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Mar 2014 23:21:15 +0100 Subject: [ticket/11459] Fix auth provider test user_timezone has no default value anymore PHPBB3-11459 --- tests/auth/provider_apache_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 23d6910843..4b12abd62a 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -161,7 +161,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'user_inactive_time' => '0', 'user_posts' => '0', 'user_lang' => '', - 'user_timezone' => 'UTC', + 'user_timezone' => '', 'user_dateformat' => 'd M Y H:i', 'user_style' => '0', 'user_rank' => '0', -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- tests/auth/provider_apache_test.php | 10 +++++++--- tests/auth/provider_db_test.php | 10 +++++++--- tests/auth/provider_oauth_token_storage_test.php | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 4b12abd62a..e17040902f 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 91ffcdc2a7..f071709a4b 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index fdc08833a3..ec28e546bd 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 4698f6928e44a24a7a10ff8b4fed2c1a24cab338 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 30 May 2014 23:00:57 +0200 Subject: [ticket/12352] Remove usages of user_pass_convert column PHPBB3-12352 --- tests/auth/fixtures/user.xml | 3 --- tests/auth/fixtures/user_533.xml | 3 --- tests/auth/provider_apache_test.php | 1 - tests/auth/provider_db_test.php | 1 - 4 files changed, 8 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml index 77f707bab3..1e0eb6ee49 100644 --- a/tests/auth/fixtures/user.xml +++ b/tests/auth/fixtures/user.xml @@ -6,7 +6,6 @@ username_clean user_password user_passchg - user_pass_convert user_email user_type user_login_attempts @@ -18,7 +17,6 @@ foobar $2y$10$4RmpyVu2y8Yf/lP3.yQBquKvE54TCUuEDEBJYY6FDDFN3LcbCGz9i 0 - 0 example@example.com 0 0 @@ -31,7 +29,6 @@ foobar2 $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ 0 - 0 example@example.com 0 0 diff --git a/tests/auth/fixtures/user_533.xml b/tests/auth/fixtures/user_533.xml index b64f376e5b..9731e4db4a 100644 --- a/tests/auth/fixtures/user_533.xml +++ b/tests/auth/fixtures/user_533.xml @@ -6,7 +6,6 @@ username_clean user_password user_passchg - user_pass_convert user_email user_type user_login_attempts @@ -18,7 +17,6 @@ foobar $2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi 0 - 0 example@example.com 0 0 @@ -31,7 +29,6 @@ foobar2 $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ 0 - 0 example@example.com 0 0 diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index e17040902f..2decf0f18c 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -148,7 +148,6 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case 'username_clean' => 'foobar', 'user_password' => $this->password_hash, 'user_passchg' => '0', - 'user_pass_convert' => '0', 'user_email' => 'example@example.com', 'user_email_hash' => '0', 'user_birthday' => '', diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index f071709a4b..23324f87f2 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -70,7 +70,6 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'username' => 'foobar', 'user_password' => $password_hash, 'user_passchg' => '0', - 'user_pass_convert' => '0', 'user_email' => 'example@example.com', 'user_type' => '0', 'user_login_attempts' => '0', -- cgit v1.2.1 From 8595b2ae86ca14c83d8a61241fadec9f72a730c3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 19 Jun 2014 20:11:49 +0200 Subject: [ticket/12716] Add regression test PHPBB3-12716 --- tests/auth/fixtures/oauth_tokens.xml | 6 ++++++ tests/auth/phpbb_not_a_token.php | 23 +++++++++++++++++++++++ tests/auth/provider_oauth_token_storage_test.php | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/auth/phpbb_not_a_token.php (limited to 'tests/auth') diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml index 9bfb5a4422..cffa02a39d 100644 --- a/tests/auth/fixtures/oauth_tokens.xml +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -5,6 +5,12 @@ session_id provider oauth_token + + 1 + 9999 + auth.provider.oauth.service.testing + {"token_class":"phpbb_not_a_token","accessToken":"error","refreshToken":0,"endOfLife":null,"extraParams":null} + diff --git a/tests/auth/phpbb_not_a_token.php b/tests/auth/phpbb_not_a_token.php new file mode 100644 index 0000000000..61cc14fa10 --- /dev/null +++ b/tests/auth/phpbb_not_a_token.php @@ -0,0 +1,23 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_not_a_token +{ + public function __construct($param1, $param2, $param3, $param4) + { + } + + public function setEndOfLife() + { + } +} diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index ec28e546bd..8919345087 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -13,6 +13,8 @@ use OAuth\OAuth2\Token\StdOAuth2Token; +require_once dirname(__FILE__) . '/phpbb_not_a_token.php'; + class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_case { protected $db; @@ -73,6 +75,22 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c $this->assertEquals($token, $stored_token); } + public function test_retrieveAccessToken_wrong_token() + { + $this->user->data['session_id'] = 9999; + try + { + $this->token_storage->retrieveAccessToken($this->service_name); + $this->fail('The token can not be deserialized and an exception should be thrown.'); + } + catch (\OAuth\Common\Storage\Exception\TokenNotFoundException $e) + { + } + + $row = $this->get_token_row_by_session_id(9999); + $this->assertFalse($row); + } + public function test_retrieveAccessToken_from_db() { $expected_token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES); -- cgit v1.2.1 From 2ebd86611a760b923752a6103e3f75d2bb94e048 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 23 Jun 2014 23:59:45 +0200 Subject: [ticket/12716] Use a string as session_id PHPBB3-12716 --- tests/auth/fixtures/oauth_tokens.xml | 2 +- tests/auth/provider_oauth_token_storage_test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/fixtures/oauth_tokens.xml b/tests/auth/fixtures/oauth_tokens.xml index cffa02a39d..6c82e94e62 100644 --- a/tests/auth/fixtures/oauth_tokens.xml +++ b/tests/auth/fixtures/oauth_tokens.xml @@ -7,7 +7,7 @@ oauth_token 1 - 9999 + abcd auth.provider.oauth.service.testing {"token_class":"phpbb_not_a_token","accessToken":"error","refreshToken":0,"endOfLife":null,"extraParams":null} diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 8919345087..45daa9816b 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -77,7 +77,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c public function test_retrieveAccessToken_wrong_token() { - $this->user->data['session_id'] = 9999; + $this->user->data['session_id'] = 'abcd'; try { $this->token_storage->retrieveAccessToken($this->service_name); @@ -87,7 +87,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c { } - $row = $this->get_token_row_by_session_id(9999); + $row = $this->get_token_row_by_session_id('abcd'); $this->assertFalse($row); } -- cgit v1.2.1 From 8d99b4afe1557a6ec0e760c4876bb06a3b9991d3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 10 Aug 2014 13:40:27 +0200 Subject: [ticket/12932] Fix tests and calls to create_datetime PHPBB3-12932 --- tests/auth/provider_apache_test.php | 2 +- tests/auth/provider_db_test.php | 2 +- tests/auth/provider_oauth_token_storage_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 2decf0f18c..68ad7b2c19 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -29,7 +29,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $db = $this->new_dbal(); $config = new \phpbb\config\config(array()); $this->request = $this->getMock('\phpbb\request\request'); - $this->user = $this->getMock('\phpbb\user'); + $this->user = new \phpbb\user('\phpbb\datetime'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 23324f87f2..744f955531 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -39,7 +39,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'max_login_attempts' => 0, )); $request = $this->getMock('\phpbb\request\request'); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 45daa9816b..71b49ff439 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -31,7 +31,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c global $phpbb_root_path, $phpEx; $this->db = $this->new_dbal(); - $this->user = $this->getMock('\phpbb\user'); + $this->user = new \phpbb\user('\phpbb\datetime'); $this->service_name = 'auth.provider.oauth.service.testing'; $this->token_storage_table = 'phpbb_oauth_tokens'; -- cgit v1.2.1 From 4683864b4bb710a32a6a9078bfa2c7d929c3f1a1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 10 Aug 2014 15:14:00 +0200 Subject: [ticket/11854] Update tests PHPBB3-11854 --- tests/auth/provider_db_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 744f955531..e33eae6b54 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -52,7 +52,9 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case // Set up passwords manager $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); - $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = new phpbb_mock_container_builder(); + + $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_container, $phpbb_root_path, $phpEx); if (version_compare(PHP_VERSION, '5.3.7', '<')) { $password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; -- cgit v1.2.1 From 63022f3c59f01ac1456cde4e837c1431a6664691 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 12 Nov 2014 11:42:08 +0100 Subject: [ticket/13332] Fix auth provider tests PHPBB3-13332 --- tests/auth/provider_db_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/auth') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index e33eae6b54..09ca0816bf 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -78,7 +78,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case ), ); - $this->assertEquals($expected, $provider->login('foobar', 'example')); + $login_return = $provider->login('foobar', 'example'); + $this->assertEquals($expected['status'], $login_return['status']); + $this->assertEquals($expected['error_msg'], $login_return['error_msg']); + + foreach ($expected['user_row'] as $key => $value) + { + $this->assertEquals($value, $login_return['user_row'][$key]); + } // Check if convert works $login_return = $provider->login('foobar2', 'example'); -- cgit v1.2.1