2 * Copyright 2007-2020 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Nokia 2007-2019
4 * Copyright Siemens AG 2015-2019
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
12 #include "cmp_testlib.h"
14 DEFINE_STACK_OF(ASN1_UTF8STRING)
16 typedef struct test_fixture {
17 const char *test_case_name;
19 const char *str; /* Not freed by tear_down */
20 const char *text; /* Not freed by tear_down */
22 } CMP_STATUS_TEST_FIXTURE;
24 static CMP_STATUS_TEST_FIXTURE *set_up(const char *const test_case_name)
26 CMP_STATUS_TEST_FIXTURE *fixture;
28 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
30 fixture->test_case_name = test_case_name;
34 static void tear_down(CMP_STATUS_TEST_FIXTURE *fixture)
36 OPENSSL_free(fixture);
41 * Tests PKIStatusInfo creation and get-functions
43 static int execute_PKISI_test(CMP_STATUS_TEST_FIXTURE *fixture)
45 OSSL_CMP_PKISI *si = NULL;
47 ASN1_UTF8STRING *statusString = NULL;
50 if (!TEST_ptr(si = OSSL_CMP_STATUSINFO_new(fixture->pkistatus,
55 status = ossl_cmp_pkisi_get_status(si);
56 if (!TEST_int_eq(fixture->pkistatus, status)
57 || !TEST_str_eq(fixture->str, ossl_cmp_PKIStatus_to_string(status)))
60 if (!TEST_ptr(statusString =
61 sk_ASN1_UTF8STRING_value(ossl_cmp_pkisi_get0_statusString(si),
63 || !TEST_str_eq(fixture->text, (char *)statusString->data))
66 if (!TEST_int_eq(fixture->pkifailure,
67 ossl_cmp_pkisi_get_pkifailureinfo(si)))
69 for (i = 0; i <= OSSL_CMP_PKIFAILUREINFO_MAX; i++)
70 if (!TEST_int_eq((fixture->pkifailure >> i) & 1,
71 ossl_cmp_pkisi_check_pkifailureinfo(si, i)))
77 OSSL_CMP_PKISI_free(si);
81 static int test_PKISI(void)
83 SETUP_TEST_FIXTURE(CMP_STATUS_TEST_FIXTURE, set_up);
84 fixture->pkistatus = OSSL_CMP_PKISTATUS_revocationNotification;
85 fixture->str = "PKIStatus: revocation notification - a revocation of the cert has occurred";
86 fixture->text = "this is an additional text describing the failure";
87 fixture->pkifailure = OSSL_CMP_CTX_FAILINFO_unsupportedVersion |
88 OSSL_CMP_CTX_FAILINFO_badDataFormat;
89 EXECUTE_TEST(execute_PKISI_test, tear_down);
95 void cleanup_tests(void)
100 int setup_tests(void)
104 * OSSL_CMP_STATUSINFO_new()
105 * ossl_cmp_pkisi_get_status()
106 * ossl_cmp_PKIStatus_to_string()
107 * ossl_cmp_pkisi_get0_statusString()
108 * ossl_cmp_pkisi_get_pkifailureinfo()
109 * ossl_cmp_pkisi_check_pkifailureinfo()
111 ADD_TEST(test_PKISI);