mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
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>
This commit is contained in:
parent
d5e1428a3b
commit
dcf8af0b22
@ -52,13 +52,17 @@ main(int argc, char **argv)
|
||||
struct afsconf_typedKey *key;
|
||||
int code = 0;
|
||||
struct afsconf_bsso_info bsso;
|
||||
struct afstest_configinfo bct;
|
||||
|
||||
memset(&bsso, 0, sizeof(bsso));
|
||||
memset(&bct, 0, sizeof(bct));
|
||||
|
||||
afstest_SkipTestsIfBadHostname();
|
||||
|
||||
plan(8);
|
||||
dirname = afstest_BuildTestConfig();
|
||||
|
||||
bct.skipkeys = 1;
|
||||
dirname = afstest_BuildTestConfig(&bct);
|
||||
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
|
@ -109,6 +109,7 @@ int main(int argc, char **argv)
|
||||
struct rx_opaque *keyMaterial;
|
||||
struct afsconf_typedKey *typedKey;
|
||||
struct afsconf_typedKeyList *typedKeyList;
|
||||
struct afstest_configinfo bct;
|
||||
char *dirname;
|
||||
char *keyfile;
|
||||
char *keyfilesrc;
|
||||
@ -116,13 +117,16 @@ int main(int argc, char **argv)
|
||||
int code;
|
||||
int i;
|
||||
|
||||
memset(&bct, 0, sizeof(bct));
|
||||
|
||||
afstest_SkipTestsIfBadHostname();
|
||||
|
||||
plan(134);
|
||||
|
||||
/* Create a temporary afs configuration directory */
|
||||
|
||||
dirname = afstest_BuildTestConfig();
|
||||
bct.skipkeys = 1;
|
||||
dirname = afstest_BuildTestConfig(&bct);
|
||||
|
||||
keyfile = afstest_asprintf("%s/KeyFile", dirname);
|
||||
|
||||
@ -566,7 +570,7 @@ int main(int argc, char **argv)
|
||||
free(keyfile);
|
||||
|
||||
/* Start a new test configuration */
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(&bct);
|
||||
dir = afsconf_Open(dirname);
|
||||
ok(dir != NULL, "Sucessfully opened brand new config directory");
|
||||
if (dir == NULL)
|
||||
|
@ -251,7 +251,7 @@ test_edges(void)
|
||||
char *dirname;
|
||||
|
||||
/* run edge case tests */
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
fprintf(stderr, "Unable to configure directory.\n");
|
||||
@ -268,7 +268,7 @@ test_no_config_files(void)
|
||||
char *dirname;
|
||||
|
||||
/* run tests without config files */
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
fprintf(stderr, "Unable to configure directory.\n");
|
||||
@ -285,7 +285,7 @@ test_with_config_files(void)
|
||||
char *dirname;
|
||||
|
||||
/* run tests with config files */
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
write_krb_conf(dirname, "MY.REALM.ORG MY.OTHER.REALM.ORG");
|
||||
write_krb_excl(dirname);
|
||||
dir = afsconf_Open(dirname);
|
||||
@ -309,7 +309,7 @@ test_set_local_realms(void)
|
||||
ok(afsconf_SetLocalRealm("MY.OTHER.REALM.ORG") == 0, "set local realm MY.OTHER.REALM.ORG");
|
||||
|
||||
/* run tests without config files */
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
fprintf(stderr, "Unable to configure directory.\n");
|
||||
@ -328,7 +328,7 @@ test_update_config_files(void)
|
||||
char *dirname;
|
||||
afs_int32 local = -1;
|
||||
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
write_krb_conf(dirname, "SOME.REALM.ORG");
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
|
@ -399,7 +399,6 @@ int main(int argc, char **argv)
|
||||
struct afsconf_dir *dir;
|
||||
char *dirname;
|
||||
int serverPid, clientPid, waited, stat;
|
||||
int code;
|
||||
int ret = 0;
|
||||
sigset_t set;
|
||||
char *argv0 = afstest_GetProgname(argv);
|
||||
@ -430,7 +429,7 @@ int main(int argc, char **argv)
|
||||
sigaddset(&set, SIGUSR1);
|
||||
opr_Verify(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
|
||||
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
|
||||
dir = afsconf_Open(dirname);
|
||||
if (dir == NULL) {
|
||||
@ -439,13 +438,6 @@ int main(int argc, char **argv)
|
||||
goto out;
|
||||
}
|
||||
|
||||
code = afstest_AddDESKeyFile(dir);
|
||||
if (code) {
|
||||
afs_com_err(argv0, code, "while adding new key\n");
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Config directory is %s\n", dirname);
|
||||
serverPid = fork();
|
||||
if (serverPid == -1) {
|
||||
|
@ -23,8 +23,13 @@ main(int argc, char **argv)
|
||||
char *keyfile = NULL;
|
||||
int in, out;
|
||||
size_t len;
|
||||
struct afstest_configinfo bct;
|
||||
|
||||
dirname = afstest_BuildTestConfig();
|
||||
memset(&bct, 0, sizeof(bct));
|
||||
|
||||
bct.skipkeys = 1;
|
||||
|
||||
dirname = afstest_BuildTestConfig(&bct);
|
||||
if (dirname == NULL) {
|
||||
fprintf(stderr, "Unable to create tmp config dir\n");
|
||||
exit(1);
|
||||
|
@ -23,7 +23,12 @@
|
||||
*/
|
||||
|
||||
/* config.c */
|
||||
extern char *afstest_BuildTestConfig(void);
|
||||
|
||||
struct afstest_configinfo {
|
||||
/* Skip adding keys to the created conf dir. */
|
||||
int skipkeys;
|
||||
};
|
||||
extern char *afstest_BuildTestConfig(struct afstest_configinfo *info);
|
||||
|
||||
struct afsconf_dir;
|
||||
extern int afstest_AddDESKeyFile(struct afsconf_dir *dir);
|
||||
|
@ -51,25 +51,35 @@ openConfigFile(char *dirname, char *filename) {
|
||||
|
||||
/*!
|
||||
* Build a test configuration directory, containing a CellServDB and ThisCell
|
||||
* file for the "example.org" cell
|
||||
* file for the "example.org" cell. Also populates the KeyFile unless
|
||||
* info->skipkeys is set.
|
||||
*
|
||||
* @param[in] info Various details for how to create the config dir. If NULL,
|
||||
* use a default zeroed struct.
|
||||
* @return
|
||||
* The path to the configuration directory. This should be freed by the caller
|
||||
* using free()
|
||||
*
|
||||
*/
|
||||
|
||||
char *
|
||||
afstest_BuildTestConfig(void) {
|
||||
afstest_BuildTestConfig(struct afstest_configinfo *info)
|
||||
{
|
||||
char *dir = NULL;
|
||||
FILE *file;
|
||||
struct afsconf_dir *confdir = NULL;
|
||||
struct afstest_configinfo info_defaults;
|
||||
struct in_addr iaddr;
|
||||
int code;
|
||||
|
||||
memset(&info_defaults, 0, sizeof(info_defaults));
|
||||
memset(&iaddr, 0, sizeof(iaddr));
|
||||
|
||||
if (info == NULL) {
|
||||
info = &info_defaults;
|
||||
}
|
||||
|
||||
dir = afstest_mkdtemp();
|
||||
if (dir == NULL) {
|
||||
goto fail;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Work out which IP address to use in our CellServDB. We figure this out
|
||||
@ -87,11 +97,31 @@ afstest_BuildTestConfig(void) {
|
||||
fprintf(file, "example.org");
|
||||
fclose(file);
|
||||
|
||||
if (!info->skipkeys) {
|
||||
confdir = afsconf_Open(dir);
|
||||
if (confdir == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
code = afstest_AddDESKeyFile(confdir);
|
||||
if (code != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
afsconf_Close(confdir);
|
||||
confdir = NULL;
|
||||
}
|
||||
|
||||
return dir;
|
||||
|
||||
fail:
|
||||
if (dir)
|
||||
error:
|
||||
if (confdir != NULL) {
|
||||
afsconf_Close(confdir);
|
||||
}
|
||||
if (dir != NULL) {
|
||||
afstest_rmdtemp(dir);
|
||||
free(dir);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -96,17 +96,10 @@ main(int argc, char **argv)
|
||||
|
||||
code = rx_Init(0);
|
||||
|
||||
dirname = afstest_BuildTestConfig();
|
||||
dirname = afstest_BuildTestConfig(NULL);
|
||||
|
||||
dir = afsconf_Open(dirname);
|
||||
|
||||
code = afstest_AddDESKeyFile(dir);
|
||||
if (code) {
|
||||
afs_com_err(argv0, code, "while adding test DES keyfile");
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
code = afstest_StartVLServer(dirname, &serverPid);
|
||||
if (code) {
|
||||
afs_com_err(argv0, code, "while starting the vlserver");
|
||||
|
Loading…
Reference in New Issue
Block a user