-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathwell_known_security.rs
37 lines (34 loc) · 2.01 KB
/
well_known_security.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
static TEXT: &str = include_str!("../static/text/well_known_security.txt");
#[test]
fn well_known_security_is_not_about_to_expire() {
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
let one_month_from_now = OffsetDateTime::now_utc() + time::Duration::days(30);
assert!(
one_month_from_now < expires,
"
┌────────────────────────────────────────────────────────────────┐
│ │
│ I looks like the expiration date of the security policy needs │
│ updating. Before blindly updating it, please make sure the │
│ pointed-to URL still refers to the source of truth of the │
│ security policy of the Rust project. If all is well, you can │
│ update the expiration date in the relevant file: │
│ │
│ static/text/well_known_security.txt │
│ │
└────────────────────────────────────────────────────────────────┘
"
);
}
#[test]
fn well_known_security_expires_within_a_year() {
let expires = TEXT.split("Expires:").nth(1).unwrap().trim();
let expires = OffsetDateTime::parse(expires, &Rfc3339).unwrap();
let one_year_from_now = OffsetDateTime::now_utc() + time::Duration::days(370);
assert!(
expires < one_year_from_now,
"The security policy should be checked once a year, please reduce the expiration date."
);
}