diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2019-09-27 10:22:23 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2019-10-29 14:17:39 +0000 |
commit | 4dde554c6ae2375ce53b24cc535124355c339462 (patch) | |
tree | a60fc6631418823956f1553307f524f1017cbd16 /test | |
parent | 0a4d6c67480a4d2fce514e08d3efe571f2ee99c9 (diff) |
chunk 5 of CMP contribution to OpenSSL
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10036)
Diffstat (limited to 'test')
-rw-r--r-- | test/build.info | 10 | ||||
-rw-r--r-- | test/cmp_asn_test.c | 14 | ||||
-rw-r--r-- | test/cmp_ctx_test.c | 5 | ||||
-rw-r--r-- | test/cmp_hdr_test.c | 468 | ||||
-rw-r--r-- | test/cmp_status_test.c | 111 | ||||
-rw-r--r-- | test/recipes/65-test_cmp_hdr.t | 22 | ||||
-rw-r--r-- | test/recipes/65-test_cmp_status.t | 22 |
7 files changed, 637 insertions, 15 deletions
diff --git a/test/build.info b/test/build.info index f50c2eaa40..7ec9bc9721 100644 --- a/test/build.info +++ b/test/build.info @@ -471,7 +471,7 @@ IF[{- !$disabled{tests} -}] DEPEND[conf_include_test]=../libcrypto libtestutil.a IF[{- !$disabled{cmp} -}] - PROGRAMS{noinst}=cmp_asn_test cmp_ctx_test + PROGRAMS{noinst}=cmp_asn_test cmp_ctx_test cmp_status_test cmp_hdr_test ENDIF SOURCE[cmp_asn_test]=cmp_asn_test.c cmp_testlib.c @@ -482,6 +482,14 @@ IF[{- !$disabled{tests} -}] INCLUDE[cmp_ctx_test]=.. ../include ../apps/include DEPEND[cmp_ctx_test]=../libcrypto.a libtestutil.a + SOURCE[cmp_hdr_test]=cmp_hdr_test.c cmp_testlib.c + INCLUDE[cmp_hdr_test]=.. ../include ../apps/include + DEPEND[cmp_hdr_test]=../libcrypto.a libtestutil.a + + SOURCE[cmp_status_test]=cmp_status_test.c cmp_testlib.c + INCLUDE[cmp_status_test]=.. ../include ../apps/include + DEPEND[cmp_status_test]=../libcrypto.a libtestutil.a + # Internal test programs. These are essentially a collection of internal # test routines. Some of them need to reach internal symbols that aren't # available through the shared library (at least on Linux, Solaris, Windows diff --git a/test/cmp_asn_test.c b/test/cmp_asn_test.c index 70439bf0af..9a224f3a56 100644 --- a/test/cmp_asn_test.c +++ b/test/cmp_asn_test.c @@ -24,21 +24,10 @@ typedef struct test_fixture { static CMP_ASN_TEST_FIXTURE *set_up(const char *const test_case_name) { CMP_ASN_TEST_FIXTURE *fixture; - int setup_ok = 0; - /* Allocate memory owned by the fixture, exit on error */ if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) - goto err; + return NULL; fixture->test_case_name = test_case_name; - setup_ok = 1; - - err: - if (!setup_ok) { -#ifndef OPENSSL_NO_STDIO - ERR_print_errors_fp(stderr); -#endif - exit(EXIT_FAILURE); - } return fixture; } @@ -121,6 +110,7 @@ void cleanup_tests(void) int setup_tests(void) { + RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH); /* ASN.1 related tests */ ADD_TEST(test_cmp_asn1_get_int); ADD_TEST(test_ASN1_OCTET_STRING_set); diff --git a/test/cmp_ctx_test.c b/test/cmp_ctx_test.c index 3c8d75f4e0..d7a3edb140 100644 --- a/test/cmp_ctx_test.c +++ b/test/cmp_ctx_test.c @@ -29,8 +29,9 @@ static OSSL_CMP_CTX_TEST_FIXTURE *set_up(const char *const test_case_name) { OSSL_CMP_CTX_TEST_FIXTURE *fixture; - if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))) - || !TEST_ptr(fixture->ctx = OSSL_CMP_CTX_new())) { + if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) + return NULL; + if (!TEST_ptr(fixture->ctx = OSSL_CMP_CTX_new())) { tear_down(fixture); return NULL; } diff --git a/test/cmp_hdr_test.c b/test/cmp_hdr_test.c new file mode 100644 index 0000000000..4f1b4a5a79 --- /dev/null +++ b/test/cmp_hdr_test.c @@ -0,0 +1,468 @@ +/* + * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright Nokia 2007-2019 + * Copyright Siemens AG 2015-2019 + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "cmp_testlib.h" + +static unsigned char rand_data[OSSL_CMP_TRANSACTIONID_LENGTH]; + +typedef struct test_fixture { + const char *test_case_name; + int expected; + OSSL_CMP_CTX *cmp_ctx; + OSSL_CMP_PKIHEADER *hdr; + +} CMP_HDR_TEST_FIXTURE; + +static void tear_down(CMP_HDR_TEST_FIXTURE *fixture) +{ + OSSL_CMP_PKIHEADER_free(fixture->hdr); + OSSL_CMP_CTX_free(fixture->cmp_ctx); + OPENSSL_free(fixture); +} + +static CMP_HDR_TEST_FIXTURE *set_up(const char *const test_case_name) +{ + CMP_HDR_TEST_FIXTURE *fixture; + + if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) + return NULL; + fixture->test_case_name = test_case_name; + if (!TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new())) + goto err; + if (!TEST_ptr(fixture->hdr = OSSL_CMP_PKIHEADER_new())) + goto err; + return fixture; + + err: + tear_down(fixture); + return NULL; +} + +static int execute_HDR_set_get_pvno_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + int pvno = 77; + + if (!TEST_int_eq(ossl_cmp_hdr_set_pvno(fixture->hdr, pvno), 1)) + return 0; + if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), pvno)) + return 0; + return 1; +} + +static int test_HDR_set_get_pvno(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_set_get_pvno_test, tear_down); + return result; +} + +#define X509_NAME_ADD(n, rd, s) X509_NAME_add_entry_by_txt((n), (rd), \ + MBSTRING_ASC, (unsigned char *)(s), -1, -1, 0) + +static int execute_HDR_get0_senderNonce_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + X509_NAME *sender = X509_NAME_new(); + ASN1_OCTET_STRING *sn; + + if (!TEST_ptr(sender)) + return 0; + + X509_NAME_ADD(sender, "CN", "A common sender name"); + if (!TEST_int_eq(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, sender), + 1)) + return 0; + if (!TEST_int_eq(ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr), + 1)) + return 0; + sn = ossl_cmp_hdr_get0_senderNonce(fixture->hdr); + if (!TEST_int_eq(ASN1_OCTET_STRING_cmp(fixture->cmp_ctx->senderNonce, sn), + 0)) + return 0; + X509_NAME_free(sender); + return 1; +} + +static int test_HDR_get0_senderNonce(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_get0_senderNonce_test, tear_down); + return result; +} + +static int execute_HDR_set1_sender_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + X509_NAME *x509name = X509_NAME_new(); + + if (!TEST_ptr(x509name)) + return 0; + + X509_NAME_ADD(x509name, "CN", "A common sender name"); + if (!TEST_int_eq(ossl_cmp_hdr_set1_sender(fixture->hdr, x509name), 1)) + return 0; + if (!TEST_int_eq(fixture->hdr->sender->type, GEN_DIRNAME)) + return 0; + + if (!TEST_int_eq( + X509_NAME_cmp(fixture->hdr->sender->d.directoryName, x509name), 0)) + return 0; + + X509_NAME_free(x509name); + return 1; +} + +static int test_HDR_set1_sender(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_set1_sender_test, tear_down); + return result; +} + +static int execute_HDR_set1_recipient_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + X509_NAME *x509name = X509_NAME_new(); + + if (!TEST_ptr(x509name)) + return 0; + + X509_NAME_ADD(x509name, "CN", "A common recipient name"); + if (!TEST_int_eq(ossl_cmp_hdr_set1_recipient(fixture->hdr, x509name), 1)) + return 0; + + if (!TEST_int_eq(fixture->hdr->recipient->type, GEN_DIRNAME)) + return 0; + + if (!TEST_int_eq( + X509_NAME_cmp(fixture->hdr->recipient->d.directoryName, x509name),0)) + return 0; + + X509_NAME_free(x509name); + return 1; +} + +static int test_HDR_set1_recipient(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_set1_recipient_test, tear_down); + return result; +} + +static int execute_HDR_update_messageTime_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + struct tm hdrtm; + time_t hdrtime, before, after, now; + + now = time(NULL); + before = mktime(gmtime(&now)); + if (!TEST_true(ossl_cmp_hdr_update_messageTime(fixture->hdr))) + return 0; + if (!TEST_true(ASN1_TIME_to_tm(fixture->hdr->messageTime, &hdrtm))) + return 0; + + hdrtime = mktime(&hdrtm); + if (!TEST_true(before <= hdrtime)) + return 0; + now = time(NULL); + after = mktime(gmtime(&now)); + return TEST_true(hdrtime <= after); +} + +static int test_HDR_update_messageTime(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_update_messageTime_test, tear_down); + return result; +} + +static int execute_HDR_set1_senderKID_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + ASN1_OCTET_STRING* senderKID = ASN1_OCTET_STRING_new(); + + if (!TEST_ptr(senderKID)) + return 0; + + ASN1_OCTET_STRING_set(senderKID, rand_data, sizeof(rand_data)); + if (!TEST_int_eq(ossl_cmp_hdr_set1_senderKID(fixture->hdr, senderKID), 1)) + return 0; + if (!TEST_int_eq( + ASN1_OCTET_STRING_cmp(fixture->hdr->senderKID, senderKID), 0)) + return 0; + + ASN1_OCTET_STRING_free(senderKID); + return 1; +} + +static int test_HDR_set1_senderKID(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_set1_senderKID_test, tear_down); + return result; +} + +static int execute_HDR_push0_freeText_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + ASN1_UTF8STRING* text = ASN1_UTF8STRING_new(); + + if (!TEST_ptr(text)) + return 0; + + if (!ASN1_STRING_set(text, "A free text", -1)) + return 0; + + if (!TEST_int_eq( + ossl_cmp_hdr_push0_freeText(fixture->hdr, text), 1)) + return 0; + if (!TEST_true(text == sk_ASN1_UTF8STRING_value( + fixture->hdr->freeText, 0))) + return 0; + + return 1; +} + +static int test_HDR_push0_freeText(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_push0_freeText_test, tear_down); + return result; +} + +static int execute_HDR_push1_freeText_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + ASN1_UTF8STRING* text = ASN1_UTF8STRING_new(); + + if (!TEST_ptr(text)) + return 0; + + if (!ASN1_STRING_set(text, "A free text", -1)) + return 0; + + if (!TEST_int_eq( + ossl_cmp_hdr_push1_freeText(fixture->hdr, text), 1)) + return 0; + if (!TEST_int_eq(ASN1_STRING_cmp( + sk_ASN1_UTF8STRING_value(fixture->hdr->freeText, 0), text), 0)) + return 0; + + ASN1_UTF8STRING_free(text); + return 1; +} + +static int test_HDR_push1_freeText(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_push1_freeText_test, tear_down); + return result; +} + +static int +execute_HDR_generalInfo_push0_item_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(); + + if (!TEST_ptr(itav)) + return 0; + + if (!TEST_int_eq( + ossl_cmp_hdr_generalInfo_push0_item(fixture->hdr, itav), 1)) + return 0; + if (!TEST_true(itav == sk_OSSL_CMP_ITAV_value( + fixture->hdr->generalInfo, 0))) + return 0; + + return 1; +} + +static int test_HDR_generalInfo_push0_item(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_generalInfo_push0_item_test, tear_down); + return result; +} + +static int +execute_HDR_generalInfo_push1_items_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + const char oid[] = "1.2.3.4"; + char buf[20]; + OSSL_CMP_ITAV *itav; + STACK_OF(OSSL_CMP_ITAV) *itavs = NULL; + ASN1_INTEGER *asn1int = ASN1_INTEGER_new(); + ASN1_TYPE *val = ASN1_TYPE_new(); + + if (!TEST_ptr(asn1int)) + return 0; + + if (!TEST_ptr(val)) + return 0; + + ASN1_INTEGER_set(asn1int, 88); + ASN1_TYPE_set(val, V_ASN1_INTEGER, asn1int); + itav = OSSL_CMP_ITAV_create(OBJ_txt2obj(oid, 1), val); + OSSL_CMP_ITAV_push0_stack_item(&itavs, itav); + + if (!TEST_int_eq( + ossl_cmp_hdr_generalInfo_push1_items(fixture->hdr, itavs), 1)) + return 0; + OBJ_obj2txt(buf, sizeof(buf), OSSL_CMP_ITAV_get0_type( + sk_OSSL_CMP_ITAV_value(fixture->hdr->generalInfo, 0)), 0); + if (!TEST_int_eq(memcmp(oid, buf, sizeof(oid)), 0)) + return 0; + + if (!TEST_int_eq(ASN1_TYPE_cmp(itav->infoValue.other, + OSSL_CMP_ITAV_get0_value( + sk_OSSL_CMP_ITAV_value(fixture->hdr->generalInfo, 0))), 0)) + return 0; + + sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free); + return 1; +} + +static int test_HDR_generalInfo_push1_items(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; + EXECUTE_TEST(execute_HDR_generalInfo_push1_items_test, tear_down); + return result; +} + +static int +execute_HDR_set_and_check_implicitConfirm_test(CMP_HDR_TEST_FIXTURE + * fixture) +{ + return TEST_false(ossl_cmp_hdr_check_implicitConfirm(fixture->hdr)) + && TEST_true(ossl_cmp_hdr_set_implicitConfirm(fixture->hdr)) + && TEST_true(ossl_cmp_hdr_check_implicitConfirm(fixture->hdr)); +} + +static int test_HDR_set_and_check_implicit_confirm(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + EXECUTE_TEST(execute_HDR_set_and_check_implicitConfirm_test, tear_down); + return result; +} + + +static int execute_HDR_init_test(CMP_HDR_TEST_FIXTURE *fixture) +{ + ASN1_OCTET_STRING *header_nonce = NULL; + ASN1_OCTET_STRING *ctx_nonce = NULL; + int res = 0; + + if (!TEST_int_eq(fixture->expected, + ossl_cmp_hdr_init(fixture->cmp_ctx, fixture->hdr))) + goto err; + if (fixture->expected != 0) { + if (!TEST_int_eq(ossl_cmp_hdr_get_pvno(fixture->hdr), OSSL_CMP_PVNO) + || !TEST_true(0 == ASN1_OCTET_STRING_cmp( + ossl_cmp_hdr_get0_senderNonce(fixture->hdr), + fixture->cmp_ctx->senderNonce)) + || !TEST_true(0 == ASN1_OCTET_STRING_cmp( + OSSL_CMP_HDR_get0_transactionID(fixture->hdr), + fixture->cmp_ctx->transactionID))) + goto err; + header_nonce = OSSL_CMP_HDR_get0_recipNonce(fixture->hdr); + ctx_nonce = fixture->cmp_ctx->recipNonce; + if (ctx_nonce != NULL + && (!TEST_ptr(header_nonce) + || !TEST_int_eq(0, ASN1_OCTET_STRING_cmp(header_nonce, + ctx_nonce)))) + goto err; + } + + res = 1; + + err: + return res; +} + +static int test_HDR_init(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + unsigned char ref[CMP_TEST_REFVALUE_LENGTH]; + + fixture->expected = 1; + if (!TEST_int_eq(1, RAND_bytes(ref, sizeof(ref))) + || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, + ref, sizeof(ref)))) { + tear_down(fixture); + fixture = NULL; + } + EXECUTE_TEST(execute_HDR_init_test, tear_down); + return result; +} + +static int test_HDR_init_with_subject(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + X509_NAME *subject = NULL; + + fixture->expected = 1; + if (!TEST_ptr(subject = X509_NAME_new()) + || !TEST_true(X509_NAME_ADD(subject, "CN", "Common Name")) + || !TEST_true(OSSL_CMP_CTX_set1_subjectName(fixture->cmp_ctx, + subject))) { + tear_down(fixture); + fixture = NULL; + } + X509_NAME_free(subject); + EXECUTE_TEST(execute_HDR_init_test, tear_down); + return result; +} + +static int test_HDR_init_no_ref_no_subject(void) +{ + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 0; + EXECUTE_TEST(execute_HDR_init_test, tear_down); + return result; +} + + +void cleanup_tests(void) +{ + return; +} + +int setup_tests(void) +{ + RAND_bytes(rand_data, OSSL_CMP_TRANSACTIONID_LENGTH); + /* Message header tests */ + ADD_TEST(test_HDR_set_get_pvno); + ADD_TEST(test_HDR_get0_senderNonce); + ADD_TEST(test_HDR_set1_sender); + ADD_TEST(test_HDR_set1_recipient); + ADD_TEST(test_HDR_update_messageTime); + ADD_TEST(test_HDR_set1_senderKID); + ADD_TEST(test_HDR_push0_freeText); + /* indirectly tests ossl_cmp_pkifreetext_push_str(): */ + ADD_TEST(test_HDR_push1_freeText); + ADD_TEST(test_HDR_generalInfo_push0_item); + ADD_TEST(test_HDR_generalInfo_push1_items); + ADD_TEST(test_HDR_set_and_check_implicit_confirm); + /* also tests public function OSSL_CMP_HDR_get0_transactionID(): */ + /* also tests public function OSSL_CMP_HDR_get0_recipNonce(): */ + /* also tests internal function ossl_cmp_hdr_get_pvno(): */ + ADD_TEST(test_HDR_init); + ADD_TEST(test_HDR_init_with_subject); + ADD_TEST(test_HDR_init_no_ref_no_subject); + /* TODO make sure that total number of tests (here currently 24) is shown, + also for other cmp_*text.c. Currently the test drivers always show 1. */ + + return 1; +} diff --git a/test/cmp_status_test.c b/test/cmp_status_test.c new file mode 100644 index 0000000000..7311c2e444 --- /dev/null +++ b/test/cmp_status_test.c @@ -0,0 +1,111 @@ +/* + * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright Nokia 2007-2019 + * Copyright Siemens AG 2015-2019 + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include "cmp_testlib.h" + +typedef struct test_fixture { + const char *test_case_name; + int pkistatus; + const char *str; /* Not freed by tear_down */ + const char *text; /* Not freed by tear_down */ + int pkifailure; +} CMP_STATUS_TEST_FIXTURE; + +static CMP_STATUS_TEST_FIXTURE *set_up(const char *const test_case_name) +{ + CMP_STATUS_TEST_FIXTURE *fixture; + + if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture)))) + return NULL; + fixture->test_case_name = test_case_name; + return fixture; +} + +static void tear_down(CMP_STATUS_TEST_FIXTURE *fixture) +{ + OPENSSL_free(fixture); +} + + +/* + * Tests PKIStatusInfo creation and get-functions + */ +static int execute_PKISI_test(CMP_STATUS_TEST_FIXTURE *fixture) +{ + OSSL_CMP_PKISI *si = NULL; + int status; + ASN1_UTF8STRING *statusString = NULL; + int res = 0, i; + + if (!TEST_ptr(si = ossl_cmp_statusinfo_new(fixture->pkistatus, + fixture->pkifailure, + fixture->text))) + goto end; + + status = ossl_cmp_pkisi_get_pkistatus(si); + if (!TEST_int_eq(fixture->pkistatus, status) + || !TEST_str_eq(fixture->str, ossl_cmp_PKIStatus_to_string(status))) + goto end; + + if (!TEST_ptr(statusString = + sk_ASN1_UTF8STRING_value(ossl_cmp_pkisi_get0_statusstring(si), + 0)) + || !TEST_str_eq(fixture->text, (char *)statusString->data)) + goto end; + + if (!TEST_int_eq(fixture->pkifailure, + ossl_cmp_pkisi_get_pkifailureinfo(si))) + goto end; + for (i = 0; i <= OSSL_CMP_PKIFAILUREINFO_MAX; i++) + if (!TEST_int_eq((fixture->pkifailure >> i) & 1, + ossl_cmp_pkisi_pkifailureinfo_check(si, i))) + goto end; + + res = 1; + + end: + OSSL_CMP_PKISI_free(si); + return res; +} + +static int test_PKISI(void) +{ + SETUP_TEST_FIXTURE(CMP_STATUS_TEST_FIXTURE, set_up); + fixture->pkistatus = OSSL_CMP_PKISTATUS_revocationNotification; + fixture->str = "PKIStatus: revocation notification - a revocation of the cert has occurred"; + fixture->text = "this is an additional text describing the failure"; + fixture->pkifailure = OSSL_CMP_CTX_FAILINFO_unsupportedVersion | + OSSL_CMP_CTX_FAILINFO_badDataFormat; + EXECUTE_TEST(execute_PKISI_test, tear_down); + return result; +} + + + +void cleanup_tests(void) +{ + return; +} + +int setup_tests(void) +{ + /*- + * this tests all of: + * ossl_cmp_statusinfo_new() + * ossl_cmp_pkisi_get_pkistatus() + * ossl_cmp_PKIStatus_to_string() + * ossl_cmp_pkisi_get0_statusstring() + * ossl_cmp_pkisi_get_pkifailureinfo() + * ossl_cmp_pkisi_pkifailureinfo_check() + */ + ADD_TEST(test_PKISI); + return 1; +} diff --git a/test/recipes/65-test_cmp_hdr.t b/test/recipes/65-test_cmp_hdr.t new file mode 100644 index 0000000000..e013a6d820 --- /dev/null +++ b/test/recipes/65-test_cmp_hdr.t @@ -0,0 +1,22 @@ +#! /usr/bin/env perl +# Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved. +# Copyright Nokia 2007-2019 +# Copyright Siemens AG 2015-2019 +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +use strict; +use OpenSSL::Test qw/:DEFAULT data_file/; +use OpenSSL::Test::Utils; + +setup("test_cmp_lib"); + +plan skip_all => "This test is not supported in a no-cmp build" + if disabled("cmp"); + +plan tests => 1; + +ok(run(test(["cmp_hdr_test"]))); diff --git a/test/recipes/65-test_cmp_status.t b/test/recipes/65-test_cmp_status.t new file mode 100644 index 0000000000..6a0a0c06b6 --- /dev/null +++ b/test/recipes/65-test_cmp_status.t @@ -0,0 +1,22 @@ +#! /usr/bin/env perl +# Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved. +# Copyright Nokia 2007-2019 +# Copyright Siemens AG 2015-2019 +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +use strict; +use OpenSSL::Test qw/:DEFAULT data_file/; +use OpenSSL::Test::Utils; + +setup("test_cmp_lib"); + +plan skip_all => "This test is not supported in a no-cmp build" + if disabled("cmp"); + +plan tests => 1; + +ok(run(test(["cmp_status_test"]))); |