Windows: remove unused and leaked uniRootFileNameClone
[openafs.git] / tests / auth / keys-t.c
index 2e32946..5c483c5 100644 (file)
@@ -36,7 +36,7 @@
 #include <afs/afsutil.h>
 #include <rx/rxkad.h>
 
-#include <tap/basic.h>
+#include <tests/tap/basic.h>
 
 #include "test.h"
 #include "common.h"
@@ -101,21 +101,34 @@ int main(int argc, char **argv)
     struct afsconf_typedKeyList *typedKeyList;
     char *dirname;
     char *keyfile;
+    char *keyfilesrc;
     afs_int32 kvno;
     int code;
     int i;
 
-    plan(123);
+    afstest_SkipTestsIfBadHostname();
+
+    plan(134);
 
     /* Create a temporary afs configuration directory */
 
-    dirname = buildTestConfig();
+    dirname = afstest_BuildTestConfig();
 
     if (asprintf(&keyfile, "%s/KeyFile", dirname) == -1)
        goto out;
 
+    /* Work out the path to our KeyFile. If the test harness hasn't set
+     * the SOURCE environment variable, then assume it is in our CWD */
+    if (getenv("SOURCE") == NULL) {
+       keyfilesrc = strdup("KeyFile");
+    } else {
+       if (asprintf(&keyfilesrc, "%s/auth/KeyFile", getenv("SOURCE")) == -1)
+           goto out;
+    }
+
     /* First, copy in a known keyfile */
-    code = copy("KeyFile", keyfile);
+    code = copy(keyfilesrc, keyfile);
+    free(keyfilesrc);
     if (code)
        goto out;
 
@@ -527,8 +540,52 @@ int main(int argc, char **argv)
        " ... with the right key in slot 1");
     afsconf_PutTypedKeyList(&typedKeyList);
 
+    /* Check that GetAllKeys works as expected */
+    code = afsconf_GetAllKeys(dir, &typedKeyList);
+    is_int(0, code, "afsconf_GetAllKeys returns success");
+    is_int(5, typedKeyList->nkeys, " ... with the correct number of keys");
+    ok(keyMatches(typedKeyList->keys[0], afsconf_rxkad, 1, 0,
+                 "\x10\x10\x10\x10\x10\x10\x10\x10", 8),
+       " ... with right key in slot 0");
+    ok(keyMatches(typedKeyList->keys[1], afsconf_rxkad, 2, 0,
+                  "\x30\x30\x30\x30\x30\x30\x30\x30", 8),
+       " ... with right key in slot 1");
+    ok(keyMatches(typedKeyList->keys[2], 1, 1, 0, "\x03", 1),
+       " ... with right key in slot 2");
+    ok(keyMatches(typedKeyList->keys[3], 1, 2, 0, "\x01", 1),
+       " ... with right key in slot 3");
+    ok(keyMatches(typedKeyList->keys[4], 1, 2, 1, "\x02\03", 2),
+       " ... with right key in slot 4");
+
+    afsconf_Close(dir);
+
+    afstest_UnlinkTestConfig(dirname);
+    free(dirname);
+    free(keyfile);
+
+    /* Start a new test configuration */
+    dirname = afstest_BuildTestConfig();
+    dir = afsconf_Open(dirname);
+    ok(dir != NULL, "Sucessfully opened brand new config directory");
+    if (dir == NULL)
+       goto out;
+
+    /* Check that directories with just new style keys work */
+    keyMaterial = rx_opaque_new("\x02\x03", 2);
+    typedKey = afsconf_typedKey_new(1, 2, 1, keyMaterial);
+    code = afsconf_AddTypedKey(dir, typedKey, 0);
+    afsconf_typedKey_put(&typedKey);
+    is_int(0, code,
+          "afsconf_AddTypedKey can add keys with different sub type");
+
+    /* Check the GetKeyByTypes returns one of the keys */
+    code = afsconf_GetKeyByTypes(dir, 1, 2, 1, &typedKey);
+    is_int(0, code, "afsconf_GetKeyByTypes returns it");
+    ok(keyMatches(typedKey, 1, 2, 1, "\x02\x03", 2),
+       " ... with the right key");
+
 out:
-    unlinkTestConfig(dirname);
+    afstest_UnlinkTestConfig(dirname);
 
     return 0;
 }