From 838a722c2228f9c0ab3498ebfe3e77e1053aeea2 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 14 Feb 2023 15:26:02 +0100 Subject: [PATCH] add missing c file --- tests/mlmmj_tests.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/mlmmj_tests.c diff --git a/tests/mlmmj_tests.c b/tests/mlmmj_tests.c new file mode 100644 index 00000000..580a2721 --- /dev/null +++ b/tests/mlmmj_tests.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2023 Baptiste Daroussin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "mlmmj_tests.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +const char *listdir[] = { + "incoming", + "queue", + "queue/discarded", + "archive", + "text", + "subconf", + "unsubconf", + "bounce", + "control", + "moderation", + "subscribers.d", + "digesters.d", + "requeue", + "nomailsubs.d" +}; + +void +init_ml(bool complete) +{ + int fd; + ATF_CHECK(mkdir("list", 00755) != -1); + fd = open("list", O_DIRECTORY); + ATF_CHECK(fd != -1); + + for (uintmax_t i = 0; i < NELEM(listdir); i++) { + ATF_CHECK(mkdirat(fd, listdir[i], 00755) != -1); + } + + if (complete) + atf_utils_create_file("list/control/listaddress", "test@test"); +} + +int +fakesmtp(int pipe) +{ + int s; + struct sockaddr_in me; + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) + exit(1); + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &(int) { 1 }, sizeof(int)) != 0) + exit(2); + memset(&me, 0, sizeof(me)); + me.sin_family = AF_INET; + me.sin_addr.s_addr = inet_addr("127.0.0.1"); + /* specific interface */ + me.sin_port = htons(25678); + if (bind(s, (struct sockaddr *) &me, sizeof(me)) == -1) + exit(3); + if (listen(s, 1) == -1) + exit(4); + dprintf(pipe, "ready\n"); + + return (s); +} + +void +read_print_reply(int fd, const char **replies, size_t nreplies) +{ + char *r; + + for (size_t i = 0; i < nreplies; i++) { + r = atf_utils_readline(fd); + if (r == NULL) + atf_tc_fail("Impossible to read response %zu", i); + printf("%s\n", r); + if (replies[i] != NULL) + dprintf(fd, "%s", replies[i]); + free(r); + } +} -- 2.47.3