|
2 | 2 |
|
3 | 3 | namespace Surfnet\SamlBundle\Tests\Unit\SAML2; |
4 | 4 |
|
| 5 | +use Mockery as m; |
5 | 6 | use PHPUnit_Framework_TestCase as UnitTest; |
| 7 | +use RobRichards\XMLSecLibs\XMLSecurityKey; |
| 8 | +use SAML2\Configuration\PrivateKey; |
| 9 | +use Surfnet\SamlBundle\Entity\IdentityProvider; |
| 10 | +use Surfnet\SamlBundle\Entity\ServiceProvider; |
6 | 11 | use Surfnet\SamlBundle\SAML2\AuthnRequest; |
7 | 12 | use Surfnet\SamlBundle\SAML2\AuthnRequestFactory; |
8 | 13 | use Symfony\Component\HttpFoundation\Request; |
@@ -46,4 +51,27 @@ public function an_exception_is_thrown_when_a_request_cannot_be_inflated() |
46 | 51 |
|
47 | 52 | AuthnRequestFactory::createFromHttpRequest($request); |
48 | 53 | } |
| 54 | + |
| 55 | + /** |
| 56 | + * @test |
| 57 | + * @group saml2 |
| 58 | + */ |
| 59 | + public function verify_force_authn_works_as_intended() |
| 60 | + { |
| 61 | + $sp = m::mock(ServiceProvider::class); |
| 62 | + $sp->shouldReceive('getAssertionConsumerUrl')->andReturn('https://example-sp.com/acs'); |
| 63 | + $sp->shouldReceive('getEntityId')->andReturn('https://example-sp.com/'); |
| 64 | + |
| 65 | + $pk = new PrivateKey(__DIR__.'/../../../Resources/keys/development_privatekey.pem', 'key-for-test', ''); |
| 66 | + |
| 67 | + $sp->shouldReceive('getPrivateKey')->andReturn($pk); |
| 68 | + |
| 69 | + $idp = m::mock(IdentityProvider::class); |
| 70 | + $idp->shouldReceive('getSsoUrl')->andReturn('https://example-idp.com/sso'); |
| 71 | + |
| 72 | + $authnRequest = AuthnRequestFactory::createNewRequest($sp, $idp, true); |
| 73 | + $this->assertTrue($authnRequest->isForceAuthn()); |
| 74 | + $authnRequest = AuthnRequestFactory::createNewRequest($sp, $idp, false); |
| 75 | + $this->assertFalse($authnRequest->isForceAuthn()); |
| 76 | + } |
49 | 77 | } |
0 commit comments