From 6fb74150b8c8f957e96fd423beeccd36cf04e1bc Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 23 Dec 2014 09:09:17 +0200 Subject: Added test for pin-value https://bugs.freedesktop.org/show_bug.cgi?id=87582 Signed-off-by: Stef Walter * Added test for bad encoded pin-value in uri --- p11-kit/test-uri.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/p11-kit/test-uri.c b/p11-kit/test-uri.c index 673ef4a..e2817b4 100644 --- a/p11-kit/test-uri.c +++ b/p11-kit/test-uri.c @@ -1237,6 +1237,7 @@ test_uri_get_set_attributes (void) p11_kit_uri_free (uri); } + static void test_uri_pin_source (void) { @@ -1275,6 +1276,57 @@ test_uri_pin_source (void) p11_kit_uri_free (uri); } + +static void +test_uri_pin_value (void) +{ + P11KitUri *uri; + const char *pin_value; + char *string; + int ret; + + uri = p11_kit_uri_new (); + assert_ptr_not_null (uri); + + p11_kit_uri_set_pin_value (uri, "123456"); + + pin_value = p11_kit_uri_get_pin_value (uri); + assert_str_eq ("123456", pin_value); + + p11_kit_uri_set_pin_value (uri, "1*&#%&@("); + + pin_value = p11_kit_uri_get_pin_value (uri); + assert_str_eq ("1*&#%&@(", pin_value); + + ret = p11_kit_uri_format (uri, P11_KIT_URI_FOR_ANY, &string); + assert_num_eq (P11_KIT_URI_OK, ret); + assert (strstr (string, "pkcs11:pin-value=1%2a%26%23%25%26%40%28") != NULL); + free (string); + + ret = p11_kit_uri_parse ("pkcs11:pin-value=blah%2Fblah", P11_KIT_URI_FOR_ANY, uri); + assert_num_eq (P11_KIT_URI_OK, ret); + + pin_value = p11_kit_uri_get_pin_value (uri); + assert_str_eq ("blah/blah", pin_value); + + p11_kit_uri_free (uri); +} + +static void +test_uri_pin_value_bad (void) +{ + P11KitUri *uri; + int ret; + + uri = p11_kit_uri_new (); + assert_ptr_not_null (uri); + + ret = p11_kit_uri_parse ("pkcs11:pin-value=blahblah%2", P11_KIT_URI_FOR_ANY, uri); + assert_num_eq (P11_KIT_URI_BAD_ENCODING, ret); + + p11_kit_uri_free (uri); +} + static void test_uri_free_null (void) { @@ -1334,6 +1386,8 @@ main (int argc, p11_test (test_uri_get_set_attribute, "/uri/test_uri_get_set_attribute"); p11_test (test_uri_get_set_attributes, "/uri/test_uri_get_set_attributes"); p11_test (test_uri_pin_source, "/uri/test_uri_pin_source"); + p11_test (test_uri_pin_value, "/uri/pin-value"); + p11_test (test_uri_pin_value_bad, "/uri/pin-value-bad"); p11_test (test_uri_free_null, "/uri/test_uri_free_null"); p11_test (test_uri_message, "/uri/test_uri_message"); -- cgit v1.1