request('GET', '/'); $this->assertIsRedirect($client, $this->createUrl('/homepage')); $client->followRedirect(); $this->assertIsRedirect($client, $this->createUrl('/login')); } public function testLoginPageIsRendered(): void { $client = self::createClient(); $this->request($client, '/login'); $response = $client->getResponse(); $this->assertTrue($client->getResponse()->isSuccessful()); $content = $response->getContent(); $this->assertStringContainsString('Kimai – Time Tracking', $content); $this->assertStringContainsString('
assertStringContainsString('assertStringContainsString('assertStringContainsString('">Log in', $content); $this->assertStringContainsString('assertStringNotContainsString('Register a new account', $content); } public function testLoginPositive(): void { $client = self::createClient(); $this->request($client, '/login'); $this->assertTrue($client->getResponse()->isSuccessful()); $form = $client->getCrawler()->filter('body form')->form(); $client->submit($form, [ '_username' => 'susan_super', '_password' => 'kitten' ]); $this->assertIsRedirect($client); // redirect to root URL $client->followRedirect(); $this->assertIsRedirect($client, '/homepage'); // redirect to homepage $client->followRedirect(); $this->assertIsRedirect($client, '/timesheet/'); // redirect to configured start page $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful()); } public function testLoginAlreadyLoggedIn(): void { $client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD); $this->request($client, '/login'); $this->assertIsRedirect($client, '/homepage'); // redirect to homepage $client->followRedirect(); $this->assertIsRedirect($client, '/timesheet/'); // redirect to configured start page $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful()); } public function testLoginNegative(): void { $client = self::createClient(); $this->request($client, '/login'); $this->assertTrue($client->getResponse()->isSuccessful()); $form = $client->getCrawler()->filter('body form')->form(); $client->submit($form, [ '_username' => 'susan_super', '_password' => '1234567890' ]); $this->assertIsRedirect($client); // redirect to root URL $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful()); self::assertStringContainsString('
Invalid credentials.
', $client->getResponse()->getContent()); } public function testCheckAction(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); self::createClient(); // just to bootstrap the container $csrf = $this->createMock(CsrfTokenManagerInterface::class); $systemConfig = new SystemConfiguration(new TestConfigLoader([]), ['saml' => ['activate' => true]]); $samlConfig = new SamlConfiguration($systemConfig); $sut = new SecurityController($csrf, $samlConfig); $sut->checkAction(); } public function testLogoutAction(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('You must activate the logout in your security firewall configuration.'); self::createClient(); // just to bootstrap the container $csrf = $this->createMock(CsrfTokenManagerInterface::class); $systemConfig = new SystemConfiguration(new TestConfigLoader([]), ['saml' => ['activate' => true]]); $samlConfig = new SamlConfiguration($systemConfig); $sut = new SecurityController($csrf, $samlConfig); $sut->logoutAction(); } }