forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmod_passwd.c
83 lines (71 loc) · 2.9 KB
/
testmod_passwd.c
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
74
75
76
77
78
79
80
81
82
83
/**
* @file
*
* @brief Tests for passwd plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdlib.h>
#include <string.h>
#include <kdbconfig.h>
#include <tests_plugin.h>
void test_read (void)
{
Key * parentKey = keyNew ("user/tests/passwd-read", KEY_VALUE, srcdir_file ("passwd/passwd_in"), KEY_END);
KeySet * conf = ksNew (10, keyNew ("system/index", KEY_VALUE, "name", KEY_END), KS_END);
PLUGIN_OPEN ("passwd");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet failed\n");
Key * key = ksLookupByName (ks, "user/tests/passwd-read/root/uid", 0);
succeed_if (key, "key root/uid not found\n");
succeed_if (strcmp (keyString (key), "32") == 0, "root/uid doesn't match\n");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void test_write (void)
{
Key * parentKey = keyNew ("user/tests/passwd-write", KEY_VALUE, elektraFilename (), KEY_END);
KeySet * conf = ksNew (30, keyNew ("system/index", KEY_VALUE, "name", KEY_END), KS_END);
PLUGIN_OPEN ("passwd");
KeySet * ks = ksNew (30, keyNew ("user/tests/passwd-write/root", KEY_BINARY, KEY_END),
keyNew ("user/tests/passwd-write/root/gecos", KEY_VALUE, "root", KEY_END),
keyNew ("user/tests/passwd-write/root/gid", KEY_VALUE, "1024", KEY_END),
keyNew ("user/tests/passwd-write/root/home", KEY_VALUE, "/root", KEY_END),
keyNew ("user/tests/passwd-write/root/passwd", KEY_VALUE, "x", KEY_END),
keyNew ("user/tests/passwd-write/root/shell", KEY_VALUE, "/bin/zsh", KEY_END),
keyNew ("user/tests/passwd-write/root/uid", KEY_VALUE, "1024", KEY_END), KS_END);
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "failed to write passwd file\n");
succeed_if (compare_line_files (srcdir_file ("passwd/passwd_out"), keyString (parentKey)), "files do nat match as expected\n");
ksDel (ks);
keyDel (parentKey);
PLUGIN_CLOSE ();
}
void test_read_write (void)
{
Key * parentKeyRead = keyNew ("user/tests/passwd-write", KEY_VALUE, srcdir_file ("passwd/passwd_in"), KEY_END);
Key * parentKeyWrite = keyNew ("user/tests/passwd-write", KEY_VALUE, elektraFilename (), KEY_END);
KeySet * conf = ksNew (10, keyNew ("system/index", KEY_VALUE, "name", KEY_END), KS_END);
PLUGIN_OPEN ("passwd");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbGet (plugin, ks, parentKeyRead) == 1, "kdbGet failed\n");
ksRewind (ks);
succeed_if (plugin->kdbSet (plugin, ks, parentKeyWrite) == 1, "kdbSet failed\n");
succeed_if (compare_line_files (srcdir_file ("passwd/passwd_in"), keyString (parentKeyWrite)), "files do not match as expected\n");
ksDel (ks);
keyDel (parentKeyRead);
keyDel (parentKeyWrite);
PLUGIN_CLOSE ();
}
int main (int argc, char ** argv)
{
printf ("PASSWD TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_read ();
test_write ();
test_read_write ();
print_result ("testmod_passwd");
return nbError;
}