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