accept more TLS versions, ignore zero return
[ghsmtp.git] / Session-test.cpp
blob5510aac903dcb11910d223c6701df7f834d7fba1
1 #include "Session.hpp"
3 #include "osutil.hpp"
5 #include <iostream>
7 #include <fcntl.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
11 struct Session_test {
12 static void test()
14 std::cout << "sizeof(Session) == " << sizeof(Session) << '\n';
15 std::cout << "sizeof(sock_) == " << sizeof(Session::sock_) << '\n';
16 std::cout << "sizeof(client_) == " << sizeof(Session::client_)
17 << '\n';
18 std::cout << "sizeof(reverse_path_) == " << sizeof(Session::reverse_path_)
19 << '\n';
20 std::cout << "sizeof(forward_path_) == " << sizeof(Session::forward_path_)
21 << '\n';
22 std::cout << "sizeof(binarymime_) == " << sizeof(Session::binarymime_)
23 << '\n';
25 setenv("GHSMTP_SERVER_ID", "digilicious.com", 1);
27 int fd_null = open("/dev/null", O_WRONLY);
28 PCHECK(fd_null >= 0) << " can't open /dev/null";
30 auto const config_path = osutil::get_config_dir();
31 auto read_hook = []() { std::cout << "Session-test read_hook\n"; };
32 Session sess(config_path, read_hook, STDIN_FILENO, fd_null);
34 auto sender{Domain{"example.er"}}; // Not a public suffix
35 auto error_msg{std::string{}};
36 CHECK(sess.verify_sender_domain_(sender, error_msg));
38 // bogus
39 CHECK(!sess.verify_sender_domain_(
40 Domain("invalid-domain-has-only-one-label"), error_msg));
42 // allow listed
43 CHECK(sess.verify_sender_domain_(Domain("lots.of.labels.digilicious.com"),
44 error_msg));
45 CHECK(sess.verify_sender_domain_(Domain("allowlisted.digilicious.com"),
46 error_msg));
47 CHECK(sess.verify_sender_domain_(
48 Domain("reg-domain-is-allowlisted.digilicious.com"), error_msg));
50 // bounce address
51 CHECK(sess.verify_sender_domain_(Domain(""), error_msg));
53 CHECK(!sess.verify_sender_domain_(Domain("com"), error_msg));
55 // IP address
56 // auto error_msg{std::string{}};
57 // CHECK(!sess.verify_ip_address_("blocklisted.digilicious.com"s));
61 int main(int argc, char* argv[]) { Session_test::test(); }