[PATCH 2/2] Add tests for secret XML parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



also validate it against the RNG schema.
---
 tests/Makefile.am                                | 12 ++-
 tests/secretschematest                           | 10 +++
 tests/secretxml2xmlin/ephemeral-usage-volume.xml |  7 ++
 tests/secretxml2xmlin/usage-ceph.xml             |  7 ++
 tests/secretxml2xmlin/usage-iscsi.xml            |  7 ++
 tests/secretxml2xmlin/usage-volume.xml           |  7 ++
 tests/secretxml2xmltest.c                        | 98 ++++++++++++++++++++++++
 7 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100755 tests/secretschematest
 create mode 100644 tests/secretxml2xmlin/ephemeral-usage-volume.xml
 create mode 100644 tests/secretxml2xmlin/usage-ceph.xml
 create mode 100644 tests/secretxml2xmlin/usage-iscsi.xml
 create mode 100644 tests/secretxml2xmlin/usage-volume.xml
 create mode 100644 tests/secretxml2xmltest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0718a69..404c17d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -94,6 +94,7 @@ EXTRA_DIST =		\
 	qemuxml2argvdata \
 	qemuxml2xmloutdata \
 	qemuxmlnsdata \
+	secretxml2xmlin \
 	securityselinuxlabeldata \
 	schematestutils.sh \
 	sexpr2xmldata \
@@ -257,6 +258,8 @@ test_programs += cputest
 
 test_programs += metadatatest
 
+test_programs += secretxml2xmltest
+
 test_scripts = \
 	capabilityschematest \
 	interfaceschematest \
@@ -266,7 +269,8 @@ test_scripts = \
 	domainschematest \
 	nodedevschematest \
 	nwfilterschematest \
-	domainsnapshotschematest
+	domainsnapshotschematest \
+	secretschematest
 
 if WITH_LIBVIRTD
 test_scripts +=				\
@@ -611,6 +615,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
index 0000000..f64d1a3
--- /dev/null
+++ b/tests/secretschematest
@@ -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
index 0000000..e273c57
--- /dev/null
+++ b/tests/secretxml2xmlin/ephemeral-usage-volume.xml
@@ -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
index 0000000..e880293
--- /dev/null
+++ b/tests/secretxml2xmlin/usage-ceph.xml
@@ -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
index 0000000..bfc9472
--- /dev/null
+++ b/tests/secretxml2xmlin/usage-iscsi.xml
@@ -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
index 0000000..e273c57
--- /dev/null
+++ b/tests/secretxml2xmlin/usage-volume.xml
@@ -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
index 0000000..be9ef64
--- /dev/null
+++ b/tests/secretxml2xmltest.c
@@ -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)
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]