mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Add tests for secret XML parsing
also validate it against the RNG schema.
This commit is contained in:
parent
032f0d5b3d
commit
665344da01
@ -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 \
|
||||
|
10
tests/secretschematest
Executable file
10
tests/secretschematest
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
: ${srcdir=.}
|
||||
. $srcdir/test-lib.sh
|
||||
. $abs_srcdir/schematestutils.sh
|
||||
|
||||
DIRS="secretxml2xmlin"
|
||||
SCHEMA="secret.rng"
|
||||
|
||||
check_schema "$DIRS" "$SCHEMA"
|
7
tests/secretxml2xmlin/ephemeral-usage-volume.xml
Normal file
7
tests/secretxml2xmlin/ephemeral-usage-volume.xml
Normal file
@ -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>
|
7
tests/secretxml2xmlin/usage-ceph.xml
Normal file
7
tests/secretxml2xmlin/usage-ceph.xml
Normal file
@ -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>
|
7
tests/secretxml2xmlin/usage-iscsi.xml
Normal file
7
tests/secretxml2xmlin/usage-iscsi.xml
Normal file
@ -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>
|
7
tests/secretxml2xmlin/usage-volume.xml
Normal file
7
tests/secretxml2xmlin/usage-volume.xml
Normal file
@ -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>
|
98
tests/secretxml2xmltest.c
Normal file
98
tests/secretxml2xmltest.c
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user