Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 68
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_functional_auth_test
0.00% covered (danger)
0.00%
0 / 68
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 test_login
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_login_other
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_login_ucp_other_auth_provider
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 test_logout
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 test_acp_login
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 test_board_auth_oauth_setting
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @group functional
16*/
17class phpbb_functional_auth_test extends phpbb_functional_test_case
18{
19    public function test_login()
20    {
21        $this->login();
22
23        // check for logout link
24        $crawler = self::request('GET', 'index.php');
25        $this->assertStringContainsString($this->lang('LOGOUT', 'admin'), $crawler->filter('.navbar')->text());
26    }
27
28    public function test_login_other()
29    {
30        $this->create_user('anothertestuser');
31        $this->login('anothertestuser');
32        $crawler = self::request('GET', 'index.php');
33        $this->assertStringContainsString('anothertestuser', $crawler->filter('#username_logged_in')->text());
34    }
35
36    /**
37     * @dependsOn test_login_other
38     */
39    public function test_login_ucp_other_auth_provider()
40    {
41        global $cache, $config;
42        $cache = new phpbb_mock_null_cache;
43        $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'";
44        $this->db->sql_query($sql);
45        $config['auth_method'] = 'foobar';
46        $this->login('anothertestuser');
47        $crawler = self::request('GET', 'index.php');
48        $this->assertStringContainsString('anothertestuser', $crawler->filter('#username_logged_in')->text());
49        $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name =  'auth_method'";
50        $this->db->sql_query($sql);
51        $config['auth_method'] = 'db';
52    }
53
54    /**
55    * @depends test_login
56    */
57    public function test_logout()
58    {
59        $this->login();
60        $this->add_lang('ucp');
61
62        $this->logout();
63    }
64
65    public function test_acp_login()
66    {
67        $this->login();
68        $this->admin_login();
69
70        // check that we are logged in
71        $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
72        $this->assertStringContainsString($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
73    }
74
75    public function test_board_auth_oauth_setting()
76    {
77        $this->login();
78        $this->admin_login();
79        $this->add_lang(['ucp', 'acp/board']);
80
81        $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
82        $this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
83
84        // Set OAuth authentication method for Google with random keys
85        $form = $crawler->selectButton($this->lang('SUBMIT'))->form([
86            'config[auth_method]' => 'oauth',
87            'config[auth_oauth_google_key]' => '123456',
88            'config[auth_oauth_google_secret]' => '123456',
89        ]);
90        $crawler = self::submit($form);
91        $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
92
93        // Test OAuth linking via UCP
94        $crawler = self::request('GET', 'ucp.php?i=ucp_auth_link&mode=auth_link&sid=' . $this->sid);
95        $this->assertStringContainsString($this->lang('AUTH_PROVIDER_OAUTH_SERVICE_GOOGLE'), $crawler->filter('h3')->text());
96        $form = $crawler->selectButton($this->lang('UCP_AUTH_LINK_LINK'))->form();
97        $crawler = self::submit($form);
98        $this->assertStringContainsString('accounts.google.com', $crawler->filter('base')->attr('href'));
99
100        // Test OAuth linking for registration
101        $this->logout();
102        $crawler = self::request('GET', 'ucp.php?mode=register');
103        $this->assertContainsLang('REGISTRATION', $crawler->filter('div.content h2')->text());
104        $form = $crawler->selectButton('I agree to these terms')->form();
105        $crawler = self::submit($form);
106        $this->assertContainsLang('AUTH_PROVIDER_OAUTH_SERVICE_GOOGLE', $crawler->filter('a.button1')->text());
107        $crawler = self::request('GET', 'ucp.php?mode=login&login=external&oauth_service=google');
108        $this->assertStringContainsString('accounts.google.com', $crawler->filter('base')->attr('href'));
109
110        // Restore default auth method, but unset random keys first
111        // Restart webclient as we were redirected to external site before
112        self::$client->restart();
113
114        $this->login();
115        $this->admin_login();
116
117        $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
118        $this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
119        $form = $crawler->selectButton($this->lang('SUBMIT'))->form([
120            'config[auth_oauth_google_key]' => '',
121            'config[auth_oauth_google_secret]' => '',
122        ]);
123        $crawler = self::submit($form);
124        $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
125        $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=auth&sid=' . $this->sid);
126        $this->assertStringContainsString($this->lang('AUTH_METHOD'), $crawler->filter('label[for="auth_method"]')->text());
127        $form = $crawler->selectButton($this->lang('SUBMIT'))->form([
128            'config[auth_method]' => 'db',
129        ]);
130        $crawler = self::submit($form);
131        $this->assertContainsLang('CONFIG_UPDATED', $crawler->filter('div[class="successbox"] > p')->text());
132    }
133}