]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
digest: trim the last element of lastdigest if needed
authorBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 18 Dec 2023 09:02:07 +0000 (10:02 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Mon, 18 Dec 2023 09:02:07 +0000 (10:02 +0100)
Add regression tests about it

src/mlmmj.c
tests/mlmmj-maintd.sh
tests/mlmmj.c

index 1ce9b5fa11e27451a8ab6b17f4ceb6c263e61258..6c6c41a0b4cae1619dcfc5aa4764e21a17eaad09 100644 (file)
@@ -85,6 +85,9 @@ parse_lastdigest(char *line, long *lastindex, time_t *lasttime,
                return true;
        }
        walk = walk + strlen(walk) + 1;
+       size_t l = strlen(walk) -1;
+       if (walk[l] == '\n')
+               walk[l] = '\0';
        *lastissue = strtoim(walk, LONG_MIN, LONG_MAX, errstr);
        if (*errstr != NULL) {
                *errstr = "Invalid value for lastissue";
index eac7b8e3eb4810e77d524051e88743ff3dcd3336..ec7bd261d4e098c63e6de94e2637b92afdb6144a 100755 (executable)
@@ -12,6 +12,7 @@ tests_init \
        digests_2 \
        digests_3 \
        digests_4 \
+       digests_5 \
        unsub_bouncers_0 \
        unsub_bouncers_1 \
        unsub_bouncers_2 \
@@ -485,6 +486,32 @@ run_digests
        atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log
 }
 
+digests_5_body()
+{
+       test $(id -u) = 0 && atf_skip "Can only be run as non-root"
+       mkdir lists
+       init_ml lists/ml
+       echo test@mlmmjtest > lists/ml/control/listaddress
+
+       echo "0" > lists/ml/index
+       echo "3774:1702743593:141" > lists/ml/lastdigest
+       atf_check -s exit:0 $mlmmjmaintd -L lists/ml -F
+       output="Starting maintenance run at
+
+clean_moderation
+clean_discarded
+clean_subconf
+clean_unsubconf
+resend_queue
+resend_requeue
+clean_nolongerbouncing
+unsub_bouncers
+probe_bouncers
+run_digests
+"
+       atf_check -o "inline:$output" sed -e "s/at .*/at/" lists/ml/mlmmj-maintd.lastrun.log
+}
+
 unsub_bouncers_0_body()
 {
        init_ml list
index e68f76434458925f463a6b44d4e5a356ad441841..b403c8dd493211c890a93276c283253969f7c2f9 100644 (file)
@@ -771,6 +771,14 @@ ATF_TC_BODY(parse_lastdigest, tc)
        ATF_REQUIRE_EQ(lasttime, 1702743593);
        ATF_REQUIRE_EQ(lastissue, 141);
        free(line);
+
+       line = xstrdup("3774:1702743593:141\n");
+       ATF_REQUIRE(parse_lastdigest(line, &lastindex, &lasttime, &lastissue,
+           &errstr));
+       ATF_REQUIRE_EQ(lastindex, 3774);
+       ATF_REQUIRE_EQ(lasttime, 1702743593);
+       ATF_REQUIRE_EQ(lastissue, 141);
+       free(line);
 }
 
 ATF_TC_BODY(extract_bouncetime, tc)