1
1
use time:: { format_description:: well_known:: Rfc3339 , OffsetDateTime } ;
2
2
3
+ static TEXT : & str = include_str ! ( "../static/text/well_known_security.txt" ) ;
4
+
3
5
#[ 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 ( ) ;
7
8
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 ) ;
9
10
assert ! (
10
- now < expires,
11
+ one_month_from_now < expires,
11
12
"
12
13
┌────────────────────────────────────────────────────────────────┐
13
14
│ │
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 │
16
17
│ pointed-to URL still refers to the source of truth of the │
17
18
│ security policy of the Rust project. If all is well, you can │
18
19
│ update the expiration date in the relevant file: │
@@ -23,3 +24,14 @@ fn well_known_security_is_not_expired() {
23
24
"
24
25
) ;
25
26
}
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