tests: Modernize writekeyfile.c 46/14246/4
authorAndrew Deason <adeason@sinenomine.net>
Wed, 17 Jun 2020 17:23:46 +0000 (12:23 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 19 Jun 2020 15:48:57 +0000 (11:48 -0400)
commitcbc5c4b51fcd0a990216fc31abe308a9e85fd9df
tree18adc2a8fe34550e589e8133a6fce992ca7b3d12
parent22a66e7b7e1d73437a8c26c2a1b45bc4ef214e77
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/TESTS
tests/auth/KeyFile.short [new file with mode: 0644]
tests/auth/Makefile.in
tests/auth/writekeyfile.c
tests/auth/writeoldkey-t [new file with mode: 0755]