check for non-ASCII local-parts without SMTPUTF8
[ghsmtp.git] / SRS0-test.cpp
blob7f80ea29fcdffcc50de5ddbe938c749360fe1a0e
1 #include "SRS0.hpp"
3 #include "Mailbox.hpp"
4 #include "osutil.hpp"
6 #include <iostream>
8 #include <fmt/format.h>
9 #include <fmt/ostream.h>
11 #include <gflags/gflags.h>
13 #include <glog/logging.h>
15 using namespace std::string_literals;
17 int main(int argc, char* argv[])
19 google::ParseCommandLineFlags(&argc, &argv, true);
21 fs::path config_path = osutil::get_config_dir();
23 SRS0 srs(config_path);
25 SRS0::from_to test_cases[] = {
26 {"reply@example.com", "local-address"},
27 {"one.reply@example.com", "local"},
28 {"reply@example.com", "local"},
29 // These should force blob mode:
30 {"reply=something@example.com", "local"},
31 {"reply@example.com", "local=address"},
32 {"\"quoted string\"@example.com", "local"},
33 {"reply@[127.0.0.1]", "local"},
36 for (auto const& test_case : test_cases) {
37 auto const enc_rep = srs.enc_reply(test_case);
38 CHECK(Mailbox::validate(fmt::format("{}@x.y", enc_rep))) << enc_rep;
39 auto const dec_rep = srs.dec_reply(enc_rep);
40 if (!dec_rep || *dec_rep != test_case) {
41 LOG(INFO) << "in mail_from == " << test_case.mail_from;
42 LOG(INFO) << "in local_part == " << test_case.rcpt_to_local_part;
43 LOG(INFO) << " enc_rep == " << enc_rep;
44 LOG(INFO) << "out mail_from == " << dec_rep->mail_from;
45 LOG(INFO) << "out local_part == " << dec_rep->rcpt_to_local_part;
46 CHECK(test_case == *dec_rep);
50 for (auto const& test_case : test_cases) {
51 auto const enc_bnc = srs.enc_bounce(test_case, "sender.com");
52 CHECK(Mailbox::validate(enc_bnc)) << enc_bnc;
53 auto const dec_bnc = srs.dec_bounce(enc_bnc, 3);
54 if (!dec_bnc || dec_bnc->mail_from != test_case.mail_from) {
55 LOG(INFO) << "in mail_from == " << test_case.mail_from;
56 LOG(INFO) << " enc_bnc == " << enc_bnc;
57 LOG(INFO) << "out mail_from == " << dec_bnc->mail_from;