]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
test: add a helper function for any kind or email reception
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 15 Feb 2023 09:13:07 +0000 (10:13 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 15 Feb 2023 09:13:07 +0000 (10:13 +0100)
tests/mlmmj.c
tests/mlmmj_tests.c
tests/mlmmj_tests.h

index 7f82b5c50a67aaaf5ede0a80496362ed23525277..6a5921d873ff9f579c6b1c7649b086a133bef80c 100644 (file)
@@ -2131,37 +2131,7 @@ ATF_TC_BODY(send_single_mail, tc)
        ATF_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, smtppipe) >= 0);
        pid_t p = atf_utils_fork();
        if (p == 0) {
-               int s = fakesmtp(smtppipe[1]);
-               int c;
-               struct sockaddr_in cl;
-               socklen_t clsize = 0;
-               c = accept(s, (struct sockaddr *) &cl, &clsize);
-               if (c == -1)
-                       err(5, "accept()");
-               dprintf(c, "220 me fake smtp\n");
-               const char *replies[] = {
-                       "250-hostname.net\n"
-                       "250-PIPELINEING\n"
-                       "250-SIZE 20480000\n"
-                       "250-ETRN\n"
-                       "250-STARTTLS\n"
-                       "250-ENHANCEDSTATUSCODES\n"
-                       "250-8BITMIME\n"
-                       "250-DSN\n"
-                       "250-SMTPUTF8\n"
-                       "250 CHUNKING\n",
-                       "250 2.1.0 OK\n",
-                       "250 2.1.0 OK\n",
-                       "350 2.1.0 OK\n",
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       NULL,
-                       "250 2.1.0 OK\n",
-                       "221 2.0.0 bye\n",
-               };
-               read_print_reply(c, replies, NELEM(replies));
+               single_mail_reception(smtppipe[1]);
                exit(0);
        }
        close(smtppipe[1]);
index 580a2721a94273187a942b625c1f427ab2a621c2..89130197347017795ba796ae1ab4c1bc30da7474 100644 (file)
@@ -106,3 +106,43 @@ read_print_reply(int fd, const char **replies, size_t nreplies)
                free(r);
        }
 }
+
+void
+single_mail_reception(int fd)
+{
+       int s = fakesmtp(fd);
+       int c;
+       char *r;
+       struct sockaddr_in cl;
+       socklen_t clsize = 0;
+       c = accept(s, (struct sockaddr *) &cl, &clsize);
+       if (c == -1)
+               exit(5);
+       dprintf(c, "220 me fake smtp\n");
+
+       const char *replies[] = {
+               "250-hostname.net\n"
+               "250-PIPELINEING\n"
+               "250-SIZE 20480000\n"
+               "250-ETRN\n"
+               "250-STARTTLS\n"
+               "250-ENHANCEDSTATUSCODES\n"
+               "250-8BITMIME\n"
+               "250-DSN\n"
+               "250-SMTPUTF8\n"
+               "250 CHUNKING\n",
+               "250 2.1.0 OK\n",
+               "250 2.1.0 OK\n",
+               "350 2.1.0 OK\n",
+       };
+       read_print_reply(c, replies, NELEM(replies));
+       while ((r = atf_utils_readline(c)) != NULL) {
+               printf("%s\n", r);
+               if (strcmp(r, ".\r") == 0) {
+                       dprintf(c, "250 2.1.0 OK\n");
+                       break;
+               }
+       }
+       const char *rep = "221 2.0.0 bye\n";
+       read_print_reply(c, &rep, 1);
+}
index 35a8320e861e2c1337cff50e5ecf7e0efb4ad9de..f6431d7e3ad40f5080dbab5a3b624671f23bb045 100644 (file)
@@ -32,3 +32,4 @@
 void init_ml(bool complete);
 int fakesmtp(int pipe);
 void read_print_reply(int fd, const char **replies, size_t nreplies);
+void single_mail_reception(int fd);