1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include "config.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <shadow.h>
#include <stdint.h>
#include <unistd.h>
#include <crypt.h>
static void test_nwrap_getspent(void **state)
{
struct spwd *sp;
uint32_t i;
(void)state; /* unused */
setspent();
for (sp = getspent(), i = 0; sp != NULL; sp = getspent(), i++) {
if (i == 0) {
assert_string_equal(sp->sp_namp, "alice");
} else {
assert_string_equal(sp->sp_namp, "bob");
}
}
endspent();
}
static void test_nwrap_getspnam(void **state)
{
char *encrypted_password;
struct spwd *sp;
(void)state; /* unused */
sp = getspnam("alice");
assert_non_null(sp);
assert_string_equal(sp->sp_namp, "alice");
encrypted_password = crypt("secret", sp->sp_pwdp);
assert_non_null(encrypted_password);
assert_string_equal(encrypted_password, sp->sp_pwdp);
sp = getspnam("bob");
assert_non_null(sp);
assert_string_equal(sp->sp_namp, "bob");
encrypted_password = crypt("secret", sp->sp_pwdp);
assert_non_null(encrypted_password);
assert_string_equal(encrypted_password, sp->sp_pwdp);
}
int main(void) {
int rc;
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_nwrap_getspent),
cmocka_unit_test(test_nwrap_getspnam),
};
rc = cmocka_run_group_tests(tests, NULL, NULL);
return rc;
}
|