Tackling issue #663 (Use humantime in tests)

This commit is contained in:
coral 2022-12-12 17:41:22 +00:00 committed by Ian Jackson
parent 81e23be67e
commit 25f113b8b3
9 changed files with 23 additions and 13 deletions

3
Cargo.lock generated
View File

@ -3595,6 +3595,7 @@ dependencies = [
"derive_builder_fork_arti",
"digest 0.10.6",
"hex-literal",
"humantime 2.1.0",
"rand 0.8.5",
"signature",
"thiserror",
@ -3987,6 +3988,7 @@ dependencies = [
"educe",
"hex",
"hex-literal",
"humantime 2.1.0",
"itertools",
"once_cell",
"phf",
@ -4043,6 +4045,7 @@ dependencies = [
"hex-literal",
"hkdf",
"hmac",
"humantime 2.1.0",
"itertools",
"pin-project",
"rand 0.8.5",

View File

@ -29,6 +29,7 @@ tor-llcrypto = { path = "../tor-llcrypto", version = "0.4.0" }
[dev-dependencies]
base64 = "0.13.0"
hex-literal = "0.3"
humantime = "2"
rand = "0.8"
[package.metadata.docs.rs]
all-features = true

View File

@ -2,12 +2,11 @@ use tor_cert::rsa::RsaCrosscert;
use tor_cert::{Ed25519Cert, KeyType};
use tor_checkable::{ExternallySigned, SelfSigned, Timebound};
use std::time::{Duration, SystemTime};
use hex_literal::hex;
#[test]
fn test_valid_ed() {
use humantime::parse_rfc3339;
use tor_llcrypto::pk::ed25519::Ed25519Identity;
// These are taken from a CERTS cell in a chutney network.
let signing_key = hex!("F82294B866A31F01FC5D0DA8572850A9B929545C3266558D7D2316E3B74172B0");
@ -15,7 +14,7 @@ fn test_valid_ed() {
let signing_key = Ed25519Identity::from_bytes(&signing_key[..]).unwrap();
let identity_key = Ed25519Identity::from_bytes(&identity_key[..]).unwrap();
let notional_time = SystemTime::UNIX_EPOCH + Duration::new(1601000000, 0);
let notional_time = parse_rfc3339("2020-09-25T02:13:20Z").unwrap();
// signing cert signed with signing key, type 4, one extension.
let c = hex!(
@ -43,7 +42,7 @@ fn test_valid_ed() {
assert_eq!(cert.cert_type(), 4.into());
assert_eq!(
cert.expiry(),
SystemTime::UNIX_EPOCH + Duration::new(0x6cc2a * 3600, 0)
parse_rfc3339("2020-10-26T18:00:00Z").unwrap()
);
// link cert signed with signing key, type 5, no extensions.
@ -72,13 +71,14 @@ fn test_valid_ed() {
assert_eq!(cert.cert_type(), 5.into());
assert_eq!(
cert.expiry(),
SystemTime::UNIX_EPOCH + Duration::new(0x6c98a * 3600, 0)
parse_rfc3339("2020-09-28T18:00:00Z").unwrap()
);
}
#[test]
fn test_valid_rsa_cc() {
let notional_time = SystemTime::UNIX_EPOCH + Duration::new(1601000000, 0);
let notional_time = humantime::parse_rfc3339("2020-09-25T02:13:20Z").unwrap();
let pk = hex!("30818902818100d38b1e6ceb946e0db0751f4cbace3dcb9688b6c25304227b4710c35afb73627e50500f5913e158b621802612d1c75827003703338375237552eb3cd3c12f6ab3604e60c1a2d26bb1fbad206ff023969a90909d6a65a5458a5312c26ebd3a3dad30302d4515cdcd264146ac18e6fc60a04bd3ec327f04294d96ba5aa25b464c3f0203010001");
let pk = tor_llcrypto::pk::rsa::PublicKey::from_der(&pk[..]).unwrap();

View File

@ -23,3 +23,5 @@ tor-llcrypto = { path = "../tor-llcrypto", version = "0.4.0" }
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dev-dependencies]
humantime = "2"

View File

@ -135,16 +135,18 @@ impl<T> crate::Timebound<T> for TimerangeBound<T> {
mod test {
use super::*;
use crate::{TimeValidityError, Timebound};
use humantime::parse_rfc3339;
use std::time::{Duration, SystemTime};
#[test]
fn test_bounds() {
#![allow(clippy::unwrap_used)]
let one_day = Duration::new(86400, 0);
let mixminion_v0_0_1 = SystemTime::UNIX_EPOCH + 12059 * one_day; //2003-01-07
let tor_v0_0_2pre13 = SystemTime::UNIX_EPOCH + 12344 * one_day; //2003-10-19
let cussed_nougat = SystemTime::UNIX_EPOCH + 14093 * one_day; //2008-08-02
let tor_v0_4_4_5 = SystemTime::UNIX_EPOCH + 18520 * one_day; //2020-09-15
let today = SystemTime::UNIX_EPOCH + 18527 * one_day; //2020-09-22
let mixminion_v0_0_1 = parse_rfc3339("2003-01-07T00:00:00Z").unwrap();
let tor_v0_0_2pre13 = parse_rfc3339("2003-10-19T00:00:00Z").unwrap();
let cussed_nougat = parse_rfc3339("2008-08-02T00:00:00Z").unwrap();
let tor_v0_4_4_5 = parse_rfc3339("2020-09-15T00:00:00Z").unwrap();
let today = parse_rfc3339("2020-09-22T00:00:00Z").unwrap();
let tr = TimerangeBound::new((), ..tor_v0_4_4_5);
assert_eq!(tr.start, None);

View File

@ -72,6 +72,7 @@ weak-table = "0.3.0"
[dev-dependencies]
hex-literal = "0.3"
humantime = "2"
itertools = "0.10.1"
serde_json = "1.0.50"
[package.metadata.docs.rs]

View File

@ -934,7 +934,7 @@ mod test {
);
assert_eq!(
rd.published(),
time::SystemTime::UNIX_EPOCH + time::Duration::new(1668455932, 0)
humantime::parse_rfc3339("2022-11-14T19:58:52Z").unwrap()
);
assert_eq!(
rd.or_ports().collect::<Vec<_>>(),

View File

@ -62,6 +62,7 @@ zeroize = "1"
[dev-dependencies]
hex = "0.4"
hex-literal = "0.3"
humantime = "2"
itertools = "0.10.1"
regex = { version = "1", default-features = false, features = ["std"] }
statrs = "0.16.0"

View File

@ -666,7 +666,7 @@ pub(super) mod test {
#[test]
fn connect_ok() -> Result<()> {
tor_rtcompat::test_with_one_runtime!(|rt| async move {
let now = SystemTime::UNIX_EPOCH + Duration::from_secs(1217696400);
let now = humantime::parse_rfc3339("2008-08-02T17:00:00Z").unwrap();
let mut buf = Vec::new();
// versions cell
buf.extend_from_slice(VERSIONS);