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 authcert::DirAuthKeyCert;
18

            
19
use std::fs;
20

            
21
use humantime::parse_rfc3339;
22

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

            
29
2
    let input = ParseInput::new(&text, file);
30
2
    let doc: netstatus::NetworkStatusSignedNs = parse_netdoc(&input)?;
31

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

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

            
47
2
    println!("{doc:?}");
48

            
49
2
    Ok(())
50
2
}
51

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

            
57
2
    let input = ParseInput::new(&text, file);
58
2
    let doc: netstatus::md::NetworkStatusSigned = parse_netdoc(&input)?;
59

            
60
2
    println!("{doc:?}");
61

            
62
2
    Ok(())
63
2
}
64

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