[libvirt] [PATCH 0/3] tests: uri: Improve uri testing and add test for urlencoded uris

Peter Krempa (3): tests: uri: Use VIR_TEST_DEBUG instead of VIR_DEBUG tests: uri: Run all test cases on a single URI tests: uri: Add test for urlencoded URIs tests/viruritest.c | 80 +++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) -- 2.21.0

VIR_TEST_DEBUG can be easily made verbose in the tests. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/viruritest.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/viruritest.c b/tests/viruritest.c index ba5db15011..336fffbf0f 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -56,61 +56,61 @@ static int testURIParse(const void *args) goto cleanup; if (STRNEQ(uri->scheme, data->scheme)) { - VIR_DEBUG("Expected scheme '%s', actual '%s'", - data->scheme, uri->scheme); + VIR_TEST_DEBUG("Expected scheme '%s', actual '%s'", + data->scheme, uri->scheme); goto cleanup; } if (STRNEQ(uri->server, data->server)) { - VIR_DEBUG("Expected server '%s', actual '%s'", - data->server, uri->server); + VIR_TEST_DEBUG("Expected server '%s', actual '%s'", + data->server, uri->server); goto cleanup; } if (uri->port != data->port) { - VIR_DEBUG("Expected port '%d', actual '%d'", - data->port, uri->port); + VIR_TEST_DEBUG("Expected port '%d', actual '%d'", + data->port, uri->port); goto cleanup; } if (STRNEQ_NULLABLE(uri->path, data->path)) { - VIR_DEBUG("Expected path '%s', actual '%s'", - data->path, uri->path); + VIR_TEST_DEBUG("Expected path '%s', actual '%s'", + data->path, uri->path); goto cleanup; } if (STRNEQ_NULLABLE(uri->query, data->query)) { - VIR_DEBUG("Expected query '%s', actual '%s'", - data->query, uri->query); + VIR_TEST_DEBUG("Expected query '%s', actual '%s'", + data->query, uri->query); goto cleanup; } if (STRNEQ_NULLABLE(uri->fragment, data->fragment)) { - VIR_DEBUG("Expected fragment '%s', actual '%s'", - data->fragment, uri->fragment); + VIR_TEST_DEBUG("Expected fragment '%s', actual '%s'", + data->fragment, uri->fragment); goto cleanup; } for (i = 0; data->params && data->params[i].name && i < uri->paramsCount; i++) { if (STRNEQ_NULLABLE(data->params[i].name, uri->params[i].name)) { - VIR_DEBUG("Expected param name %zu '%s', actual '%s'", - i, data->params[i].name, uri->params[i].name); + VIR_TEST_DEBUG("Expected param name %zu '%s', actual '%s'", + i, data->params[i].name, uri->params[i].name); goto cleanup; } if (STRNEQ_NULLABLE(data->params[i].value, uri->params[i].value)) { - VIR_DEBUG("Expected param value %zu '%s', actual '%s'", - i, data->params[i].value, uri->params[i].value); + VIR_TEST_DEBUG("Expected param value %zu '%s', actual '%s'", + i, data->params[i].value, uri->params[i].value); goto cleanup; } } if (data->params && data->params[i].name) { - VIR_DEBUG("Missing parameter %zu %s=%s", - i, data->params[i].name, data->params[i].value); + VIR_TEST_DEBUG("Missing parameter %zu %s=%s", + i, data->params[i].name, data->params[i].value); goto cleanup; } if (i != uri->paramsCount) { - VIR_DEBUG("Unexpected parameter %zu %s=%s", - i, uri->params[i].name, uri->params[i].value); + VIR_TEST_DEBUG("Unexpected parameter %zu %s=%s", + i, uri->params[i].name, uri->params[i].value); goto cleanup; } @@ -121,8 +121,8 @@ static int testURIParse(const void *args) goto cleanup; if (STRNEQ(uristr, data->uri_out)) { - VIR_DEBUG("URI did not roundtrip, expect '%s', actual '%s'", - data->uri_out, uristr); + VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'", + data->uri_out, uristr); goto cleanup; } -- 2.21.0

Determine whether the test has failed after running all the cases so that we don't need to rerun it multiple times to see all problems. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/viruritest.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/viruritest.c b/tests/viruritest.c index 336fffbf0f..04c237832d 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -51,6 +51,7 @@ static int testURIParse(const void *args) const struct URIParseData *data = args; char *uristr = NULL; size_t i; + bool fail = false; if (!(uri = virURIParse(data->uri))) goto cleanup; @@ -58,60 +59,62 @@ static int testURIParse(const void *args) if (STRNEQ(uri->scheme, data->scheme)) { VIR_TEST_DEBUG("Expected scheme '%s', actual '%s'", data->scheme, uri->scheme); - goto cleanup; + fail = true; } if (STRNEQ(uri->server, data->server)) { VIR_TEST_DEBUG("Expected server '%s', actual '%s'", data->server, uri->server); - goto cleanup; + fail = true; } if (uri->port != data->port) { VIR_TEST_DEBUG("Expected port '%d', actual '%d'", data->port, uri->port); - goto cleanup; + fail = true; } if (STRNEQ_NULLABLE(uri->path, data->path)) { VIR_TEST_DEBUG("Expected path '%s', actual '%s'", data->path, uri->path); - goto cleanup; + fail = true; } if (STRNEQ_NULLABLE(uri->query, data->query)) { VIR_TEST_DEBUG("Expected query '%s', actual '%s'", data->query, uri->query); - goto cleanup; + fail = true; } if (STRNEQ_NULLABLE(uri->fragment, data->fragment)) { VIR_TEST_DEBUG("Expected fragment '%s', actual '%s'", data->fragment, uri->fragment); - goto cleanup; + fail = true; } for (i = 0; data->params && data->params[i].name && i < uri->paramsCount; i++) { if (STRNEQ_NULLABLE(data->params[i].name, uri->params[i].name)) { VIR_TEST_DEBUG("Expected param name %zu '%s', actual '%s'", i, data->params[i].name, uri->params[i].name); - goto cleanup; + fail = true; } if (STRNEQ_NULLABLE(data->params[i].value, uri->params[i].value)) { VIR_TEST_DEBUG("Expected param value %zu '%s', actual '%s'", i, data->params[i].value, uri->params[i].value); - goto cleanup; + fail = true; } } if (data->params && data->params[i].name) { VIR_TEST_DEBUG("Missing parameter %zu %s=%s", i, data->params[i].name, data->params[i].value); - goto cleanup; + fail = true; } if (i != uri->paramsCount) { - VIR_TEST_DEBUG("Unexpected parameter %zu %s=%s", - i, uri->params[i].name, uri->params[i].value); - goto cleanup; + for (; i < uri->paramsCount; i++) { + VIR_TEST_DEBUG("Unexpected parameter %zu %s=%s", + i, uri->params[i].name, uri->params[i].value); + } + fail = true; } VIR_FREE(uri->query); @@ -123,9 +126,12 @@ static int testURIParse(const void *args) if (STRNEQ(uristr, data->uri_out)) { VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'", data->uri_out, uristr); - goto cleanup; + fail = true; } + if (fail) + goto cleanup; + ret = 0; cleanup: VIR_FREE(uristr); -- 2.21.0

When specifying extra params for spcie TLS verification, it's necessary to pass a weird URI to it. Let's add a test for this case where the TLS string contains a space. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/viruritest.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/viruritest.c b/tests/viruritest.c index 04c237832d..c09e5323bc 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -178,6 +178,14 @@ mymain(void) TEST_PARSE("test://[2001:41c8:1:4fd4::2]:123/system", "test", "2001:41c8:1:4fd4::2", 123, "/system", NULL, NULL, NULL, NULL); TEST_PARSE("gluster+rdma://example.com:1234/gv0/vol.img", "gluster+rdma", "example.com", 1234, "/gv0/vol.img", NULL, NULL, NULL, NULL); + virURIParam spiceparams[] = { + { (char *) "tlsSubject", (char *) "C=XX,L=Testtown,O=Test Company,CN=tester.test", false }, + { NULL, NULL, false }, + }; + TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", + "spice://[3ffe::104]:5900/?tlsSubject=C%3dXX%2cL%3dTesttown%2cO%3dTest%20Company%2cCN%3dtester%2etest", + "spice", "3ffe::104", 5900, "/", "tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", NULL, NULL, spiceparams); + virURIParam params1[] = { { (char*)"foo", (char*)"one", false }, { (char*)"bar", (char*)"two", false }, -- 2.21.0

On Tue, Jun 11, 2019 at 05:43:13PM +0200, Peter Krempa wrote:
Peter Krempa (3): tests: uri: Use VIR_TEST_DEBUG instead of VIR_DEBUG tests: uri: Run all test cases on a single URI tests: uri: Add test for urlencoded URIs
tests/viruritest.c | 80 +++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa