tests: Avoid plain printf in auth/superuser-t If we're reporting an error, we should be printing to stderr. If we're printing informational data, we should be using diag() to try to avoid interfering with the TAP data. Change all printf() calls into one of those two options. Change-Id: I2e0d577e0c32efa539ed486190dbaca23bd0487f Reviewed-on: https://gerrit.openafs.org/14866 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Improve fork/waitpid error handling A couple of places in our test code aren't handling errors from fork() or waitpid() properly. We don't expect to ever hit errors for these, but sysbail() in this case, so they don't fail silently. Change-Id: I1c548f93f4d4ac4344032d7847470b04319386f2 Reviewed-on: https://gerrit.openafs.org/14865 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Add test keys in afstest_BuildTestConfig Change afstest_BuildTestConfig to add the local keys into the generated config dir, unless the info->skipkeys is set. This just makes afstest_BuildTestConfig a little easier to use for the common case of generating a fully-usable config dir with usable keys (only some callers want to skip generating keys in order to test key-populating functionality). Change-Id: I1ce9d062ea30c391a93562fc90bc18997de75383 Reviewed-on: https://gerrit.openafs.org/14835 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce afstest.pm Create a perl module for some generic common code for our tests written in perl: afstest.pm. With this commit, the module just contains a couple of functions to calculate paths in our src and obj trees (src_path(), obj_path()), analogous to afstest_src_path and afstest_obj_path in our C helper library, libafstest_common.la. Convert all existing perl test code that uses C_TAP_SOURCE/C_TAP_BUILD to use these new functions. Change-Id: I5e4d45e3d2d59449bbfc426476cb29b710c73bc1 Reviewed-on: https://gerrit.openafs.org/14800 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Remove check/test/tests subdir targets Since commit a62de618 (Build util tests properly with make check), running 'make check' in tests/ also runs 'make check' in each of the tests subdirectories, which builds the tests in that dir. (And the same goes for 'make test' and 'make tests'.) This does ensure that the tests are built before we run them, but it's a bit strange to build the tests under 'make check', a target that usually runs tests. We do this in the top-level tests dir to make sure that the tests are built, but this purpose is served by the existing 'make all' target. So to reduce some duplication of logic, and reduce the number of targets the subdirs need to implement, just have 'make check' depend on 'make all', so we know the tests are built when we go to run them. Change-Id: I2fcbe88daeeae94cd7ef7a4a8326c4b56fadee5a Reviewed-on: https://gerrit.openafs.org/14636 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Generalize temp dir management Currently, afstest_BuildTestConfig calls afstest_mkdtemp (our thin wrapper around mkdtemp) to create its temporary config dir. We may want to make new tests, though, that create a temp dir for other purposes. To make that easier, move a little more code into afstest_mkdtemp, so the caller doesn't need to construct the template. To allow callers to clean up such temporary dirs, change afstest_UnlinkTestConfig into a more general function, afstest_rmdtemp. Allow this new function to remove all files in a dir, not just files one-level-deep. To avoid needing to write our own traversal and removal logic, just run 'rm -rf' via a new function, afstest_systemlp(). Move these temp dir-related functions from config.c into files.c, since they are no longer specific to config dirs. Change-Id: I16750a2f30e98c9ca2e14dfb7d3fc9bc5d456e8d Reviewed-on: https://gerrit.openafs.org/14632 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Introduce afstest_*_path() Currently, several of our tests contain logic to locate files (via srcdir or objdir), based on the C_TAP_SOURCE/BUILD environment variables. This logic is duplicated in several places, so consolidate the code into a couple of new functions: afstest_src_path and afstest_obj_path. Update all callers to use these new functions. Change-Id: I67a5e5d7f8fd7a1edb55a45e52d877ac41f9a2ea Reviewed-on: https://gerrit.openafs.org/14319 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Introduce afstest_asprintf Add a thin wrapper around asprintf, called afstest_asprintf (and afstest_vasprintf), which does its own error checking. This just helps makes tests a little less cluttered when needing to construct strings. Adapt all asprintf callers in 'tests' to use the wrapper. Change-Id: I6c4ae5b72af827e2c4c66ecfc57f152855b1d401 Reviewed-on: https://gerrit.openafs.org/14620 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Introduce libafstest_common Currently, a few tests use the code in tests/common/ by linking individual object files in there in addition to the test code (e.g. linking ../common/config.o along with superuser-t.o). This convention makes it very obnoxious to move code around in tests/common/, since any users need to update their link lines. It also makes it difficult for code in tests/common/ to make use of functions in other tests/common/ files. To fix this, just build all of the objects in tests/common/ into a convenience library, called libafstest_common, and link the relevant tests against that. Link a few requisite libraries (roken, rfc3961) in libafstest_common, so each individual test doesn't need to link against them. Also link the TAP library itself in libafstest_common, so tests don't have to explicitly link against it separately. To do this, convert it into a libtool library, libafstest_tap.la. Change-Id: I9c031c164efee20201336edcbfaff429e1d231b7 Reviewed-on: https://gerrit.openafs.org/14318 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce 'make check TESTS=test/name' Currently 'make check' always runs all tests. We can run individual tests manually, but doing so is a bit cumbersome to do under the same environment as 'make check', since doing so means running something like this: $ MAKECHECK=1 $(abs_top_srcdir)/tests/libwrap @TOP_OBJDIR@/lib \ ./runtests opr/fmt util/ktime To make it easier to run single tests introduce a way of calling 'make check' like this: $ make check TESTS='opr/fmt util/ktime' Which will run the same commands as 'make check', but will run runtests with only the specified tests, instead of running the default list. Some makefiles currently use a "TESTS" or "tests" variable to list their test binaries; rename them all to "BINS" to avoid conflicting with this new use for "TESTS" and to make our makefiles a little more consistent. Change-Id: I427f83be0d4571794644a97123bcd1f32427bd05 Reviewed-on: https://gerrit.openafs.org/14317 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Move key-related warnings to common server code Each server process can log a couple of different warnings about the server keys found on disk: - If afsconf_GetLatestKey() returns success (indicating a single-DES key is present), we call LogDesWarning(). - If afsconf_CountKeys() returns 0 (indicating there are no keys at all on disk), we log a warning that all authenticated access will fail. Currently, the code to do these checks and log the relevant warning is duplicated across the startup code for nearly every server process. To avoid this duplication, and to make sure the checks aren't accidentally skipped for anyone, move these checks to afsconf_BuildServerSecurityObjects, which every server process calls. We must add an additional parameter to afsconf_BuildServerSecurityObjects to handle the different logging mechanism these servers use, but afsconf_BuildServerSecurityObjects is declared in a public header (cellconfig.h), and is exported in a public library (libafsauthent). So to avoid changing a public symbol, introduce a new variant of the function, called afsconf_BuildServerSecurityObjects_int. Declare this in a new internal header, authcon.h. We don't have easily-usable logging functions for upserver and butc, so just don't log the warnings for those. For ubik servers, don't update ubik_SetServerSecurityProcs to use the new function; the initial call to afsconf_BuildServerSecurityObjects_int in the server's startup code will cover logging the warning on startup. Change-Id: I5d5fceefdaf907f96db9f1c0d21ceb6957299a59 Reviewed-on: https://gerrit.openafs.org/10831 Tested-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Accommodate c-tap-harness 4.7 The SOURCE and BUILD environment variables have been changed to C_TAP_SOURCE and C_TAP_BUILD in the new version of c-tap-harness. The runtests command syntax has changed as well. Convert all of the old SOURCE and BUILD environment variables to the new C_TAP_SOURCE and C_TAP_BUILD names. Add the required -l command line option to specify the test list. Add the new runtests -v option to run the tests in verbose mode to make it easier to see which tests failed. Change-Id: I209a6dc13d6cd1507519234fce1564fc4641e70b Reviewed-on: https://gerrit.openafs.org/14295 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Modernize writekeyfile.c tests/auth/writekeyfile.c contains some code used to generate tests/auth/KeyFile, which is used to test code interpreting the old-style KeyFile format. This code currently has a few problems: - We don't check the results of afstest_mkdtemp, which could allow symlink attacks from other users on the system. - We duplicate some logic from afstest_BuildTestConfig, in order to build a temporary config dir. - writekeyfile isn't built or run by default (it only exists to generate KeyFile, so it's almost never run), so eventual bitrot is quite likely, and the existing code already generates warnings. To avoid this, change writekeyfile.c to use the existing afstest_BuildTestConfig to generate a local config dir. To ensure we avoid bitrot, build writekeyfile by default, and create a test to run it, to make sure it can generate a KeyFile as expected. Note that the KeyFile.short we test against is different than the KeyFile currently in the tree. The existing KeyFile was generated from an older OpenAFS release, which always generated 100-byte KeyFiles, even if we only have a few keys. The current codebase only writes out as much key data as needed, so the generated KeyFiles are shorter (but still understandable by older OpenAFS releases). Keep the old 100-byte KeyFile around, since that's what older OpenAFS would generate, and create a new KeyFile.short to test against, to make sure our code for generating KeyFiles doesn't change any further. Change-Id: Ibe9246c6dd808ed2b2225dd7be2b27bbdee072fd Reviewed-on: https://gerrit.openafs.org/14246 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Use usleep instead of nanosleep Commit "Build tests by default" 68f406436cc21853ff854c514353e7eb607cb6cb changes the build so tests are always built. On Solaris 10 the build fails because nanosleep is in librt, which we do not link against. Replace nanosleep with usleep. This avoids introducing extra configure tests just for Solaris 10. Note that with Solaris 11 nanosleep was moved from librt to libc, the standard C library. Change-Id: I6639f32bb8c8ace438e0092a866f06561dad54f1 Reviewed-on: https://gerrit.openafs.org/14244 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Emulate mkdtemp when not available Commit "Build tests by default" 68f406436cc21853ff854c514353e7eb607cb6cb changes the build so tests are always built. On Solaris 10 Update 10 and earlier the build fails because the mkdtemp function is not available. Introduce a wrapper 'afstest_mkdtemp' that uses mkdtemp if available, otherwise uses mktemp/mkdir. Change-Id: I0118f838ed9a89927e2ddac4cad822574601558a Reviewed-on: https://gerrit.openafs.org/14243 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Wait for server start in auth/superuser-t The auth/superuser-t test runs an Rx server and client in two child processes. If the client process tries to contact the server before the server has started listening on its port, some tests involving RPCs can fail (notably test 39, "Can run a simple RPC"). Normally if we try to contact a server that's not there, Rx will try resending its packets a few times, but on Linux with AFS_RXERRQ_ENV, if the port isn't open at all, we can get an ICMP_PORT_UNREACH error, which causes the relevant Rx call to die immediately with RX_CALL_DEAD. This means that if the auth/superuser-t client is only just a bit faster than the server starting up, tests can fail, since the server's port is not open yet. To avoid this, we can wait until the server's port is open before starting the client process. To do this, have the server process send a SIGUSR1 to the parent after rx_Init() is called, and have the parent process wait for the SIGUSR1 (waiting for a max of 5 seconds before failing). This should guarantee that the server's port will be open by the time the client starts running. Note that before commit 086d1858 (LINUX: Include linux/time.h for linux/errqueue.h), AFS_RXERRQ_ENV was mistakenly disabled on Linux 3.17+, so this issue was probably not possible on recent Linux before that commit. Change-Id: I0032a640b83c24f72c03e7bea100df5bc3d9ed4c Reviewed-on: https://gerrit.openafs.org/14109 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
tests: Introduce afstest_GetProgname Currently, in tests/volser/vos-t.c we call afs_com_err as "authname-t", which is clearly a mistake during some code refactoring (introduced in commit 2ce3fdc5, "tests: Abstract out code to produce a Ubik client"). We could just change this to "vos-t", but instead of specifying constant strings everywhere, change this to figure out what the current command is called, and just use that. Put this code into a new function, afstest_GetProgname, and convert existing tests to use that instead of hard-coding the program name given to afs_com_err. Change-Id: I3ed02c89f93798568783c7d717e8fb2e39dcce14 Reviewed-on: https://gerrit.openafs.org/13991 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Fix most tests for objdir builds Fix a few miscellaneous issues with building and running our tests in objdir builds: - Our C tests use -I$(srcdir)/../.. in the CFLAGS, so we can #include <tests/tap/basic.h>. However, basic.h actually gets copied from src/external/c-tap-harness/tests/tap/ to tests/tap/ during the build, and so basic.h is available in the objdir, not srcdir. For objdir builds, this causes building the tests to fail with failing to find basic.h. Fix this to use TOP_OBJDIR as the include path instead. - Our 'make check' in tests/ tries to run ./libwrap; but our cwd will be in the objdir for objdir builds, and libwrap is a script in our srcdir. Fix this to run libwrap from the srcdir path. - In tests/opr/softsig-t, it tries to find the 'softsig-helper' binary in the same dir as 'softsig-t'. However, softsig-t is just a script in the srcdir, but softsig-helper is a binary built in the objdir. Fix this to use the BUILD env var provided by the tests wrapper, by default. Change-Id: Iff642613bfc88d0d7e348660dc62f59e6fa8af75 Reviewed-on: https://gerrit.openafs.org/13939 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Use rxgk in afsconf_BuildServerSecurityObjects In afsconf_BuildServerSecurityObjects, create a server security object for rxgk. Currently, this will only accept printed rxgk tokens, not tokens negotiated via GSSNegotiate. Future commits will add functionality to handle user-negotiated tokens, fileserver-specific creds, etc. Change-Id: Ie2bbef0d591641e80bb85240316c4ee5f9f8ff05 Reviewed-on: https://gerrit.openafs.org/12941 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests/auth/keys-t.c: Don’t ignore return value of write Resolves this warning: keys-t.c: In function ‘copy’: keys-t.c:63:6: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result] write(out, block, len); ^ Change-Id: If2427f2658b428091ffba3d11643ad95f193a67d Reviewed-on: http://gerrit.openafs.org/11957 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>