• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 16484517872

23 Jul 2025 10:27PM UTC coverage: 72.168% (-0.005%) from 72.173%
16484517872

push

github

yuwata
test-unit-serialize.c: Migrate to new assertion macros

We recently added a new set of assertion macros such as ASSERT_GE, ASSERT_OK, ASSERT_EQ, ... which show not
only the expression that failed but also the values of the arguments of the expression. Let's use them.

4 of 4 new or added lines in 1 file covered. (100.0%)

321 existing lines in 44 files now uncovered.

302532 of 419205 relevant lines covered (72.17%)

743874.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/src/test/test-libcrypt-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <crypt.h>
4

5
#include "libcrypt-util.h"
6
#include "strv.h"
7
#include "tests.h"
8

9
static void test_crypt_preferred_method(void) {
1✔
10
        log_info("/* %s */", __func__);
1✔
11

12
        log_info("crypt_preferred_method: %s",
1✔
13
#if HAVE_CRYPT_PREFERRED_METHOD
14
                 crypt_preferred_method()
15
#else
16
                 "(not available)"
17
#endif
18
        );
19
}
1✔
20

21
static void test_make_salt(void) {
1✔
22
        log_info("/* %s */", __func__);
1✔
23

24
        for (int i = 0; i < 10; i++) {
11✔
25
                _cleanup_free_ char *t;
10✔
26

27
                assert_se(make_salt(&t) == 0);
10✔
28
                log_info("%s", t);
10✔
29
        }
30
}
1✔
31

32
static int test_hash_password(void) {
1✔
33
        log_info("/* %s */", __func__);
1✔
34

35
        /* As a warm-up exercise, check if we can hash passwords. */
36

37
        bool have_sane_hash = false;
1✔
38

39
        FOREACH_STRING(hash,
7✔
40
                       "ew3bU1.hoKk4o",
41
                       "$1$gc5rWpTB$wK1aul1PyBn9AX1z93stk1",
42
                       "$2b$12$BlqcGkB/7BFvNMXKGxDea.5/8D6FTny.cbNcHW/tqcrcyo6ZJd8u2",
43
                       "$5$lGhDrcrao9zb5oIK$05KlOVG3ocknx/ThreqXE/gk.XzFFBMTksc4t2CPDUD",
44
                       "$6$c7wB/3GiRk0VHf7e$zXJ7hN0aLZapE.iO4mn/oHu6.prsXTUG/5k1AxpgR85ELolyAcaIGRgzfwJs3isTChMDBjnthZyaMCfCNxo9I.",
45
                       "$y$j9T$$9cKOWsAm4m97WiYk61lPPibZpy3oaGPIbsL4koRe/XD") {
46
                int b;
6✔
47

48
                b = test_password_one(hash, "ppp");
6✔
49
                log_info("%s: %s", hash, yes_no(b));
12✔
50
#if defined(XCRYPT_VERSION_MAJOR)
51
                /* xcrypt is supposed to always implement all methods. */
52
                assert_se(b);
6✔
53
#endif
54

55
                if (b && IN_SET(hash[1], '6', 'y'))
6✔
56
                        have_sane_hash = true;
57
        }
58

59
        return have_sane_hash;
1✔
60
}
61

62
static void test_hash_password_full(void) {
1✔
63
        log_info("/* %s */", __func__);
1✔
64

65
        _cleanup_free_ void *cd_data = NULL;
2✔
66
        int cd_size = 0;
1✔
67

68
        log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
1✔
69

70
        for (unsigned c = 0; c < 2; c++)
3✔
71
                FOREACH_STRING(i, "abc123", "h⸿sło") {
6✔
72
                        _cleanup_free_ char *hashed;
4✔
73

74
                        if (c == 0)
4✔
75
                                assert_se(hash_password_full(i, &cd_data, &cd_size, &hashed) == 0);
2✔
76
                        else
77
                                assert_se(hash_password_full(i, NULL, NULL, &hashed) == 0);
2✔
78
                        log_debug("\"%s\" → \"%s\"", i, hashed);
4✔
79
                        log_info("crypt_r[a] buffer size: %i bytes", cd_size);
4✔
80

81
                        assert_se(test_password_one(hashed, i) == true);
4✔
82
                        assert_se(test_password_one(i, hashed) <= 0); /* We get an error for non-utf8 */
4✔
83
                        assert_se(test_password_one(hashed, "foobar") == false);
4✔
84
                        assert_se(test_password_many(STRV_MAKE(hashed), i) == true);
4✔
85
                        assert_se(test_password_many(STRV_MAKE(hashed), "foobar") == false);
4✔
86
                        assert_se(test_password_many(STRV_MAKE(hashed, hashed, hashed), "foobar") == false);
4✔
87
                        assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
4✔
88
                                                               hashed,
89
                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
90
                                                     i) == true);
91
                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
4✔
92
                                                               hashed,
93
                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
94
                                                     i) == true);
95
                        assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
4✔
96
                                                               hashed,
97
                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
98
                                                     "") == false);
99
                        assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
4✔
100
                                                               hashed,
101
                                                               "$y$j9T$SAayASazWZIQeJd9AS02m/$"),
102
                                                     "") == false);
103
                }
104
}
1✔
105

106
int main(int argc, char *argv[]) {
1✔
107
        test_setup_logging(LOG_DEBUG);
1✔
108

109
#if defined(__powerpc__) && !defined(XCRYPT_VERSION_MAJOR)
110
        return log_tests_skipped("crypt_r() causes a buffer overflow on ppc64el, see https://github.com/systemd/systemd/pull/16981#issuecomment-691203787");
111
#endif
112

113
        test_crypt_preferred_method();
1✔
114
        test_make_salt();
1✔
115

116
        if (!test_hash_password())
1✔
UNCOV
117
                return log_tests_skipped("crypt doesn't support yescrypt or sha512crypt");
×
118

119
        test_hash_password_full();
1✔
120

121
        return 0;
1✔
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc