summaryrefslogtreecommitdiff
path: root/trust/test-jks.c
diff options
context:
space:
mode:
Diffstat (limited to 'trust/test-jks.c')
-rw-r--r--trust/test-jks.c58
1 files changed, 54 insertions, 4 deletions
diff --git a/trust/test-jks.c b/trust/test-jks.c
index 4e34478..49f930e 100644
--- a/trust/test-jks.c
+++ b/trust/test-jks.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2011, Collabora Ltd.
- * Copyright (c) 2018, Red Hat Inc.
+ * Copyright (c) 2019, Red Hat Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -46,13 +46,13 @@
#include "pkcs11.h" /* CK_FUNCTION_LIST */
#include "pkcs11x.h" /* CKO_X_CERTIFICATE_EXTENSION */
#include "oid.h" /* P11_OID_EXTENDED_KEY_USAGE */
+#include "parser.h"
#include "test.h" /* p11_test() */
#include <stdarg.h> /* va_list */
#include <stdio.h> /* asprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* memcpy() */
-#include <unistd.h> /* rmdir() */
struct {
CK_FUNCTION_LIST module;
@@ -81,8 +81,7 @@ teardown (void *unused)
{
CK_RV rv;
- if (rmdir (test.directory) < 0)
- assert_not_reached ();
+ p11_test_directory_delete (test.directory);
free (test.directory);
p11_enumerate_cleanup (&test.ex);
@@ -188,9 +187,59 @@ test_file_multiple (void)
ret = p11_extract_jks_cacerts (&test.ex, destination);
assert_num_eq (true, ret);
+ free (destination);
test_check_file (test.directory, "extract.jks", SRCDIR "/trust/fixtures/multiple.jks");
+}
+
+static void
+test_file_duplicated (void)
+{
+ char *destination;
+ p11_parser *parser;
+ p11_array *parsed;
+ CK_ATTRIBUTE *duplicated1;
+ CK_ATTRIBUTE *duplicated2;
+ bool ret;
+
+ parser = p11_parser_new (NULL);
+ assert_ptr_not_null (parser);
+
+ parsed = p11_parser_parsed (parser);
+ assert_ptr_not_null (parsed);
+
+ p11_parser_formats (parser, p11_parser_format_x509, NULL);
+
+ ret = p11_parse_file (parser, SRCDIR "/trust/fixtures/duplicated1.der", NULL,
+ P11_PARSE_FLAG_NONE);
+
+ assert_num_eq (1, parsed->num);
+ duplicated1 = parsed->elem[0];
+ parsed->elem[0] = NULL;
+
+ ret = p11_parse_file (parser, SRCDIR "/trust/fixtures/duplicated2.der", NULL,
+ P11_PARSE_FLAG_NONE);
+
+ assert_num_eq (1, parsed->num);
+ duplicated2 = parsed->elem[0];
+ parsed->elem[0] = NULL;
+
+ p11_parser_free (parser);
+
+ setup_objects (duplicated1, NULL);
+ setup_objects (duplicated2, NULL);
+
+ p11_kit_iter_add_filter (test.ex.iter, certificate_filter, 1);
+ p11_kit_iter_begin_with (test.ex.iter, &test.module, 0, 0);
+
+ if (asprintf (&destination, "%s/%s", test.directory, "extract.jks") < 0)
+ assert_not_reached ();
+
+ ret = p11_extract_jks_cacerts (&test.ex, destination);
+ assert_num_eq (true, ret);
free (destination);
+
+ test_check_file (test.directory, "extract.jks", SRCDIR "/trust/fixtures/duplicated.jks");
}
extern time_t _p11_extract_jks_timestamp;
@@ -205,6 +254,7 @@ main (int argc,
p11_fixture (setup, teardown);
p11_test (test_file_multiple, "/jks/test_file_multiple");
+ p11_test (test_file_duplicated, "/jks/test_file_duplicated");
return p11_test_run (argc, argv);
}