Skip to content

Commit eef2e6d

Browse files
committed
Improve tests for .well-known/security.txt
- make CI fail already one month before expiry - make sure the expiry date is no further than one year into the future
1 parent 4a5ab5a commit eef2e6d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

static/text/well_known_security.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Contact: https://www.rust-lang.org/policies/security
2-
Expires: 2024-05-15T00:00:00.000Z
2+
Expires: 2025-05-15T00:00:00.000Z

tests/well_known_security.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
22

3+
static TEXT: &str = include_str!("../static/text/well_known_security.txt");
4+
35
#[test]
4-
fn well_known_security_is_not_expired() {
5-
let text = include_str!("../static/text/well_known_security.txt");
6-
let expires = text.split("Expires:").nth(1).unwrap().trim();
6+
fn well_known_security_is_not_about_to_expire() {
7+
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
78
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
8-
let now = OffsetDateTime::now_utc();
9+
let one_month_from_now = OffsetDateTime::now_utc() + time::Duration::days(30);
910
assert!(
10-
now < expires,
11+
one_month_from_now < expires,
1112
"
1213
┌────────────────────────────────────────────────────────────────┐
1314
│ │
14-
│ I looks like the expiration date of the security policy has
15-
passed. Before blindly updating it, please make sure the
15+
│ I looks like the expiration date of the security policy needs
16+
updating. Before blindly updating it, please make sure the │
1617
│ pointed-to URL still refers to the source of truth of the │
1718
│ security policy of the Rust project. If all is well, you can │
1819
│ update the expiration date in the relevant file: │
@@ -23,3 +24,14 @@ fn well_known_security_is_not_expired() {
2324
"
2425
);
2526
}
27+
28+
#[test]
29+
fn well_known_security_expires_within_a_year() {
30+
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
31+
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
32+
let one_year_from_now = OffsetDateTime::now_utc() + time::Duration::days(370);
33+
assert!(
34+
expires < one_year_from_now,
35+
"The security policy should be checked once a year, please reduce the expiration date."
36+
);
37+
}

0 commit comments

Comments
 (0)