33
44use Auth0 \Login \Auth0Service ;
55use Auth0 \Login \Facade \Auth0 as Auth0Facade ;
6- use Auth0 \Login \LaravelSessionStore ;
76use Auth0 \Login \LoginServiceProvider as Auth0ServiceProvider ;
8- use Auth0 \SDK \API \Helpers \State \DummyStateHandler ;
9- use Auth0 \SDK \Store \EmptyStore ;
7+ use Auth0 \SDK \Exception \InvalidTokenException ;
108use Auth0 \SDK \Store \SessionStore ;
9+ use Illuminate \Http \RedirectResponse ;
10+ use Illuminate \Support \Facades \Cache ;
1111use Orchestra \Testbench \TestCase as OrchestraTestCase ;
12- use Session ;
1312
1413class Auth0ServiceTest extends OrchestraTestCase
1514{
@@ -23,13 +22,19 @@ public static function setUpBeforeClass()
2322 'client_id ' => '__test_client_id__ ' ,
2423 'client_secret ' => '__test_client_secret__ ' ,
2524 'redirect_uri ' => 'https://example.com/callback ' ,
25+ 'transient_store ' => new SessionStore (),
2626 ];
2727 }
2828
29+ public function tearDown () : void
30+ {
31+ Cache::flush ();
32+ }
33+
2934 public function testThatServiceUsesSessionStoreByDefault ()
3035 {
31- Session:: put ( 'auth0__user ' , '__test_user__ ' );
32- $ service = new Auth0Service (self ::$ defaultConfig, new LaravelSessionStore (), new DummyStateHandler () );
36+ session ([ 'auth0__user ' => '__test_user__ ' ] );
37+ $ service = new Auth0Service (self ::$ defaultConfig );
3338 $ user = $ service ->getUser ();
3439
3540 $ this ->assertArrayHasKey ('profile ' , $ user );
@@ -38,12 +43,9 @@ public function testThatServiceUsesSessionStoreByDefault()
3843
3944 public function testThatServiceSetsEmptyStoreFromConfigAndConstructor ()
4045 {
41- Session:: put ( 'auth0__user ' , '__test_user__ ' );
46+ session ([ 'auth0__user ' => '__test_user__ ' ] );
4247
43- $ service = new Auth0Service (self ::$ defaultConfig + ['store ' => false , 'state_handler ' => false ]);
44- $ this ->assertNull ($ service ->getUser ());
45-
46- $ service = new Auth0Service (self ::$ defaultConfig , new EmptyStore (), new DummyStateHandler ());
48+ $ service = new Auth0Service (self ::$ defaultConfig + ['store ' => false ]);
4749 $ this ->assertNull ($ service ->getUser ());
4850
4951 $ service = new Auth0Service (self ::$ defaultConfig );
@@ -52,11 +54,10 @@ public function testThatServiceSetsEmptyStoreFromConfigAndConstructor()
5254
5355 public function testThatServiceLoginReturnsRedirect ()
5456 {
55-
5657 $ service = new Auth0Service (self ::$ defaultConfig );
5758 $ redirect = $ service ->login ();
5859
59- $ this ->assertInstanceOf ( \ Illuminate \ Http \ RedirectResponse::class, $ redirect );
60+ $ this ->assertInstanceOf ( RedirectResponse::class, $ redirect );
6061
6162 $ targetUrl = parse_url ($ redirect ->getTargetUrl ());
6263
@@ -68,6 +69,22 @@ public function testThatServiceLoginReturnsRedirect()
6869 $ this ->assertContains ('client_id=__test_client_id__ ' , $ targetUrlQuery );
6970 }
7071
72+ /**
73+ * @throws InvalidTokenException
74+ */
75+ public function testThatServiceCanUseLaravelCache ()
76+ {
77+ $ cache_key = md5 ('https://__invalid_domain__/.well-known/jwks.json ' );
78+ cache ([$ cache_key => [uniqid ()]], 10 );
79+ session (['auth0__nonce ' => uniqid ()]);
80+
81+ $ service = new Auth0Service (['domain ' => '__invalid_domain__ ' ] + self ::$ defaultConfig );
82+
83+ // Without the cache set above, would expect a cURL error for a bad domain.
84+ $ this ->expectException (InvalidTokenException::class);
85+ $ service ->decodeJWT (uniqid ());
86+ }
87+
7188 /*
7289 * Test suite helpers
7390 */
0 commit comments