1414
1515use App \Events \UserPasswordResetSuccessful ;
1616use App \Jobs \EmitAuditLogJob ;
17- use App \Jobs \RevokeUserGrants ;
17+ use App \Jobs \RevokeUserGrantsOnExplicitLogout ;
18+ use App \Jobs \RevokeUserGrantsOnPasswordChange ;
19+ use App \Jobs \RevokeUserGrantsOnSessionRevocation ;
1820use Auth \User ;
1921use Illuminate \Support \Facades \Config ;
2022use Illuminate \Support \Facades \Event ;
@@ -51,12 +53,12 @@ protected function tearDown(): void
5153 }
5254
5355 // -------------------------------------------------------------------------
54- // Test 1: Dispatching UserPasswordResetSuccessful fires RevokeUserGrants
56+ // Test 1: Dispatching UserPasswordResetSuccessful fires RevokeUserGrantsOnPasswordChange
5557 // -------------------------------------------------------------------------
5658
5759 /**
5860 * When a UserPasswordResetSuccessful event is fired the EventServiceProvider
59- * listener must schedule a RevokeUserGrants job ( all clients, reason = 'password change') .
61+ * listener must schedule a RevokeUserGrantsOnPasswordChange job for all clients.
6062 */
6163 public function testPasswordResetEventDispatchesRevokeUserGrantsJob (): void
6264 {
@@ -65,28 +67,25 @@ public function testPasswordResetEventDispatchesRevokeUserGrantsJob(): void
6567 // afterResponse() registers a terminating callback; fire it now.
6668 app ()->terminate ();
6769
68- Queue::assertPushed (RevokeUserGrants::class, function (RevokeUserGrants $ job ) {
69- $ ref = new \ReflectionObject ($ job );
70- $ userId = $ ref ->getProperty ('user_id ' );
71- $ clientId = $ ref ->getProperty ('client_id ' );
72- $ reason = $ ref ->getProperty ('reason ' );
70+ Queue::assertPushed (RevokeUserGrantsOnPasswordChange::class, function (RevokeUserGrantsOnPasswordChange $ job ) {
71+ $ ref = new \ReflectionClass (\App \Jobs \RevokeUserGrants::class);
72+ $ userId = $ ref ->getProperty ('user_id ' );
73+ $ clientId = $ ref ->getProperty ('client_id ' );
7374 $ userId ->setAccessible (true );
7475 $ clientId ->setAccessible (true );
75- $ reason ->setAccessible (true );
7676
7777 return $ userId ->getValue ($ job ) === $ this ->test_user ->getId ()
78- && $ clientId ->getValue ($ job ) === null
79- && $ reason ->getValue ($ job ) === 'password change ' ;
78+ && $ clientId ->getValue ($ job ) === null ;
8079 });
8180 }
8281
8382 // -------------------------------------------------------------------------
84- // Test 2: PUT /admin/api/v1/users/me with password schedules RevokeUserGrants
83+ // Test 2: PUT /admin/api/v1/users/me with password schedules RevokeUserGrantsOnPasswordChange
8584 // -------------------------------------------------------------------------
8685
8786 /**
88- * Posting a new password via the profile API must schedule a RevokeUserGrants
89- * job so tokens from other sessions are revoked.
87+ * Posting a new password via the profile API must schedule a
88+ * RevokeUserGrantsOnPasswordChange job so tokens from other sessions are revoked.
9089 */
9190 public function testProfilePasswordChangePutsRevokeUserGrantsJobOnQueue (): void
9291 {
@@ -105,15 +104,12 @@ public function testProfilePasswordChangePutsRevokeUserGrantsJobOnQueue(): void
105104 // The listener for UserPasswordResetSuccessful uses afterResponse().
106105 app ()->terminate ();
107106
108- Queue::assertPushed (RevokeUserGrants ::class, function (RevokeUserGrants $ job ) {
109- $ ref = new \ReflectionObject ( $ job );
107+ Queue::assertPushed (RevokeUserGrantsOnPasswordChange ::class, function (RevokeUserGrantsOnPasswordChange $ job ) {
108+ $ ref = new \ReflectionClass (\ App \ Jobs \RevokeUserGrants::class );
110109 $ clientId = $ ref ->getProperty ('client_id ' );
111- $ reason = $ ref ->getProperty ('reason ' );
112110 $ clientId ->setAccessible (true );
113- $ reason ->setAccessible (true );
114111
115- return $ clientId ->getValue ($ job ) === null
116- && $ reason ->getValue ($ job ) === 'password change ' ;
112+ return $ clientId ->getValue ($ job ) === null ;
117113 });
118114 }
119115
@@ -165,12 +161,12 @@ public function testCurrentSessionPreservedAfterPasswordChange(): void
165161 }
166162
167163 // -------------------------------------------------------------------------
168- // Test 5: DELETE /admin/api/v1/users/me/tokens schedules RevokeUserGrants
164+ // Test 5: DELETE /admin/api/v1/users/me/tokens schedules RevokeUserGrantsOnSessionRevocation
169165 // -------------------------------------------------------------------------
170166
171167 /**
172168 * The "sign out all other devices" endpoint must respond with 204 and
173- * schedule a RevokeUserGrants job for all clients.
169+ * schedule a RevokeUserGrantsOnSessionRevocation job for all clients.
174170 */
175171 public function testBulkRevokeEndpointSchedulesRevokeUserGrantsJob (): void
176172 {
@@ -179,23 +175,20 @@ public function testBulkRevokeEndpointSchedulesRevokeUserGrantsJob(): void
179175
180176 app ()->terminate ();
181177
182- Queue::assertPushed (RevokeUserGrants ::class, function (RevokeUserGrants $ job ) {
183- $ ref = new \ReflectionObject ( $ job );
178+ Queue::assertPushed (RevokeUserGrantsOnSessionRevocation ::class, function (RevokeUserGrantsOnSessionRevocation $ job ) {
179+ $ ref = new \ReflectionClass (\ App \ Jobs \RevokeUserGrants::class );
184180 $ userId = $ ref ->getProperty ('user_id ' );
185181 $ clientId = $ ref ->getProperty ('client_id ' );
186- $ reason = $ ref ->getProperty ('reason ' );
187182 $ userId ->setAccessible (true );
188183 $ clientId ->setAccessible (true );
189- $ reason ->setAccessible (true );
190184
191185 return $ userId ->getValue ($ job ) === $ this ->test_user ->getId ()
192- && $ clientId ->getValue ($ job ) === null
193- && $ reason ->getValue ($ job ) === 'user-initiated session revocation ' ;
186+ && $ clientId ->getValue ($ job ) === null ;
194187 });
195188 }
196189
197190 // -------------------------------------------------------------------------
198- // Test 6: RevokeUserGrants::handle() calls revokeUsersToken with client_id
191+ // Test 6: RevokeUserGrantsOnExplicitLogout passes client_id to token service
199192 // -------------------------------------------------------------------------
200193
201194 /**
@@ -211,16 +204,16 @@ public function testRevokeUserGrantsJobPassesClientIdToTokenService(): void
211204 ->once ()
212205 ->with ($ this ->test_user ->getId (), $ client_id );
213206
214- $ job = new RevokeUserGrants ($ this ->test_user , $ client_id, ' unit test ' );
207+ $ job = new RevokeUserGrantsOnExplicitLogout ($ this ->test_user , $ client_id );
215208 $ job ->handle ($ mock_service );
216209 }
217210
218211 // -------------------------------------------------------------------------
219- // Test 7: RevokeUserGrants::handle() calls revokeUsersToken with null client_id
212+ // Test 7: RevokeUserGrantsOnPasswordChange passes null client_id to token service
220213 // -------------------------------------------------------------------------
221214
222215 /**
223- * When constructed without a client_id the job must call
216+ * RevokeUserGrantsOnPasswordChange must call
224217 * ITokenService::revokeUsersToken($user_id, null), revoking across all clients.
225218 */
226219 public function testRevokeUserGrantsJobPassesNullClientIdToTokenService (): void
@@ -230,7 +223,7 @@ public function testRevokeUserGrantsJobPassesNullClientIdToTokenService(): void
230223 ->once ()
231224 ->with ($ this ->test_user ->getId (), null );
232225
233- $ job = new RevokeUserGrants ($ this ->test_user , null , ' unit test ' );
226+ $ job = new RevokeUserGrantsOnPasswordChange ($ this ->test_user );
234227 $ job ->handle ($ mock_service );
235228 }
236229
@@ -239,8 +232,8 @@ public function testRevokeUserGrantsJobPassesNullClientIdToTokenService(): void
239232 // -------------------------------------------------------------------------
240233
241234 /**
242- * When opentelemetry.enabled is true, RevokeUserGrants::handle() must
243- * dispatch an EmitAuditLogJob with the correct log message and audit fields.
235+ * When opentelemetry.enabled is true, the job must dispatch an EmitAuditLogJob
236+ * with the correct log message and audit fields.
244237 */
245238 public function testOtelAuditJobDispatchedWhenOpentelemetryEnabled (): void
246239 {
@@ -249,7 +242,7 @@ public function testOtelAuditJobDispatchedWhenOpentelemetryEnabled(): void
249242 $ mock_service = Mockery::mock (ITokenService::class);
250243 $ mock_service ->shouldReceive ('revokeUsersToken ' )->once ();
251244
252- $ job = new RevokeUserGrants ($ this ->test_user , null , ' password change ' );
245+ $ job = new RevokeUserGrantsOnPasswordChange ($ this ->test_user );
253246 $ job ->handle ($ mock_service );
254247
255248 Queue::assertPushed (EmitAuditLogJob::class, function (EmitAuditLogJob $ emitted ) {
@@ -267,8 +260,7 @@ public function testOtelAuditJobDispatchedWhenOpentelemetryEnabled(): void
267260 // -------------------------------------------------------------------------
268261
269262 /**
270- * When opentelemetry.enabled is false, RevokeUserGrants::handle() must not
271- * dispatch any EmitAuditLogJob.
263+ * When opentelemetry.enabled is false, the job must not dispatch any EmitAuditLogJob.
272264 */
273265 public function testOtelAuditJobNotDispatchedWhenOpentelemetryDisabled (): void
274266 {
@@ -277,7 +269,7 @@ public function testOtelAuditJobNotDispatchedWhenOpentelemetryDisabled(): void
277269 $ mock_service = Mockery::mock (ITokenService::class);
278270 $ mock_service ->shouldReceive ('revokeUsersToken ' )->once ();
279271
280- $ job = new RevokeUserGrants ($ this ->test_user , null , ' password change ' );
272+ $ job = new RevokeUserGrantsOnPasswordChange ($ this ->test_user );
281273 $ job ->handle ($ mock_service );
282274
283275 Queue::assertNotPushed (EmitAuditLogJob::class);
0 commit comments