mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Replace time with std::time in components/net (#31079)
* Replace time with std::time in components/net Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Fix cookie::test_sort_order test Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
d86e713a9c
commit
580062228b
13 changed files with 161 additions and 123 deletions
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use net::hsts::{HstsEntry, HstsList};
|
||||
use net_traits::IncludeSubdomains;
|
||||
|
@ -12,7 +13,7 @@ fn test_hsts_entry_is_not_expired_when_it_has_no_timestamp() {
|
|||
let entry = HstsEntry {
|
||||
host: "mozilla.org".to_owned(),
|
||||
include_subdomains: false,
|
||||
max_age: Some(20),
|
||||
max_age: Some(Duration::from_secs(20)),
|
||||
timestamp: None,
|
||||
};
|
||||
|
||||
|
@ -25,7 +26,12 @@ fn test_hsts_entry_is_not_expired_when_it_has_no_max_age() {
|
|||
host: "mozilla.org".to_owned(),
|
||||
include_subdomains: false,
|
||||
max_age: None,
|
||||
timestamp: Some(time::get_time().sec as u64),
|
||||
timestamp: Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
),
|
||||
};
|
||||
|
||||
assert!(!entry.is_expired());
|
||||
|
@ -36,8 +42,14 @@ fn test_hsts_entry_is_expired_when_it_has_reached_its_max_age() {
|
|||
let entry = HstsEntry {
|
||||
host: "mozilla.org".to_owned(),
|
||||
include_subdomains: false,
|
||||
max_age: Some(10),
|
||||
timestamp: Some(time::get_time().sec as u64 - 20u64),
|
||||
max_age: Some(Duration::from_secs(10)),
|
||||
timestamp: Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs() -
|
||||
20u64,
|
||||
),
|
||||
};
|
||||
|
||||
assert!(entry.is_expired());
|
||||
|
@ -106,7 +118,7 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() {
|
|||
vec![HstsEntry::new(
|
||||
"mozilla.org".to_owned(),
|
||||
IncludeSubdomains::NotIncluded,
|
||||
Some(500000u64),
|
||||
Some(Duration::from_secs(500000u64)),
|
||||
)
|
||||
.unwrap()],
|
||||
);
|
||||
|
@ -118,7 +130,7 @@ fn test_push_entry_with_0_max_age_evicts_entry_from_list() {
|
|||
HstsEntry::new(
|
||||
"mozilla.org".to_owned(),
|
||||
IncludeSubdomains::NotIncluded,
|
||||
Some(0),
|
||||
Some(Duration::ZERO),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
@ -367,8 +379,14 @@ fn test_hsts_list_with_expired_entry_is_not_is_host_secure() {
|
|||
vec![HstsEntry {
|
||||
host: "mozilla.org".to_owned(),
|
||||
include_subdomains: false,
|
||||
max_age: Some(20),
|
||||
timestamp: Some(time::get_time().sec as u64 - 100u64),
|
||||
max_age: Some(Duration::from_secs(20)),
|
||||
timestamp: Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs() -
|
||||
100u64,
|
||||
),
|
||||
}],
|
||||
);
|
||||
let hsts_list = HstsList {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue