two functions now
[ghsmtp.git] / SPF-test.cpp
blobaccdb58324d2a686e45b890ec63af92adf464521
1 #include "SPF.hpp"
3 #include <iostream>
5 int main(int argc, char const* argv[])
7 CHECK_EQ(sizeof(SPF::Server), sizeof(void*));
8 CHECK_EQ(sizeof(SPF::Request), sizeof(void*));
10 SPF::Server const srv{"Example.com"};
12 SPF::Request req{srv};
13 req.set_ipv4_str("108.83.36.113");
14 req.set_helo_dom("digilicious.com");
15 req.set_env_from("postmaster@digilicious.com");
16 SPF::Response const res{req};
17 CHECK_EQ(res.result(), SPF::Result::PASS);
18 CHECK(0 == strcmp(res.header_comment(), "Example.com: domain of "
19 "digilicious.com designates "
20 "108.83.36.113 as permitted sender"));
21 auto pass_new = "Received-SPF: pass (Example.com: "
22 "domain of digilicious.com designates "
23 "108.83.36.113 as permitted sender) "
24 "client-ip=108.83.36.113; "
25 "envelope-from=\"postmaster@digilicious."
26 "com\"; helo=digilicious.com;";
27 auto pass_old = "Received-SPF: pass (Example.com: "
28 "domain of digilicious.com designates "
29 "108.83.36.113 as permitted sender) "
30 "client-ip=108.83.36.113; "
31 "envelope-from=postmaster@digilicious."
32 "com; helo=digilicious.com;";
34 CHECK((0 == strcmp(res.received_spf(), pass_new)) ||
35 (0 == strcmp(res.received_spf(), pass_old)));
37 SPF::Request req2{srv};
38 req2.set_ipv4_str("10.1.1.1");
39 req2.set_helo_dom("digilicious.com");
40 req2.set_env_from("postmaster@digilicious.com");
41 SPF::Response const res2{req2};
42 CHECK_EQ(res2.result(), SPF::Result::FAIL);
43 CHECK(0 == strcmp(res2.header_comment(), "Example.com: domain of "
44 "digilicious.com does not designate "
45 "10.1.1.1 as permitted sender"));
47 auto fail_new = "Received-SPF: fail (Example.com: "
48 "domain of digilicious.com does not "
49 "designate 10.1.1.1 as permitted "
50 "sender) client-ip=10.1.1.1; "
51 "envelope-from=\"postmaster@digilicious."
52 "com\"; helo=digilicious.com;";
53 auto fail_old = "Received-SPF: fail (Example.com: "
54 "domain of digilicious.com does not "
55 "designate 10.1.1.1 as permitted "
56 "sender) client-ip=10.1.1.1; "
57 "envelope-from=postmaster@digilicious."
58 "com; helo=digilicious.com;";
60 CHECK((0 == strcmp(res2.received_spf(), fail_new)) ||
61 (0 == strcmp(res2.received_spf(), fail_old)));
63 CHECK(0 == strcmp(res2.smtp_comment(), "Please see "
64 "http://www.openspf.org/"
65 "Why?id=postmaster%40digilicious.com&"
66 "ip=10.1.1.1&receiver=Example.com : "
67 "Reason: mechanism"));
69 SPF::Request req3{srv};
70 req3.set_ipv6_str("2600:1700:c281:3070:6a1c:a2ff:fe12:4ae6");
71 req3.set_helo_dom("digilicious.com");
72 // req3.set_env_from("bogus@example.com");
73 SPF::Response const res3{req3};
74 // CHECK_EQ(res3.result(), SPF::Result::PASS);
76 std::cout << "result == " << res3.result() << '\n';
77 std::cout << "smtp_comment == "
78 << (res3.smtp_comment() ? res3.smtp_comment() : "(null)") << '\n';
79 std::cout << "header_comment == "
80 << (res3.header_comment() ? res3.header_comment() : "(null)")
81 << '\n';
82 std::cout << "received_spf == "
83 << (res3.received_spf() ? res3.received_spf() : "(null)") << '\n';