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
#![allow(clippy::string_slice)] // See arti#2571
14
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
15
#![allow(clippy::needless_borrows_for_generic_args)] // TODO add to maint/add_warning
16

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

            
22
use std::fs;
23

            
24
use humantime::parse_rfc3339;
25

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

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

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

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

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

            
52
2
    Ok(())
53
2
}
54

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

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

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

            
65
2
    Ok(())
66
2
}
67

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