1
// @@ begin test lint list maintained by maint/add_warning @@
2
#![allow(clippy::bool_assert_comparison)]
3
#![allow(clippy::clone_on_copy)]
4
#![allow(clippy::dbg_macro)]
5
#![allow(clippy::mixed_attributes_style)]
6
#![allow(clippy::print_stderr)]
7
#![allow(clippy::print_stdout)]
8
#![allow(clippy::single_char_pattern)]
9
#![allow(clippy::unwrap_used)]
10
#![allow(clippy::unchecked_time_subtraction)]
11
#![allow(clippy::useless_vec)]
12
#![allow(clippy::needless_pass_by_value)]
13
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
14
#![allow(clippy::needless_borrows_for_generic_args)] // TODO add to maint/add_warning
15

            
16
use super::*;
17
use crate::doc::authcert;
18
use authcert::AuthCert as DirAuthKeyCert;
19
use authcert::AuthCertUnverified as DirAuthKeyCertUnverified;
20

            
21
use std::fs;
22

            
23
use humantime::parse_rfc3339;
24

            
25
#[test]
26
2
fn parse_consensus_ns() -> anyhow::Result<()> {
27
2
    let file = "testdata2/cached-consensus";
28
2
    let text = fs::read_to_string(&file)?;
29
2
    let now = parse_rfc3339("2000-01-01T00:02:25Z")?;
30

            
31
2
    let input = ParseInput::new(&text, file);
32
2
    let doc: netstatus::NetworkStatusUnverifiedNs = parse_netdoc(&input)?;
33

            
34
2
    let file = "testdata2/cached-certs";
35
2
    let text = fs::read_to_string(&file)?;
36
2
    let input = ParseInput::new(&text, file);
37
2
    let certs: Vec<DirAuthKeyCertUnverified> = parse_netdoc_multiple(&input)?;
38
2
    let certs = certs
39
2
        .into_iter()
40
9
        .map(|cert| cert.verify_selfcert(now))
41
2
        .collect::<Result<Vec<DirAuthKeyCert>, _>>()?;
42

            
43
2
    let doc = doc.verify(
44
2
        now,
45
9
        &certs.iter().map(|cert| *cert.fingerprint).collect_vec(),
46
2
        &certs.iter().collect_vec(),
47
    )?;
48

            
49
2
    println!("{doc:?}");
50

            
51
2
    Ok(())
52
2
}
53

            
54
#[test]
55
2
fn parse_consensus_md() -> anyhow::Result<()> {
56
2
    let file = "testdata2/cached-microdesc-consensus";
57
2
    let text = fs::read_to_string(&file)?;
58

            
59
2
    let input = ParseInput::new(&text, file);
60
2
    let doc: netstatus::md::NetworkStatusUnverified = parse_netdoc(&input)?;
61

            
62
2
    println!("{doc:?}");
63

            
64
2
    Ok(())
65
2
}
66

            
67
#[test]
68
2
fn parse_authcert() -> anyhow::Result<()> {
69
2
    let file = "testdata2/cached-certs--1";
70
2
    let now = parse_rfc3339("2000-06-01T00:00:05Z")?;
71
2
    let text = fs::read_to_string(file)?;
72
2
    let input = ParseInput::new(&text, file);
73
2
    let doc: DirAuthKeyCertUnverified = parse_netdoc(&input)?;
74
2
    let doc = doc.verify_selfcert(now)?;
75
2
    println!("{doc:?}");
76
2
    assert_eq!(
77
2
        doc.fingerprint.0.to_string(),
78
        "$0b8997614ec647c1c6b6a044e2b5408f0b823fb0",
79
    );
80
2
    Ok(())
81
2
}