aboutsummaryrefslogtreecommitdiff
path: root/src/parser/deserializer.rs
blob: 75d3c6e43a2a73fdc742e0316a06f212e47f5b2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::io::Read;

use crate::data_structures;

fn deserialize_dmarc_report<R: Read>(reader: R) -> 
Result<data_structures::Feedback, serde_xml_rs::Error> {
   serde_xml_rs::from_reader(reader) 
}

#[cfg(test)]
mod test {
    use super::*;

    use std::fs::File;
    use std::io::BufReader;

    #[test]
    fn test_deserialize_dmarc_report() {
        let dmarc_report_file = File::open("fixtures/dmarc_report_fixture.xml").unwrap();

        let reader = BufReader::new(dmarc_report_file);

        let should_be = data_structures::Feedback {
            version: String::from("1.0"),
            report_metadata: data_structures::ReportMetadata {
                org_name: String::from("Enterprise Outlook"),
                email: String::from("dmarcreport@microsoft.com"),
                report_id: String::from("3374fb5148ba40c1a5cf8e3d36f34a34"),
                date_range: data_structures::DateRange {
                    begin: String::from("1707436800"),
                    end: String::from("1707523200"),
                },
            },
            policy_published: data_structures::PolicyPublished {
                domain: String::from("boitalett.re"),
                adkim: String::from("s"),
                aspf: String::from("s"),
                p: String::from("reject"),
                sp: String::from("reject"),
                pct: String::from("100"),
                fo: String::from("0"),
            },
            record: data_structures::Record {
                row: data_structures::Row {
                    source_ip: String::from("195.154.102.43"),
                    count: String::from("1"),
                    policy_evaluated: data_structures::PolicyEvaluated {
                        disposition: String::from("none"),
                        dkim: String::from("pass"),
                        spf: String::from("pass"),
                    },
                },
                identifiers: data_structures::Identifiers {
                    envelope_to: String::from("babilou.com"),
                    envelope_from: String::from("boitalett.re"),
                    header_from: String::from("boitalett.re"),
                },
                auth_results: data_structures::AuthResults {
                    dkim: data_structures::DKIM {
                        domain: String::from("boitalett.re"),
                        selector: String::from("2023101501"),
                        result: String::from("pass"),
                    },
                    spf: data_structures::SPF {
                        domain: String::from("boitalett.re"),
                        scope: String::from("mfrom"),
                        result: String::from("pass"),
                    },
                },
            },
        };

        match deserialize_dmarc_report(reader) {
            Ok(report) => {
                assert_eq!(
                    report.report_metadata.report_id,
                    should_be.report_metadata.report_id
                );
                println!("{:?}", report);
            },
            Err(err) => {
                panic!("{:?}", err);
            }
        }
    }
}