3
Mocks of common libc functions who have global state. Version 1.1 focuses on
4
NSS related methods (user, group, and netgroup queries).
6
This library is a re-implementation of specific libc methods, not a tool for
7
creating mock functions. Use MockLibc to create a consistent environment for
8
your unit tests, when they need to query system information.
13
* Tests require the 'id' and 'innetgr' commands in the PATH
33
$ export MOCK_PASSWD=./testdata/passwd
34
$ export MOCK_GROUP=./testdata/group
36
$ echo “foo:x:9000:9000::/home/foo:/bin/bash” > “$MOCK_PASSWD”
37
$ echo “mockusers:x:9001:foo” > “$MOCK_GROUP”
39
uid=9000(foo) gid=9000(foo) groups=9000(foo),9001(mockusers)
42
== Use without install ==
44
mocklibc can be used directly from the bin directory, without being installed:
53
If using a git checkout instead of a source tarball, always run
54
'autogen --install' before './configure'. Whenever a Makefile.am or
55
configure.ac is modified, run 'autogen' again without --install.
58
== Mocked Functions ==
60
NSS Methods completely disregard /etc/nsswitch.conf, similar to using just
61
"files", but with modified paths. DNS is not modified and no *_r methods will
62
be implemented in this version.
64
* pwd.h (NSS users, configured with MOCK_PASSWD)
70
* grp.h (NSS groups, configured with MOCK_GROUP)
76
* netdb.h (NSS netgroups, no DNS, configured with MOCK_NETGROUP)
85
All configuration is handled through environment variables, though specific
86
mocklibc_* methods may be added in the future for things like time and random
89
Environment Variables:
90
* MOCK_PASSWD - Path to /etc/passwd replacement
91
* MOCK_GROUP - Path to /etc/group replacement
92
* MOCK_NETGROUP - Path to /etc/netgroup replacement
97
* Why not use a chroot? Chroot requires root, and forcing unit tests to run as
98
root is not desirable.
99
* Is there something that already does this? There are mock frameworks for C,
100
but this library is an implementation of specific common mocks C developers
101
need. A mock of set/get/endgrent still requires some basic code for iterating
102
group objects. This library provides that.
107
* Add functions to free unused memory in 'netdb_netgroup.c'. It leaks a ton of
108
memory every call. See TODO comments in code.
113
The following may be supported in the future, and I'm taking requests for other
114
functionality at 'vonhollen@gmail.com'.
117
* Redirect syslog messages to file at $MOCK_SYSLOG
118
* '*_r' methods in pwd.h, grp.h, and netdb.h
119
* netdb.h: gethostbyname, gethostbyaddr, getaddrinfo, get/freeaddrinfo
120
* Whitelist apps with $MOCK_ONLY (includes list of argv[0] names)