]> BookStack Code Mirror - bookstack/blob - tests/Auth/LoginAutoInitiateTest.php
Merge branch 'login-auto-redirect' into development
[bookstack] / tests / Auth / LoginAutoInitiateTest.php
1 <?php
2
3 namespace Tests\Auth;
4
5 use Tests\TestCase;
6
7 class LoginAutoInitiateTest extends TestCase
8 {
9
10     protected function setUp(): void
11     {
12         parent::setUp();
13
14         config()->set([
15             'auth.auto_initiate' => true,
16             'services.google.client_id' => false,
17             'services.github.client_id' => false,
18         ]);
19     }
20
21     public function test_with_oidc()
22     {
23         config()->set([
24             'auth.method' => 'oidc',
25         ]);
26
27         $req = $this->get('/login');
28         $req->assertSeeText('Attempting Login');
29         $req->assertElementExists('form[action$="/oidc/login"][method=POST][id="login-form"] button');
30         $req->assertElementExists('button[form="login-form"]');
31     }
32
33     public function test_with_saml2()
34     {
35         config()->set([
36             'auth.method' => 'saml2',
37         ]);
38
39         $req = $this->get('/login');
40         $req->assertSeeText('Attempting Login');
41         $req->assertElementExists('form[action$="/saml2/login"][method=POST][id="login-form"] button');
42         $req->assertElementExists('button[form="login-form"]');
43     }
44
45     public function test_it_does_not_run_if_social_provider_is_active()
46     {
47         config()->set([
48             'auth.method' => 'oidc',
49             'services.google.client_id' => 'abc123a',
50             'services.google.client_secret' => 'def456',
51         ]);
52
53         $req = $this->get('/login');
54         $req->assertDontSeeText('Attempting Login');
55         $req->assertSee('Log In');
56     }
57
58     public function test_it_does_not_run_if_prevent_query_string_exists()
59     {
60         config()->set([
61             'auth.method' => 'oidc',
62         ]);
63
64         $req = $this->get('/login?prevent_auto_init=true');
65         $req->assertDontSeeText('Attempting Login');
66         $req->assertSee('Log In');
67     }
68
69     public function test_logout_with_auto_init_leads_to_login_page_with_prevention_query()
70     {
71         config()->set([
72             'auth.method' => 'oidc',
73         ]);
74         $this->actingAs($this->getEditor());
75
76         $req = $this->post('/logout');
77         $req->assertRedirect('/login?prevent_auto_init=true');
78     }
79
80 }