@@ -179,6 +179,8 @@ async fn test_device_auth_flow(cptestctx: &ControlPlaneTestContext) {
179179 assert_eq ! ( get_tokens_priv( testctx) . await . len( ) , 0 ) ;
180180 let tokens_unpriv_after = get_tokens_unpriv ( testctx) . await ;
181181 assert_eq ! ( tokens_unpriv_after. len( ) , 1 ) ;
182+ assert_eq ! ( tokens_unpriv_after[ 0 ] . id, token. token_id) ;
183+ assert_eq ! ( token. time_expires, None ) ;
182184 assert_eq ! ( tokens_unpriv_after[ 0 ] . time_expires, None ) ;
183185
184186 // now make a request with the token. it 403s because unpriv user has no
@@ -241,7 +243,9 @@ async fn test_device_auth_flow(cptestctx: &ControlPlaneTestContext) {
241243
242244/// Helper to make the test cute. Goes through the whole flow, returns the token
243245/// as a string
244- async fn get_device_token ( testctx : & ClientTestContext ) -> String {
246+ async fn get_device_token (
247+ testctx : & ClientTestContext ,
248+ ) -> DeviceAccessTokenGrant {
245249 let client_id = Uuid :: new_v4 ( ) ;
246250 let authn_params = DeviceAuthRequest { client_id, ttl_seconds : None } ;
247251
@@ -279,8 +283,8 @@ async fn get_device_token(testctx: &ClientTestContext) -> String {
279283 client_id,
280284 } ;
281285
282- // Get the token
283- let token : DeviceAccessTokenGrant = NexusRequest :: new (
286+ // Get the token and return it
287+ NexusRequest :: new (
284288 RequestBuilder :: new ( testctx, Method :: POST , "/device/token" )
285289 . allow_non_dropshot_errors ( )
286290 . body_urlencoded ( Some ( & token_params) )
@@ -291,9 +295,7 @@ async fn get_device_token(testctx: &ClientTestContext) -> String {
291295 . await
292296 . expect ( "failed to get token" )
293297 . parsed_body ( )
294- . expect ( "failed to deserialize token response" ) ;
295-
296- token. access_token
298+ . expect ( "failed to deserialize token response" )
297299}
298300
299301#[ nexus_test]
@@ -309,12 +311,14 @@ async fn test_device_token_expiration(cptestctx: &ControlPlaneTestContext) {
309311
310312 // get a token for the privileged user. default silo max token expiration
311313 // is null, so tokens don't expire
312- let initial_token = get_device_token ( testctx) . await ;
314+ let initial_token_grant = get_device_token ( testctx) . await ;
315+ let initial_token = initial_token_grant. access_token ;
313316
314317 // now there is a token in the list
315318 let tokens = get_tokens_priv ( testctx) . await ;
316319 assert_eq ! ( tokens. len( ) , 1 ) ;
317320 assert_eq ! ( tokens[ 0 ] . time_expires, None ) ;
321+ assert_eq ! ( tokens[ 0 ] . id, initial_token_grant. token_id) ;
318322
319323 // test token works on project list
320324 project_list ( & testctx, & initial_token, StatusCode :: OK )
@@ -377,7 +381,16 @@ async fn test_device_token_expiration(cptestctx: &ControlPlaneTestContext) {
377381 assert_eq ! ( settings. device_token_max_ttl_seconds, Some ( 3 ) ) ;
378382
379383 // create token again (this one will have the 3-second expiration)
380- let expiring_token = get_device_token ( testctx) . await ;
384+ let expiring_token_grant = get_device_token ( testctx) . await ;
385+
386+ // check that expiration time is there and in the right range
387+ let exp = expiring_token_grant
388+ . time_expires
389+ . expect ( "Expiring token should have an expiration time" ) ;
390+ let exp = ( exp - Utc :: now ( ) ) . num_seconds ( ) ;
391+ assert ! ( exp > 0 && exp < 5 , "should be around 3 seconds from now" ) ;
392+
393+ let expiring_token = expiring_token_grant. access_token ;
381394
382395 // use a block so we don't touch expiring_token
383396 {
0 commit comments