22namespace ADmad \JwtAuth \Auth \Test \TestCase \Auth ;
33
44use ADmad \JwtAuth \Auth \JwtAuthenticate ;
5- use Cake \Controller \Component \AuthComponent ;
6- use Cake \Controller \Controller ;
75use Cake \Core \Configure ;
86use Cake \I18n \Time ;
97use Cake \Network \Request ;
1412use Firebase \JWT \JWT ;
1513
1614/**
17- * Test case for JwtAuthentication
15+ * Test case for JwtAuthentication.
1816 */
1917class JwtAuthenticateTest extends TestCase
2018{
@@ -24,7 +22,7 @@ class JwtAuthenticateTest extends TestCase
2422 ];
2523
2624 /**
27- * setup
25+ * setup.
2826 *
2927 * @return void
3028 */
@@ -36,7 +34,7 @@ public function setUp()
3634
3735 $ this ->Registry = $ this ->getMock ('Cake\Controller\ComponentRegistry ' );
3836 $ this ->auth = new JwtAuthenticate ($ this ->Registry , [
39- 'userModel ' => 'Users '
37+ 'userModel ' => 'Users ' ,
4038 ]);
4139
4240 $ this ->token = JWT ::encode (['sub ' => 1 ], Security::salt ());
@@ -45,7 +43,7 @@ public function setUp()
4543 }
4644
4745 /**
48- * test authenticate token as query parameter
46+ * test authenticate token as query parameter.
4947 *
5048 * @return void
5149 */
@@ -62,7 +60,7 @@ public function testAuthenticateTokenParameter()
6260 'user_name ' => 'admad ' ,
6361 'email ' => 'admad@example.com ' ,
6462 'created ' => new Time ('2014-03-17 01:18:23 ' ),
65- 'updated ' => new Time ('2014-03-17 01:20:31 ' )
63+ 'updated ' => new Time ('2014-03-17 01:20:31 ' ),
6664 ];
6765 $ request = new Request ('posts/index?token= ' . $ this ->token );
6866 $ result = $ this ->auth ->getUser ($ request , $ this ->response );
@@ -75,7 +73,7 @@ public function testAuthenticateTokenParameter()
7573 }
7674
7775 /**
78- * test authenticate token as request header
76+ * test authenticate token as request header.
7977 *
8078 * @return void
8179 */
@@ -89,7 +87,7 @@ public function testAuthenticateTokenHeader()
8987 'user_name ' => 'admad ' ,
9088 'email ' => 'admad@example.com ' ,
9189 'created ' => new Time ('2014-03-17 01:18:23 ' ),
92- 'updated ' => new Time ('2014-03-17 01:20:31 ' )
90+ 'updated ' => new Time ('2014-03-17 01:20:31 ' ),
9391 ];
9492 $ request ->env ('HTTP_AUTHORIZATION ' , 'Bearer ' . $ this ->token );
9593 $ result = $ this ->auth ->getUser ($ request , $ this ->response );
@@ -113,7 +111,7 @@ public function testQueryDatasourceFalse()
113111 $ expected = [
114112 'id ' => 99 ,
115113 'username ' => 'ADmad ' ,
116- 'group ' => ['name ' => 'admin ' ]
114+ 'group ' => ['name ' => 'admin ' ],
117115 ];
118116 $ request ->env (
119117 'HTTP_AUTHORIZATION ' ,
@@ -125,7 +123,7 @@ public function testQueryDatasourceFalse()
125123 }
126124
127125 /**
128- * test for valid token but no matching user found in db
126+ * test for valid token but no matching user found in db.
129127 *
130128 * @return void
131129 */
@@ -140,7 +138,7 @@ public function testWithValidTokenButNoUserInDb()
140138 }
141139
142140 /**
143- * test contain
141+ * test contain.
144142 *
145143 * @return void
146144 */
@@ -157,8 +155,8 @@ public function testFindUserWithContain()
157155 'updated ' => new Time ('2014-03-17 01:20:31 ' ),
158156 'group ' => [
159157 'id ' => 1 ,
160- 'title ' => 'admin '
161- ]
158+ 'title ' => 'admin ' ,
159+ ],
162160 ];
163161 $ request ->env ('HTTP_AUTHORIZATION ' , 'Bearer ' . $ this ->token );
164162
@@ -176,7 +174,7 @@ public function testFindUserWithContain()
176174 }
177175
178176 /**
179- * Test that authenticated() always returns false
177+ * Test that authenticated() always returns false.
180178 *
181179 * @return void
182180 */
@@ -187,7 +185,7 @@ public function testAuthenticated()
187185
188186 /**
189187 * test that with debug off for invalid token exception from JWT::decode()
190- * is re-thrown
188+ * is re-thrown.
191189 *
192190 * @expectedException DomainException
193191 */
@@ -213,7 +211,7 @@ public function testUnauthenticated()
213211
214212 /**
215213 * test unauthenticated() doesn't throw exception is config `unauthenticatedException`
216- * is set to falsey value
214+ * is set to falsey value.
217215 */
218216 public function testUnauthenticatedNoException ()
219217 {
@@ -223,7 +221,7 @@ public function testUnauthenticatedNoException()
223221
224222 /**
225223 * test that getUser() returns false instead of throwing exception with
226- * invalid token when debug is off
224+ * invalid token when debug is off.
227225 *
228226 * @return void
229227 */
0 commit comments