BookStack/tests/Auth/LoginAutoInitiateTest.php
Dan Brown 8b211ed461
Review and update of login auto initiation PR
For PR #3406

- Updated naming from 'redirect' to 'initate/initation'.
- Updated phpunit.xml and .env.example.complete files with the new
  option.
- Cleaned up controller logic a bit.
- Added content and design to the new initation view to not leave user
  on a blank view for a while.
- Added non-JS button to initiation view as fallback option for
  progression.
- Moved new test to it's own Test class and expanded with additional
  scenario tests for better functionality coverage.
2022-06-21 15:32:18 +01:00

80 lines
2.1 KiB
PHP

<?php
namespace Tests\Auth;
use Tests\TestCase;
class LoginAutoInitiateTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
config()->set([
'auth.auto_initiate' => true,
'services.google.client_id' => false,
'services.github.client_id' => false,
]);
}
public function test_with_oidc()
{
config()->set([
'auth.method' => 'oidc',
]);
$req = $this->get('/login');
$req->assertSeeText('Attempting Login');
$req->assertElementExists('form[action$="/oidc/login"][method=POST][id="login-form"] button');
$req->assertElementExists('button[form="login-form"]');
}
public function test_with_saml2()
{
config()->set([
'auth.method' => 'saml2',
]);
$req = $this->get('/login');
$req->assertSeeText('Attempting Login');
$req->assertElementExists('form[action$="/saml2/login"][method=POST][id="login-form"] button');
$req->assertElementExists('button[form="login-form"]');
}
public function test_it_does_not_run_if_social_provider_is_active()
{
config()->set([
'auth.method' => 'oidc',
'services.google.client_id' => 'abc123a',
'services.google.client_secret' => 'def456',
]);
$req = $this->get('/login');
$req->assertDontSeeText('Attempting Login');
$req->assertSee('Log In');
}
public function test_it_does_not_run_if_prevent_query_string_exists()
{
config()->set([
'auth.method' => 'oidc',
]);
$req = $this->get('/login?prevent_auto_init=true');
$req->assertDontSeeText('Attempting Login');
$req->assertSee('Log In');
}
public function test_logout_with_auto_init_leads_to_login_page_with_prevention_query()
{
config()->set([
'auth.method' => 'oidc',
]);
$this->actingAs($this->getEditor());
$req = $this->post('/logout');
$req->assertRedirect('/login?prevent_auto_init=true');
}
}