]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add tests for secret XML parsing
authorJán Tomko <jtomko@redhat.com>
Fri, 14 Feb 2014 14:44:59 +0000 (15:44 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 14 Feb 2014 15:47:14 +0000 (16:47 +0100)
also validate it against the RNG schema.

tests/Makefile.am
tests/secretschematest [new file with mode: 0755]
tests/secretxml2xmlin/ephemeral-usage-volume.xml [new file with mode: 0644]
tests/secretxml2xmlin/usage-ceph.xml [new file with mode: 0644]
tests/secretxml2xmlin/usage-iscsi.xml [new file with mode: 0644]
tests/secretxml2xmlin/usage-volume.xml [new file with mode: 0644]
tests/secretxml2xmltest.c [new file with mode: 0644]

index 9bb61ca7091ade8c04407a8eec8b07a824dfd38f..0c72cc2489061769c9ef3503873b4d069a3bb181 100644 (file)
@@ -95,6 +95,7 @@ EXTRA_DIST =          \
        qemuxml2argvdata \
        qemuxml2xmloutdata \
        qemuxmlnsdata \
+       secretxml2xmlin \
        securityselinuxlabeldata \
        schematestutils.sh \
        sexpr2xmldata \
@@ -258,6 +259,8 @@ test_programs += cputest
 
 test_programs += metadatatest
 
+test_programs += secretxml2xmltest
+
 test_scripts = \
        capabilityschematest \
        interfaceschematest \
@@ -267,7 +270,8 @@ test_scripts = \
        domainschematest \
        nodedevschematest \
        nwfilterschematest \
-       domainsnapshotschematest
+       domainsnapshotschematest \
+       secretschematest
 
 if WITH_LIBVIRTD
 test_scripts +=                                \
@@ -612,6 +616,12 @@ nwfilterxml2xmltest_SOURCES = \
        testutils.c testutils.h
 nwfilterxml2xmltest_LDADD = $(LDADDS)
 
+secretxml2xmltest_SOURCES = \
+       secretxml2xmltest.c \
+       testutils.c testutils.h
+secretxml2xmltest_LDADD = $(LDADDS)
+
+
 if WITH_STORAGE
 storagevolxml2argvtest_SOURCES = \
     storagevolxml2argvtest.c \
diff --git a/tests/secretschematest b/tests/secretschematest
new file mode 100755 (executable)
index 0000000..f64d1a3
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+. $abs_srcdir/schematestutils.sh
+
+DIRS="secretxml2xmlin"
+SCHEMA="secret.rng"
+
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/secretxml2xmlin/ephemeral-usage-volume.xml b/tests/secretxml2xmlin/ephemeral-usage-volume.xml
new file mode 100644 (file)
index 0000000..e273c57
--- /dev/null
@@ -0,0 +1,7 @@
+<secret ephemeral='yes' private='yes'>
+  <uuid>22e1353d-c27e-4d6d-bf15-465053e6ba0b</uuid>
+  <description>Ephemeral Private Secret</description>
+  <usage type='volume'>
+    <volume>/var/lib/libvirt/images/image.img</volume>
+  </usage>
+</secret>
diff --git a/tests/secretxml2xmlin/usage-ceph.xml b/tests/secretxml2xmlin/usage-ceph.xml
new file mode 100644 (file)
index 0000000..e880293
--- /dev/null
@@ -0,0 +1,7 @@
+<secret ephemeral='no' private='yes'>
+  <uuid>f52a81b2-424e-490c-823d-6bd4235bc572</uuid>
+  <description>Ceph secret</description>
+  <usage type='ceph'>
+    <name>CephCephCephCeph</name>
+  </usage>
+</secret>
diff --git a/tests/secretxml2xmlin/usage-iscsi.xml b/tests/secretxml2xmlin/usage-iscsi.xml
new file mode 100644 (file)
index 0000000..bfc9472
--- /dev/null
@@ -0,0 +1,7 @@
+<secret ephemeral='no' private='yes'>
+  <uuid>27f25d34-aea6-4e2a-be85-fa2c18380be8</uuid>
+  <description>iSCSI secret</description>
+  <usage type='iscsi'>
+    <target>iscsitarget</target>
+  </usage>
+</secret>
diff --git a/tests/secretxml2xmlin/usage-volume.xml b/tests/secretxml2xmlin/usage-volume.xml
new file mode 100644 (file)
index 0000000..e273c57
--- /dev/null
@@ -0,0 +1,7 @@
+<secret ephemeral='yes' private='yes'>
+  <uuid>22e1353d-c27e-4d6d-bf15-465053e6ba0b</uuid>
+  <description>Ephemeral Private Secret</description>
+  <usage type='volume'>
+    <volume>/var/lib/libvirt/images/image.img</volume>
+  </usage>
+</secret>
diff --git a/tests/secretxml2xmltest.c b/tests/secretxml2xmltest.c
new file mode 100644 (file)
index 0000000..be9ef64
--- /dev/null
@@ -0,0 +1,98 @@
+#include <config.h>
+
+#include <stdlib.h>
+
+#include "internal.h"
+#include "testutils.h"
+#include "secret_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+    char *inXmlData = NULL;
+    char *outXmlData = NULL;
+    char *actual = NULL;
+    int ret = -1;
+    virSecretDefPtr secret = NULL;
+
+    if (virtTestLoadFile(inxml, &inXmlData) < 0)
+        goto fail;
+    if (virtTestLoadFile(outxml, &outXmlData) < 0)
+        goto fail;
+
+    if (!(secret = virSecretDefParseString(inXmlData)))
+        goto fail;
+
+    if (!(actual = virSecretDefFormat(secret)))
+        goto fail;
+
+    if (STRNEQ(outXmlData, actual)) {
+        virtTestDifference(stderr, outXmlData, actual);
+        goto fail;
+    }
+
+    ret = 0;
+
+fail:
+    VIR_FREE(inXmlData);
+    VIR_FREE(outXmlData);
+    VIR_FREE(actual);
+    virSecretDefFree(secret);
+    return ret;
+}
+
+struct testInfo {
+    const char *name;
+    bool different;
+};
+
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+    int result = -1;
+    char *inxml = NULL;
+    char *outxml = NULL;
+    const struct testInfo *info = data;
+
+    if (virAsprintf(&inxml, "%s/secretxml2xmlin/%s.xml",
+                    abs_srcdir, info->name) < 0 ||
+        virAsprintf(&outxml, "%s/secretxml2xml%s/%s.xml",
+                    abs_srcdir,
+                    info->different ? "out" : "in",
+                    info->name) < 0) {
+        goto cleanup;
+    }
+
+    result = testCompareXMLToXMLFiles(inxml, outxml);
+
+cleanup:
+    VIR_FREE(inxml);
+    VIR_FREE(outxml);
+
+    return result;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+#define DO_TEST(name)                                           \
+    do {                                                        \
+        const struct testInfo info = {name, false};             \
+        if (virtTestRun("Secret XML->XML " name,                \
+                        testCompareXMLToXMLHelper, &info) < 0)  \
+            ret = -1;                                           \
+    } while (0)
+
+    DO_TEST("ephemeral-usage-volume");
+    DO_TEST("usage-volume");
+    DO_TEST("usage-ceph");
+    DO_TEST("usage-iscsi");
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)