Skip to content

Commit 042417c

Browse files
committed
minor: address emily's non-blocking comments on #9411
1 parent 6bb047d commit 042417c

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

nexus/auth/src/authn/external/session_cookie.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,7 @@ mod test {
396396
}]),
397397
};
398398
let result = authn_with_cookie(&context, Some("session=abc")).await;
399-
assert!(matches!(
400-
result,
401-
SchemeResult::Authenticated(Details {
402-
actor: _,
403-
device_token_expiration: _
404-
})
405-
));
399+
assert!(matches!(result, SchemeResult::Authenticated(Details { .. })));
406400

407401
// valid cookie should have updated time_last_used
408402
let sessions = context.sessions.lock().unwrap();

nexus/src/app/device_auth.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,32 +142,32 @@ impl super::Nexus {
142142
// token is being used)
143143

144144
// Validate the requested TTL against the silo's max TTL
145-
if let Some(max) = silo_max_ttl {
146-
if requested_ttl > max.0.into() {
147-
return Err(Error::invalid_request(&format!(
148-
"Requested TTL {} seconds exceeds maximum allowed \
149-
TTL for this silo of {} seconds",
150-
requested_ttl, max
151-
)));
152-
}
145+
if let Some(max) = silo_max_ttl
146+
&& requested_ttl > max.0.into()
147+
{
148+
return Err(Error::invalid_request(&format!(
149+
"Requested TTL {} seconds exceeds maximum allowed \
150+
TTL for this silo of {} seconds",
151+
requested_ttl, max
152+
)));
153153
};
154154

155155
let requested_exp =
156156
Utc::now() + Duration::seconds(requested_ttl.0.into());
157157

158158
// If currently authenticated via token, error if requested exceeds it
159-
if let Some(auth_exp) = opctx.authn.device_token_expiration() {
160-
if requested_exp > auth_exp {
161-
return Err(Error::invalid_request(
162-
"Requested token TTL would exceed the expiration time \
163-
of the token being used to authenticate the confirm \
164-
request. To get the full requested TTL, confirm \
165-
this token using a web console session. Alternatively, \
166-
omit requested TTL to get a token with the longest \
167-
allowed lifetime, determined by the lesser of the silo \
168-
max and the current token's expiration time.",
169-
));
170-
}
159+
if let Some(auth_exp) = opctx.authn.device_token_expiration()
160+
&& requested_exp > auth_exp
161+
{
162+
return Err(Error::invalid_request(
163+
"Requested token TTL would exceed the expiration time \
164+
of the token being used to authenticate the confirm \
165+
request. To get the full requested TTL, confirm \
166+
this token using a web console session. Alternatively, \
167+
omit requested TTL to get a token with the longest \
168+
allowed lifetime, determined by the lesser of the silo \
169+
max and the current token's expiration time.",
170+
));
171171
}
172172

173173
Some(requested_exp)

nexus/tests/integration_tests/device_auth.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ async fn test_device_token_cannot_extend_expiration(
704704
testctx,
705705
session_auth_response.device_code,
706706
client_id,
707-
AuthnMode::Session(session_token.clone()),
708707
)
709708
.await;
710709

@@ -746,7 +745,6 @@ async fn test_device_token_cannot_extend_expiration(
746745
testctx,
747746
session_auth_response2.device_code,
748747
client_id,
749-
AuthnMode::Session(session_token),
750748
)
751749
.await;
752750

@@ -788,13 +786,9 @@ async fn test_device_token_cannot_extend_expiration(
788786
.expect("failed to confirm initial token");
789787

790788
// Fetch the initial token
791-
let initial_token_grant = fetch_device_token(
792-
testctx,
793-
auth_response_1.device_code,
794-
client_id,
795-
AuthnMode::PrivilegedUser,
796-
)
797-
.await;
789+
let initial_token_grant =
790+
fetch_device_token(testctx, auth_response_1.device_code, client_id)
791+
.await;
798792

799793
let initial_token = initial_token_grant.access_token;
800794
let initial_expiration = initial_token_grant.time_expires.unwrap();
@@ -1130,7 +1124,6 @@ async fn fetch_device_token(
11301124
testctx: &ClientTestContext,
11311125
device_code: String,
11321126
client_id: Uuid,
1133-
authn_mode: AuthnMode,
11341127
) -> DeviceAccessTokenGrant {
11351128
NexusRequest::new(
11361129
RequestBuilder::new(testctx, Method::POST, "/device/token")
@@ -1143,7 +1136,6 @@ async fn fetch_device_token(
11431136
}))
11441137
.expect_status(Some(StatusCode::OK)),
11451138
)
1146-
.authn_as(authn_mode)
11471139
.execute_and_parse_unwrap::<DeviceAccessTokenGrant>()
11481140
.await
11491141
}

0 commit comments

Comments
 (0)