mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 07:58:56 +02:00
Merge pull request #6233 from rxu/ticket/16799
[ticket/16799] Fix OAuth external account linking PHP fatal error
This commit is contained in:
commit
ccac4c5fe8
@ -85,7 +85,7 @@ abstract class base implements provider_interface
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function login_link_has_necessary_data($login_link_data)
|
public function login_link_has_necessary_data(array $login_link_data)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ class oauth extends base
|
|||||||
$provider = $this->request->variable('oauth_service', '', false);
|
$provider = $this->request->variable('oauth_service', '', false);
|
||||||
$service_name = $this->get_service_name($provider);
|
$service_name = $this->get_service_name($provider);
|
||||||
|
|
||||||
if ($provider === '' || !array_key_exists($service_name, $this->service_providers))
|
if ($provider === '' || !$this->service_providers->offsetExists($service_name))
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
|
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
|
||||||
@ -411,7 +411,7 @@ class oauth extends base
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function login_link_has_necessary_data($login_link_data)
|
public function login_link_has_necessary_data(array $login_link_data)
|
||||||
{
|
{
|
||||||
if (empty($login_link_data))
|
if (empty($login_link_data))
|
||||||
{
|
{
|
||||||
@ -452,7 +452,7 @@ class oauth extends base
|
|||||||
|
|
||||||
$service_name = $this->get_service_name($link_data['oauth_service']);
|
$service_name = $this->get_service_name($link_data['oauth_service']);
|
||||||
|
|
||||||
if (!array_key_exists($service_name, $this->service_providers))
|
if (!$this->service_providers->offsetExists($service_name))
|
||||||
{
|
{
|
||||||
return 'LOGIN_ERROR_OAUTH_SERVICE_DOES_NOT_EXIST';
|
return 'LOGIN_ERROR_OAUTH_SERVICE_DOES_NOT_EXIST';
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ interface provider_interface
|
|||||||
* @return string|null Returns a string with a language constant if there
|
* @return string|null Returns a string with a language constant if there
|
||||||
* is data missing or null if there is no error.
|
* is data missing or null if there is no error.
|
||||||
*/
|
*/
|
||||||
public function login_link_has_necessary_data($login_link_data);
|
public function login_link_has_necessary_data(array $login_link_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Links an external account to a phpBB account.
|
* Links an external account to a phpBB account.
|
||||||
|
@ -77,4 +77,63 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
|
|||||||
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
|
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
|
||||||
$this->assertStringContainsString($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
|
$this->assertStringContainsString($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_board_auth_oauth_setting()
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
$this->admin_login();
|
||||||
|
$this->add_lang(['ucp', 'acp/board']);
|
||||||
|
|
||||||
|
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
|
||||||
|
$this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
|
||||||
|
|
||||||
|
// Set OAuth authentication method for Google with random keys
|
||||||
|
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
|
||||||
|
'config[auth_method]' => 'oauth',
|
||||||
|
'config[auth_oauth_google_key]' => '123456',
|
||||||
|
'config[auth_oauth_google_secret]' => '123456',
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
|
||||||
|
|
||||||
|
// Test OAuth linking via UCP
|
||||||
|
$crawler = self::request('GET', 'ucp.php?i=ucp_auth_link&mode=auth_link&sid=' . $this->sid);
|
||||||
|
$this->assertStringContainsString($this->lang('AUTH_PROVIDER_OAUTH_SERVICE_GOOGLE'), $crawler->filter('h3')->text());
|
||||||
|
$form = $crawler->selectButton($this->lang('UCP_AUTH_LINK_LINK'))->form();
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertStringContainsString('Google Accounts', $crawler->filter('title')->text());
|
||||||
|
|
||||||
|
// Test OAuth linking for registration
|
||||||
|
$this->logout();
|
||||||
|
$crawler = self::request('GET', 'ucp.php?mode=register');
|
||||||
|
$this->assertContainsLang('REGISTRATION', $crawler->filter('div.content h2')->text());
|
||||||
|
$form = $crawler->selectButton('I agree to these terms')->form();
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertContainsLang('AUTH_PROVIDER_OAUTH_SERVICE_GOOGLE', $crawler->filter('a[class="button2"]')->text());
|
||||||
|
$crawler = self::request('GET', 'ucp.php?mode=login&login=external&oauth_service=google');
|
||||||
|
$this->assertStringContainsString('Google Accounts', $crawler->filter('title')->text());
|
||||||
|
|
||||||
|
// Restore default auth method, but unset random keys first
|
||||||
|
// Restart webclient as we were redirected to external site before
|
||||||
|
self::$client->restart();
|
||||||
|
|
||||||
|
$this->login();
|
||||||
|
$this->admin_login();
|
||||||
|
|
||||||
|
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
|
||||||
|
$this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
|
||||||
|
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
|
||||||
|
'config[auth_oauth_google_key]' => '',
|
||||||
|
'config[auth_oauth_google_secret]' => '',
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
|
||||||
|
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
|
||||||
|
$this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
|
||||||
|
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
|
||||||
|
'config[auth_method]' => 'db',
|
||||||
|
]);
|
||||||
|
$crawler = self::submit($form);
|
||||||
|
$this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -973,7 +973,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
|||||||
// Any output before the doc type means there was an error
|
// Any output before the doc type means there was an error
|
||||||
$content = self::get_content();
|
$content = self::get_content();
|
||||||
self::assertStringNotContainsString('[phpBB Debug]', $content);
|
self::assertStringNotContainsString('[phpBB Debug]', $content);
|
||||||
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
|
self::assertStringStartsWith('<!DOCTYPE', strtoupper(substr(trim($content), 0, 10)), 'Output found before DOCTYPE specification.');
|
||||||
|
|
||||||
if ($status_code !== false)
|
if ($status_code !== false)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user