~ubuntu-branches/ubuntu/wily/policykit-1/wily

« back to all changes in this revision

Viewing changes to test/mocklibc/README

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-01-06 12:28:54 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120106122854-ib9s0ej8akqiy0lb
Tags: 0.104-1
* New upstream release.
  - Add support for netgroups. (LP: #724052)
* debian/rules: Disable systemd support, continue to work with ConsokeKit.
* 05_revert-admin-identities-unix-group-wheel.patch: Refresh to apply
  cleanly.
* debian/libpolkit-gobject-1-0.symbols: Add new symbols from this new
  release.
* debian/rules: Do not let test failures fail the build. The new test suite
  also runs a test against the system D-BUS/ConsoleKit, which can't work on
  buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
= MockLibc 1.1 =
 
2
 
 
3
Mocks of common libc functions who have global state. Version 1.1 focuses on
 
4
NSS related methods (user, group, and netgroup queries).
 
5
 
 
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.
 
9
 
 
10
 
 
11
== Requirements ==
 
12
 
 
13
* Tests require the 'id' and 'innetgr' commands in the PATH
 
14
 
 
15
 
 
16
== Build ==
 
17
 
 
18
$ cd mocklibc-1.1
 
19
$ ./configure
 
20
$ make
 
21
$ make check
 
22
 
 
23
 
 
24
== Install ==
 
25
 
 
26
$ make install
 
27
 
 
28
 
 
29
== Example Usage ==
 
30
 
 
31
$ id foo
 
32
id: foo: No such user
 
33
$ export MOCK_PASSWD=./testdata/passwd
 
34
$ export MOCK_GROUP=./testdata/group
 
35
$ mkdir ./testdata
 
36
$ echo “foo:x:9000:9000::/home/foo:/bin/bash” > “$MOCK_PASSWD”
 
37
$ echo “mockusers:x:9001:foo” > “$MOCK_GROUP”
 
38
$ mocklibc id foo
 
39
uid=9000(foo) gid=9000(foo) groups=9000(foo),9001(mockusers)
 
40
 
 
41
 
 
42
== Use without install ==
 
43
 
 
44
mocklibc can be used directly from the bin directory, without being installed:
 
45
$ cd mocklibc-1.1
 
46
$ ./configure
 
47
$ make
 
48
$ bin/mocklibc id foo
 
49
 
 
50
 
 
51
== Hacking ==
 
52
 
 
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.
 
56
 
 
57
 
 
58
== Mocked Functions ==
 
59
 
 
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.
 
63
 
 
64
* pwd.h (NSS users, configured with MOCK_PASSWD)
 
65
  * setpwent
 
66
  * getpwent
 
67
  * endpwent
 
68
  * getpwnam
 
69
  * getpwuid
 
70
* grp.h (NSS groups, configured with MOCK_GROUP)
 
71
  * setpwent
 
72
  * getpwent
 
73
  * endpwent
 
74
  * getpwnam
 
75
  * getpwuid
 
76
* netdb.h (NSS netgroups, no DNS, configured with MOCK_NETGROUP)
 
77
  * setnetgrent
 
78
  * getnetgrent
 
79
  * endnetgrent
 
80
  * innetgr
 
81
 
 
82
 
 
83
== Configuration ==
 
84
 
 
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
 
87
number generation.
 
88
 
 
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
 
93
 
 
94
 
 
95
== F.A.Q. ==
 
96
 
 
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.
 
103
 
 
104
 
 
105
== TODO ==
 
106
 
 
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.
 
109
 
 
110
 
 
111
== Future ==
 
112
 
 
113
The following may be supported in the future, and I'm taking requests for other
 
114
functionality at 'vonhollen@gmail.com'.
 
115
 
 
116
Features:
 
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)
 
121