2 * Copyright 2007-2019 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 typedef struct test_fixture
{
15 const char *test_case_name
;
17 const char *str
; /* Not freed by tear_down */
18 const char *text
; /* Not freed by tear_down */
20 } CMP_STATUS_TEST_FIXTURE
;
22 static CMP_STATUS_TEST_FIXTURE
*set_up(const char *const test_case_name
)
24 CMP_STATUS_TEST_FIXTURE
*fixture
;
26 if (!TEST_ptr(fixture
= OPENSSL_zalloc(sizeof(*fixture
))))
28 fixture
->test_case_name
= test_case_name
;
32 static void tear_down(CMP_STATUS_TEST_FIXTURE
*fixture
)
34 OPENSSL_free(fixture
);
39 * Tests PKIStatusInfo creation and get-functions
41 static int execute_PKISI_test(CMP_STATUS_TEST_FIXTURE
*fixture
)
43 OSSL_CMP_PKISI
*si
= NULL
;
45 ASN1_UTF8STRING
*statusString
= NULL
;
48 if (!TEST_ptr(si
= OSSL_CMP_STATUSINFO_new(fixture
->pkistatus
,
53 status
= ossl_cmp_pkisi_get_status(si
);
54 if (!TEST_int_eq(fixture
->pkistatus
, status
)
55 || !TEST_str_eq(fixture
->str
, ossl_cmp_PKIStatus_to_string(status
)))
58 if (!TEST_ptr(statusString
=
59 sk_ASN1_UTF8STRING_value(ossl_cmp_pkisi_get0_statusString(si
),
61 || !TEST_str_eq(fixture
->text
, (char *)statusString
->data
))
64 if (!TEST_int_eq(fixture
->pkifailure
,
65 ossl_cmp_pkisi_get_pkifailureinfo(si
)))
67 for (i
= 0; i
<= OSSL_CMP_PKIFAILUREINFO_MAX
; i
++)
68 if (!TEST_int_eq((fixture
->pkifailure
>> i
) & 1,
69 ossl_cmp_pkisi_check_pkifailureinfo(si
, i
)))
75 OSSL_CMP_PKISI_free(si
);
79 static int test_PKISI(void)
81 SETUP_TEST_FIXTURE(CMP_STATUS_TEST_FIXTURE
, set_up
);
82 fixture
->pkistatus
= OSSL_CMP_PKISTATUS_revocationNotification
;
83 fixture
->str
= "PKIStatus: revocation notification - a revocation of the cert has occurred";
84 fixture
->text
= "this is an additional text describing the failure";
85 fixture
->pkifailure
= OSSL_CMP_CTX_FAILINFO_unsupportedVersion
|
86 OSSL_CMP_CTX_FAILINFO_badDataFormat
;
87 EXECUTE_TEST(execute_PKISI_test
, tear_down
);
93 void cleanup_tests(void)
102 * OSSL_CMP_STATUSINFO_new()
103 * ossl_cmp_pkisi_get_status()
104 * ossl_cmp_PKIStatus_to_string()
105 * ossl_cmp_pkisi_get0_statusString()
106 * ossl_cmp_pkisi_get_pkifailureinfo()
107 * ossl_cmp_pkisi_check_pkifailureinfo()
109 ADD_TEST(test_PKISI
);