Add libctx/provider support to cmp_server_test
authorShane Lontis <shane.lontis@oracle.com>
Thu, 14 May 2020 02:32:44 +0000 (12:32 +1000)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Fri, 21 Aug 2020 07:04:11 +0000 (09:04 +0200)
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
(Merged from https://github.com/openssl/openssl/pull/11808)

test/cmp_server_test.c
test/recipes/65-test_cmp_server.t

index dc52a2515d0dec694e88afe87c8ecb864a903b8e..4b3525d7bdaad8f55829dab3d396309656a4f28d 100644 (file)
@@ -18,6 +18,8 @@ typedef struct test_fixture {
     OSSL_CMP_MSG *req;
 } CMP_SRV_TEST_FIXTURE;
 
+static OPENSSL_CTX *libctx = NULL;
+static OSSL_PROVIDER *default_null_provider = NULL, *provider = NULL;
 static OSSL_CMP_MSG *request = NULL;
 
 static void tear_down(CMP_SRV_TEST_FIXTURE *fixture)
@@ -33,7 +35,7 @@ static CMP_SRV_TEST_FIXTURE *set_up(const char *const test_case_name)
     if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
         return NULL;
     fixture->test_case_name = test_case_name;
-    if (!TEST_ptr(fixture->srv_ctx = OSSL_CMP_SRV_CTX_new(NULL, NULL)))
+    if (!TEST_ptr(fixture->srv_ctx = OSSL_CMP_SRV_CTX_new(libctx, NULL)))
         goto err;
     return fixture;
 
@@ -67,7 +69,7 @@ static int execute_test_handle_request(CMP_SRV_TEST_FIXTURE *fixture)
     OSSL_CMP_ERRORMSGCONTENT *errorContent;
     int res = 0;
 
-    if (!TEST_ptr(client_ctx = OSSL_CMP_CTX_new(NULL, NULL))
+    if (!TEST_ptr(client_ctx = OSSL_CMP_CTX_new(libctx, NULL))
             || !TEST_true(OSSL_CMP_CTX_set_transfer_cb_arg(client_ctx, ctx)))
         goto end;
 
@@ -119,9 +121,16 @@ static int test_handle_request(void)
 void cleanup_tests(void)
 {
     OSSL_CMP_MSG_free(request);
+    OSSL_PROVIDER_unload(default_null_provider);
+    OSSL_PROVIDER_unload(provider);
+    OPENSSL_CTX_free(libctx);
     return;
 }
 
+#define USAGE \
+    "CR_protected_PBM_1234.der module_name [module_conf_file]\n"
+OPT_TEST_DECLARE_USAGE(USAGE)
+
 int setup_tests(void)
 {
     const char *request_f;
@@ -132,10 +141,13 @@ int setup_tests(void)
     }
 
     if (!TEST_ptr(request_f = test_get_argument(0))) {
-        TEST_error("usage: cmp_server_test CR_protected_PBM_1234.der\n");
+        TEST_error("usage: cmp_server_test %s", USAGE);
         return 0;
     }
 
+    if (!test_get_libctx(&libctx, &default_null_provider, &provider, 1, USAGE))
+        return 0;
+
     if (!TEST_ptr(request = load_pkimsg(request_f))) {
         cleanup_tests();
         return 0;
index 87dbdb10b26f3e9ea582065a5c9adff7c3f572d5..5864163f016f3b5797de0d6c11a30f7eb661b457 100644 (file)
@@ -9,10 +9,18 @@
 # https://www.openssl.org/source/license.html
 
 use strict;
-use OpenSSL::Test qw/:DEFAULT data_file/;
+use OpenSSL::Test qw/:DEFAULT data_file srctop_file srctop_dir bldtop_file bldtop_dir/;
 use OpenSSL::Test::Utils;
 
-setup("test_cmp_server");
+BEGIN {
+    setup("test_cmp_server");
+}
+
+use lib srctop_dir('Configurations');
+use lib bldtop_dir('.');
+use platform;
+
+my $no_fips = disabled('fips') || ($ENV{NO_FIPS} // 0);
 
 plan skip_all => "This test is not supported in a no-cmp build"
     if disabled("cmp");
@@ -20,7 +28,19 @@ plan skip_all => "This test is not supported in a no-cmp build"
 plan skip_all => "This test is not supported in a no-ec build"
     if disabled("ec");
 
-plan tests => 1;
+plan tests => 2 + ($no_fips ? 0 : 2); #fips install + fips test
+
+my @basic_cmd = ("cmp_server_test", data_file("CR_protected_PBM_1234.der"));
+
+ok(run(test([@basic_cmd, "none"])));
+
+ok(run(test([@basic_cmd, "default", srctop_file("test", "default.cnf")])));
+
+unless ($no_fips) {
+    ok(run(app(['openssl', 'fipsinstall',
+                '-out', bldtop_file('providers', 'fipsmodule.cnf'),
+                '-module', bldtop_file('providers', platform->dso('fips'))])),
+       "fipsinstall");
 
-ok(run(test(["cmp_server_test",
-             data_file("CR_protected_PBM_1234.der")])));
+    ok(run(test([@basic_cmd, "fips", srctop_file("test", "fips.cnf")])));
+}