@@ -179,11 +179,6 @@ async fn test_device_auth_flow(cptestctx: &ControlPlaneTestContext) {
179179 assert_eq ! ( tokens_unpriv_after. len( ) , 1 ) ;
180180 assert_eq ! ( tokens_unpriv_after[ 0 ] . time_expires, None ) ;
181181
182- // now make a request with the token. it 403s because unpriv user has no roles
183- project_list ( & testctx, & token. access_token , StatusCode :: FORBIDDEN )
184- . await
185- . expect ( "projects list should 403 with no roles" ) ;
186-
187182 // make sure it also fails with a nonsense token
188183 project_list ( & testctx, "oxide-token-xyz" , StatusCode :: UNAUTHORIZED )
189184 . await
@@ -203,6 +198,45 @@ async fn test_device_auth_flow(cptestctx: &ControlPlaneTestContext) {
203198 project_list ( & testctx, & token. access_token , StatusCode :: OK )
204199 . await
205200 . expect ( "failed to get projects with token" ) ;
201+
202+ let token_id = tokens_unpriv_after[ 0 ] . id ;
203+
204+ // Test that privileged user cannot delete unpriv's token through this
205+ // endpoint, though it will probably be able to do it via a different one
206+ let token_url = format ! ( "/v1/me/tokens/{}" , token_id) ;
207+ NexusRequest :: new (
208+ RequestBuilder :: new ( testctx, Method :: DELETE , & token_url)
209+ . expect_status ( Some ( StatusCode :: NOT_FOUND ) ) ,
210+ )
211+ . authn_as ( AuthnMode :: PrivilegedUser )
212+ . execute ( )
213+ . await
214+ . expect ( "privileged user should get a 404 when trying to delete another user's token" ) ;
215+
216+ // Test deleting the token as the owner
217+ NexusRequest :: object_delete ( testctx, & token_url)
218+ . authn_as ( AuthnMode :: UnprivilegedUser )
219+ . execute ( )
220+ . await
221+ . expect ( "failed to delete token" ) ;
222+
223+ // Verify token is gone from the list
224+ assert_eq ! ( get_tokens_unpriv( testctx) . await . len( ) , 0 ) ;
225+
226+ // Token should no longer work for API calls
227+ project_list ( & testctx, & token. access_token , StatusCode :: UNAUTHORIZED )
228+ . await
229+ . expect ( "deleted token should be unauthorized" ) ;
230+
231+ // Trying to delete the same token again should 404
232+ NexusRequest :: new (
233+ RequestBuilder :: new ( testctx, Method :: DELETE , & token_url)
234+ . expect_status ( Some ( StatusCode :: NOT_FOUND ) ) ,
235+ )
236+ . authn_as ( AuthnMode :: UnprivilegedUser )
237+ . execute ( )
238+ . await
239+ . expect ( "double delete should 404" ) ;
206240}
207241
208242/// Helper to make the test cute. Goes through the whole flow, returns the token
0 commit comments