more Spamhaus checking and EHLO id lookup
[ghsmtp.git] / SPF-test.cpp
bloba96fa9d4bbb8d9fccc93adcfb356f9c7323e06e0
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::SOFTFAIL);
43 CHECK(0 == strcmp(res2.header_comment(),
44 "Example.com: transitioning domain of "
45 "digilicious.com does not designate "
46 "10.1.1.1 as permitted sender"));
47 auto fail_new =
48 "Received-SPF: softfail (Example.com: transitioning domain of "
49 "digilicious.com does not designate 10.1.1.1 as permitted sender) "
50 "client-ip=10.1.1.1; envelope-from=postmaster@digilicious.com; "
51 "helo=digilicious.com;";
52 auto fail_old = "Received-SPF: fail (Example.com: "
53 "domain of digilicious.com does not "
54 "designate 10.1.1.1 as permitted "
55 "sender) client-ip=10.1.1.1; "
56 "envelope-from=postmaster@digilicious."
57 "com; helo=digilicious.com;";
59 LOG(INFO) << res2.received_spf();
61 CHECK((0 == strcmp(res2.received_spf(), fail_new)) ||
62 (0 == strcmp(res2.received_spf(), fail_old)));
64 CHECK(0 == strcmp(res2.smtp_comment(), "Please see "
65 "http://www.openspf.org/"
66 "Why?id=postmaster%40digilicious.com&"
67 "ip=10.1.1.1&receiver=Example.com : "
68 "Reason: mechanism"));
70 SPF::Request req3{srv};
71 req3.set_ipv6_str("2600:1700:c281:3070:6a1c:a2ff:fe12:4ae6");
72 req3.set_helo_dom("digilicious.com");
73 // req3.set_env_from("bogus@example.com");
74 SPF::Response const res3{req3};
75 // CHECK_EQ(res3.result(), SPF::Result::PASS);
77 std::cout << "result == " << res3.result() << '\n';
78 std::cout << "smtp_comment == "
79 << (res3.smtp_comment() ? res3.smtp_comment() : "(null)") << '\n';
80 std::cout << "header_comment == "
81 << (res3.header_comment() ? res3.header_comment() : "(null)")
82 << '\n';
83 std::cout << "received_spf == "
84 << (res3.received_spf() ? res3.received_spf() : "(null)") << '\n';