11<?php
22
33use Jumbojett \OpenIDConnectClient ;
4+ use Jumbojett \OpenIDConnectClientException ;
45
56class OpenIDConnectClientTest extends PHPUnit_Framework_TestCase
67{
@@ -17,4 +18,39 @@ public function testGetRedirectURL()
1718 $ _SERVER ['REQUEST_URI ' ] = '/path/index.php?foo=bar&baz#fragment ' ;
1819 self ::assertSame ('http://domain.test/path/index.php ' , $ client ->getRedirectURL ());
1920 }
21+
22+ public function testAuthenticateDoesNotThrowExceptionIfClaimsIsMissingNonce ()
23+ {
24+ $ fakeClaims = new \StdClass ();
25+ $ fakeClaims ->iss = 'fake-issuer ' ;
26+ $ fakeClaims ->aud = 'fake-client-id ' ;
27+ $ fakeClaims ->nonce = null ;
28+
29+ $ _REQUEST ['id_token ' ] = 'abc.123.xyz ' ;
30+ $ _REQUEST ['state ' ] = false ;
31+ $ _SESSION ['openid_connect_state ' ] = false ;
32+
33+ /** @var OpenIDConnectClient | PHPUnit_Framework_MockObject_MockObject $client */
34+ $ client = $ this ->getMockBuilder (OpenIDConnectClient::class)->setMethods (['decodeJWT ' , 'getProviderConfigValue ' , 'verifyJWTsignature ' ])->getMock ();
35+ $ client ->method ('decodeJWT ' )->willReturn ($ fakeClaims );
36+ $ client ->method ('getProviderConfigValue ' )->with ('jwks_uri ' )->willReturn (true );
37+ $ client ->method ('verifyJWTsignature ' )->willReturn (true );
38+
39+ $ client ->setClientID ('fake-client-id ' );
40+ $ client ->setIssuer ('fake-issuer ' );
41+ $ client ->setIssuerValidator (function () {
42+ return true ;
43+ });
44+ $ client ->setAllowImplicitFlow (true );
45+ $ client ->setProviderURL ('https://jwt.io/ ' );
46+
47+ try {
48+ $ authenticated = $ client ->authenticate ();
49+ $ this ->assertTrue ($ authenticated );
50+ } catch ( OpenIDConnectClientException $ e ) {
51+ if ( $ e ->getMessage () === 'Unable to verify JWT claims ' ) {
52+ self ::fail ( 'OpenIDConnectClientException was thrown when it should not have been. ' );
53+ }
54+ }
55+ }
2056}
0 commit comments