[ 'activate' => $activated, ] ]; } protected function getAuth(): Auth { return (new SamlAuthFactoryFactory($this))->create()->create(); } protected function getSamlConfiguration(bool $activated = true): SamlConfiguration { return new SamlConfiguration($this->getSystemConfigurationMock($this->getDefaultSettings($activated), [])); } public function testAssertionConsumerServiceAction(): void { $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->getSamlConfiguration()); $sut->assertionConsumerServiceAction(); } public function testMetadataAction(): void { $expectedXmlString = << 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->getSamlConfiguration()); $result = $sut->metadataAction(); self::assertInstanceOf(Response::class, $result); self::assertEquals('xml', $result->headers->get('Content-Type')); $expected = new \DOMDocument(); $tmp = $expected->loadXML($expectedXmlString); self::assertTrue($tmp); $actual = new \DOMDocument(); $tmp = $actual->loadXML($result->getContent()); self::assertTrue($tmp); // the "validUntil" attribute in the outer node changes per request self::assertEquals($expected->firstChild->firstChild, $actual->firstChild->firstChild); } public function testLoginActionThrowsErrorOnSecurityErrorAttribute(): void { $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->getSamlConfiguration()); $sut->loginAction($request); } public function testLoginActionThrowsExceptionOnDisabledSaml(): void { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSamlConfiguration(false)); $sut->loginAction(new Request()); } public function testMetadataActionThrowsExceptionOnDisabledSaml(): void { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSamlConfiguration(false)); $sut->metadataAction(); } public function testLogoutActionThrowsExceptionOnDisabledSaml(): void { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSamlConfiguration(false)); $sut->logoutAction(); } public function testAcsActionThrowsExceptionOnDisabledSaml(): void { $this->expectException(NotFoundHttpException::class); $this->expectExceptionMessage('SAML deactivated'); $factory = $this->getMockBuilder(SamlAuthFactory::class)->disableOriginalConstructor()->getMock(); $sut = new SamlController($factory, $this->getSamlConfiguration(false)); $sut->assertionConsumerServiceAction(); } }