openafs/tests/auth/authcon-t.c
Andrew Deason 71acc392a3 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>
2021-08-13 17:50:23 -04:00

98 lines
3.2 KiB
C

/*
* Copyright (c) 2010 Your File System Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
* Test those bits of the authcon interface that we can test without involving
* the cache manager.
*/
#include <afsconfig.h>
#include <afs/param.h>
#include <roken.h>
#include <rx/rx.h>
#include <rx/rxkad.h>
#include <afs/authcon.h>
#include <afs/cellconfig.h>
#include <tests/tap/basic.h>
#include "common.h"
int
main(int argc, char **argv)
{
struct afsconf_dir *dir;
char *dirname;
struct rx_securityClass **classes;
struct rx_securityClass *secClass;
int secIndex;
int numClasses;
struct afsconf_typedKey *key;
int code = 0;
struct afsconf_bsso_info bsso;
memset(&bsso, 0, sizeof(bsso));
afstest_SkipTestsIfBadHostname();
plan(8);
dirname = afstest_BuildTestConfig();
dir = afsconf_Open(dirname);
if (dir == NULL) {
fprintf(stderr, "Unable to configure directory.\n");
code = 1;
goto out;
}
rx_Init(0);
/* Server Security objects */
bsso.dir = dir;
afsconf_BuildServerSecurityObjects_int(&bsso, &classes, &numClasses);
is_int(5, numClasses, "5 security classes are returned, as expected");
ok(classes[1] == NULL, "The rxvab class is undefined, as requested");
free(classes);
/* Up to date checks */
ok(afsconf_UpToDate(dir), "Newly opened directory is up to date");
is_int(0, afsconf_AddKey(dir,
1, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 0),
"Adding key worked");
ok(!afsconf_UpToDate(dir), "Directory with newly added key isn't");
afsconf_ClientAuth(dir, &secClass, &secIndex);
ok(afsconf_UpToDate(dir), "afsconf_ClientAuth() resets UpToDate check");
afsconf_DeleteKey(dir, 1);
ok(!afsconf_UpToDate(dir), "Directory with newly deleted key isn't");
afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &key);
ok(afsconf_UpToDate(dir), "afsconf_GetLatestKeyByTypes resest UpToDate");
out:
afstest_rmdtemp(dirname);
return code;
}