[ 'activate' => $activated, ] ]; } protected function getAuth(): Auth { return (new SamlAuthFactoryFactory($this))->create()->create(); } protected function getSystemConfiguration(bool $activated = true) { return $this->getSystemConfigurationMock($this->getDefaultSettings($activated), []); } public function testAssertionConsumerServiceAction() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('You must configure the check path in your firewall.'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration()); $sut->assertionConsumerServiceAction(); } public function testLogoutAction() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('You must configure the logout path in your firewall.'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration()); $sut->logoutAction(); } public function testMetadataAction() { $expected = << urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified Kimai Kimai https://www.kimai.org Kimai Admin kimai-tech@example.com Kimai Support kimai-support@example.com EOD; $oauth = $this->getAuth(); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $factory->expects($this->once())->method('create')->willReturn($oauth); $sut = new SamlController($factory, $this->getSystemConfiguration()); $result = $sut->metadataAction(); self::assertInstanceOf(Response::class, $result); self::assertEquals('xml', $result->headers->get('Content-Type')); $expected = Xml::load($expected); $actual = Xml::load($result->getContent()); // the "validUntil" attribute in the outer node changes per request self::assertEquals($expected->firstChild->firstChild, $actual->firstChild->firstChild); } public function testLoginActionThrowsErrorOnSecurityErrorAttribute() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('My test error'); $request = new Request(); $request->setSession($this->createMock(SessionInterface::class)); $request->attributes->set(Security::AUTHENTICATION_ERROR, new \Exception('My test error')); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration()); $sut->loginAction($request); } public function testLoginActionThrowsExceptionOnDisabledSaml() { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration(false)); $sut->loginAction(new Request()); } public function testMetadataActionThrowsExceptionOnDisabledSaml() { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration(false)); $sut->metadataAction(); } public function testLogoutActionThrowsExceptionOnDisabledSaml() { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration(false)); $sut->logoutAction(); } public function testAcsActionThrowsExceptionOnDisabledSaml() { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSystemConfiguration(false)); $sut->assertionConsumerServiceAction(); } }