From 6b057e026cfb9603c6260d619e0a37e3679aa0d5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Oct 2014 13:58:09 +0100 Subject: [PATCH 1/5] [ticket/13248] Use auth provider collection for getting provider PHPBB3-13248 --- phpBB/phpbb/auth/auth.php | 6 +++--- tests/functional/auth_test.php | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/auth/auth.php b/phpBB/phpbb/auth/auth.php index 38755ccf99..b59f0e60ec 100644 --- a/phpBB/phpbb/auth/auth.php +++ b/phpBB/phpbb/auth/auth.php @@ -927,11 +927,11 @@ class auth */ function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0) { - global $config, $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; + global $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; - $method = trim(basename($config['auth_method'])); + $provider_collection = $phpbb_container->get('auth.provider_collection'); - $provider = $phpbb_container->get('auth.provider.' . $method); + $provider = $provider_collection->get_provider(); if ($provider) { $login = $provider->login($username, $password); diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index b4b4279bf1..1794afd009 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -33,6 +33,30 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); } + /** + * @dependsOn test_login_other + */ + public function test_login_ucp_other_auth_provider() + { + global $cache, $config; + $cache = new phpbb_mock_null_cache; + $db = $this->get_db(); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $crawler = self::request('GET', 'ucp.php?mode=login'); + $form = $crawler->selectButton('Login')->form(); + $form->setValues(array( + 'username' => 'anothertestuser', + 'password' => str_repeat('anothertestuser', 2), + )); + $config['auth_method'] = 'foobar'; + $crawler = self::submit($form); + $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $config['auth_method'] = 'db'; + } + /** * @depends test_login */ From c3f5dc75bed689956b7d4ed1e5b7e0d2c80257c9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Oct 2014 14:24:33 +0100 Subject: [PATCH 2/5] [ticket/13248] Allow specifying different auth provider in provider collection PHPBB3-13248 --- phpBB/phpbb/auth/provider_collection.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/auth/provider_collection.php b/phpBB/phpbb/auth/provider_collection.php index a74a2135dc..bf724419b7 100644 --- a/phpBB/phpbb/auth/provider_collection.php +++ b/phpBB/phpbb/auth/provider_collection.php @@ -38,6 +38,7 @@ class provider_collection extends \phpbb\di\service_collection /** * Get an auth provider. * + * @param string $provider_name The name of the auth provider * @return object Default auth provider selected in config if it * does exist. Otherwise the standard db auth * provider. @@ -46,11 +47,12 @@ class provider_collection extends \phpbb\di\service_collection * auth provider exist. The db auth provider * should always exist in a phpBB installation. */ - public function get_provider() + public function get_provider($provider_name = '') { - if ($this->offsetExists('auth.provider.' . basename(trim($this->config['auth_method'])))) + $provider_name = ($provider_name !== '') ?: basename(trim($this->config['auth_method'])); + if ($this->offsetExists('auth.provider.' . $provider_name)) { - return $this->offsetGet('auth.provider.' . basename(trim($this->config['auth_method']))); + return $this->offsetGet('auth.provider.' . $provider_name); } // Revert to db auth provider if selected method does not exist else if ($this->offsetExists('auth.provider.db')) From a9249bce5ec73b4a4a11d2db13938db6fc4dcaec Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Oct 2014 14:25:00 +0100 Subject: [PATCH 3/5] [ticket/13248] Always use provider collection for getting provider PHPBB3-13248 --- phpBB/includes/ucp/ucp_auth_link.php | 5 +++-- phpBB/includes/ucp/ucp_login_link.php | 6 +++--- phpBB/includes/ucp/ucp_register.php | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/ucp/ucp_auth_link.php b/phpBB/includes/ucp/ucp_auth_link.php index a595ce46c3..748f0fdec2 100644 --- a/phpBB/includes/ucp/ucp_auth_link.php +++ b/phpBB/includes/ucp/ucp_auth_link.php @@ -34,11 +34,12 @@ class ucp_auth_link */ public function main($id, $mode) { - global $config, $request, $template, $phpbb_container, $user; + global $request, $template, $phpbb_container, $user; $error = array(); - $auth_provider = $phpbb_container->get('auth.provider.' . $config['auth_method']); + $provider_collection = $phpbb_container->get('auth.provider_collection'); + $auth_provider = $provider_collection->get_provider(); // confirm that the auth provider supports this page $provider_data = $auth_provider->get_auth_link_data(); diff --git a/phpBB/includes/ucp/ucp_login_link.php b/phpBB/includes/ucp/ucp_login_link.php index 5ca5df00f7..27d59c56b7 100644 --- a/phpBB/includes/ucp/ucp_login_link.php +++ b/phpBB/includes/ucp/ucp_login_link.php @@ -39,7 +39,7 @@ class ucp_login_link */ function main($id, $mode) { - global $config, $phpbb_container, $request, $template, $user; + global $phpbb_container, $request, $template, $user; global $phpbb_root_path, $phpEx; // Initialize necessary variables @@ -57,8 +57,8 @@ class ucp_login_link } // Use the auth_provider requested even if different from configured - $auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']); - $auth_provider = $phpbb_container->get($auth_provider); + $provider_collection = $phpbb_container->get('auth.provider_collection'); + $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', '')); // Set the link_method to login_link $data['link_method'] = 'login_link'; diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 9a15967bae..88078c10af 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -87,8 +87,8 @@ class ucp_register if (!empty($login_link_data)) { // Confirm that we have all necessary data - $auth_provider = 'auth.provider.' . $request->variable('auth_provider', $config['auth_method']); - $auth_provider = $phpbb_container->get($auth_provider); + $provider_collection = $phpbb_container->get('auth.provider_collection'); + $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', '')); $result = $auth_provider->login_link_has_necessary_data($login_link_data); if ($result !== null) From d9c868d0f5f9c2c097e3fded0ac6882c2f2ff988 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Oct 2014 16:54:43 +0100 Subject: [PATCH 4/5] [ticket/13248] Correctly pass provider name PHPBB3-13248 --- phpBB/phpbb/auth/provider_collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/auth/provider_collection.php b/phpBB/phpbb/auth/provider_collection.php index bf724419b7..8e7e9e2cc1 100644 --- a/phpBB/phpbb/auth/provider_collection.php +++ b/phpBB/phpbb/auth/provider_collection.php @@ -49,7 +49,7 @@ class provider_collection extends \phpbb\di\service_collection */ public function get_provider($provider_name = '') { - $provider_name = ($provider_name !== '') ?: basename(trim($this->config['auth_method'])); + $provider_name = ($provider_name !== '') ? $provider_name : basename(trim($this->config['auth_method'])); if ($this->offsetExists('auth.provider.' . $provider_name)) { return $this->offsetGet('auth.provider.' . $provider_name); From 8aec6b58e087fa86c71baaccbeb07fe7a495aee5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Oct 2014 20:52:14 +0100 Subject: [PATCH 5/5] [ticket/13248] Use functional framework login method in tests PHPBB3-13248 --- tests/functional/auth_test.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 1794afd009..76e1709afb 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -43,14 +43,9 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $db = $this->get_db(); $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'"; $db->sql_query($sql); - $crawler = self::request('GET', 'ucp.php?mode=login'); - $form = $crawler->selectButton('Login')->form(); - $form->setValues(array( - 'username' => 'anothertestuser', - 'password' => str_repeat('anothertestuser', 2), - )); $config['auth_method'] = 'foobar'; - $crawler = self::submit($form); + $this->login('anothertestuser'); + $crawler = self::request('GET', 'index.php'); $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'"; $db->sql_query($sql);