22// License, v. 2.0. If a copy of the MPL was not distributed with this
33// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
5+ use std:: num:: NonZeroU32 ;
6+
57use dropshot:: test_util:: ClientTestContext ;
68use nexus_auth:: authn:: USER_TEST_UNPRIVILEGED ;
79use nexus_db_queries:: db:: fixed_data:: silo:: DEFAULT_SILO ;
810use nexus_db_queries:: db:: identity:: { Asset , Resource } ;
911use nexus_test_utils:: http_testing:: TestResponse ;
10- use nexus_test_utils:: resource_helpers:: { object_get, object_put} ;
12+ use nexus_test_utils:: resource_helpers:: {
13+ object_get, object_put, object_put_error,
14+ } ;
1115use nexus_test_utils:: {
1216 http_testing:: { AuthnMode , NexusRequest , RequestBuilder } ,
1317 resource_helpers:: grant_iam,
@@ -245,9 +249,8 @@ async fn get_device_token(testctx: &ClientTestContext) -> String {
245249 token. access_token
246250}
247251
248- /// similar to the above except happy path only, focused on expiration
249252#[ nexus_test]
250- async fn test_device_auth_expiration ( cptestctx : & ControlPlaneTestContext ) {
253+ async fn test_device_token_expiration ( cptestctx : & ControlPlaneTestContext ) {
251254 let testctx = & cptestctx. external_client ;
252255
253256 let settings: views:: SiloSettings =
@@ -263,11 +266,26 @@ async fn test_device_auth_expiration(cptestctx: &ControlPlaneTestContext) {
263266 . await
264267 . expect ( "initial token should work" ) ;
265268
269+ // passing negative or zero gives a 400
270+ for value in [ -3 , 0 ] {
271+ let error = object_put_error (
272+ testctx,
273+ "/v1/settings" ,
274+ & serde_json:: json!( { "device_token_max_ttl_seconds" : value } ) ,
275+ StatusCode :: BAD_REQUEST ,
276+ )
277+ . await ;
278+ let msg = "unable to parse JSON body: device_token_max_ttl_seconds: invalid value" ;
279+ assert ! ( error. message. starts_with( & msg) ) ;
280+ }
281+
266282 // set token expiration on silo to 3 seconds
267283 let settings: views:: SiloSettings = object_put (
268284 testctx,
269285 "/v1/settings" ,
270- & params:: SiloSettingsUpdate { device_token_max_ttl_seconds : Some ( 3 ) } ,
286+ & params:: SiloSettingsUpdate {
287+ device_token_max_ttl_seconds : NonZeroU32 :: new ( 3 ) ,
288+ } ,
271289 )
272290 . await ;
273291
0 commit comments