Skip to content

Commit af7979e

Browse files
wpfleger96Alia
andauthored
test(auth): read the clock once in NIP-FI until test (#8457)
🤖 The exact NIP-FI assertion-lifetime boundary test could fail when its JWT helper read the clock, then ES256 signing crossed a whole-second boundary. The token's `until` claim could land one second beyond the verifier's `now + skew + maximum_age` ceiling even though both were intended to use the same test instant. This changes the test helper to accept a captured instant and uses that instant for both the JWT time claims and `verify_at`. The boundary remains strict: `now + 3630s` is accepted and `now + 3631s` is rejected. No production code changes. Signed-off-by: Will Pfleger <[email protected]> Signed-off-by: Alia <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@buzz.block.builderlab.xyz> Co-authored-by: Alia <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@buzz.block.builderlab.xyz>
1 parent dc4cdc4 commit af7979e

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎crates/buzz-auth/src/nip_fi/command.rs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,17 @@ mod tests {
948948
until_offset_secs: i64,
949949
overrides: serde_json::Value,
950950
) -> String {
951-
let now = now_ts();
951+
mint_cmd_jwt_at(target, Utc::now(), until_offset_secs, overrides)
952+
}
953+
954+
/// Mint a command JWT using the supplied instant for all time claims.
955+
fn mint_cmd_jwt_at(
956+
target: &nostr::PublicKey,
957+
now: DateTime<Utc>,
958+
until_offset_secs: i64,
959+
overrides: serde_json::Value,
960+
) -> String {
961+
let now = now.timestamp();
952962
let mut claims = serde_json::json!({
953963
"iss": ISS,
954964
"aud": AUD,
@@ -1225,14 +1235,14 @@ mod tests {
12251235
let target = target_key();
12261236
let now = Utc::now();
12271237
for until_offset in [3600, 30 + 3600, 1] {
1228-
let token = mint_cmd_jwt(&target, until_offset, serde_json::json!({}));
1238+
let token = mint_cmd_jwt_at(&target, now, until_offset, serde_json::json!({}));
12291239
assert_eq!(
12301240
cv.verify_at(&token, METHOD, PATH, &target, now).map(|_| ()),
12311241
Ok(()),
12321242
"until = now + {until_offset}s must fit the ceiling"
12331243
);
12341244
}
1235-
let token = mint_cmd_jwt(&target, 30 + 3600 + 1, serde_json::json!({}));
1245+
let token = mint_cmd_jwt_at(&target, now, 30 + 3600 + 1, serde_json::json!({}));
12361246
assert_eq!(
12371247
cv.verify_at(&token, METHOD, PATH, &target, now).map(|_| ()),
12381248
Err(CommandError::UntilExceedsCeiling),

0 commit comments

Comments
 (0)