88use Firebase \JWT \Key ;
99use Firebase \JWT \JWK as FirebaseJWK ;
1010use MixerApi \JwtAuth \Configuration \Configuration ;
11+ use MixerApi \JwtAuth \Exception \JwtAuthException ;
1112use MixerApi \JwtAuth \Jwk \JwkSet ;
1213
1314class ControllerTest extends TestCase
@@ -23,10 +24,13 @@ class ControllerTest extends TestCase
2324
2425 public function setUp (): void
2526 {
26- parent ::setUp (); // TODO: Change the autogenerated stub
27+ parent ::setUp ();
2728 static ::setAppNamespace ('MixerApi\JwtAuth\Test\App ' );
2829 }
2930
31+ /**
32+ * When requesting the JWKS endpoint, the server responds with the keyset.
33+ */
3034 public function test_jwks (): void
3135 {
3236 TestHelper::createRs256Config ();
@@ -38,9 +42,12 @@ public function test_jwks(): void
3842 }
3943
4044 /**
45+ * When a valid login request is made with the given algorithm, the server responds with a JWT.
46+ *
4147 * @dataProvider dataProviderForAlg
4248 * @param string $alg
4349 * @return void
50+ * @throws JwtAuthException
4451 */
4552 public function test_login (string $ alg ): void
4653 {
@@ -60,6 +67,8 @@ public function test_login(string $alg): void
6067 }
6168
6269 /**
70+ * When a login request is made with invalid credentials for the given algorithm the server responds with a 401.
71+ *
6372 * @dataProvider dataProviderForAlg
6473 * @param string $alg
6574 * @return void
@@ -72,6 +81,29 @@ public function test_login_fails(string $alg): void
7281 }
7382
7483 /**
84+ * When an authenticated request is made to an endpoint requiring authentication, the server responds with a 200.
85+ *
86+ * @dataProvider dataProviderForAlg
87+ * @param string $alg
88+ * @return void
89+ */
90+ public function test_auth_works (string $ alg ): void
91+ {
92+ $ alg === 'RS ' ? TestHelper::createRs256Config () : TestHelper::createHs256Config ();
93+ $ this ->
post (
'/test/login.json ' , [
'email ' =>
'[email protected] ' ,
'password ' =>
'password ' ]);
94+ $ this ->assertResponseCode (200 );
95+ $ body = (string )$ this ->_response ->getBody ();
96+ $ this ->configRequest ([
97+ 'headers ' => ['Authorization ' => 'Bearer ' . $ body ],
98+ ]);
99+
100+ $ this ->get ('/test/index.json ' );
101+ $ this ->assertResponseOk ();
102+ }
103+
104+ /**
105+ * When an unauthenticated request is made to an endpoint requiring authentication, the server responds with a 401.
106+ *
75107 * @dataProvider dataProviderForAlg
76108 * @param string $alg
77109 * @return void
0 commit comments