Skip to content

Commit

Permalink
This is a test for nocache provider behavior
Browse files Browse the repository at this point in the history
A follow-up to openssl#26038
  • Loading branch information
beldmit committed Dec 19, 2024
1 parent c5257fd commit c125395
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/nocache-and-default.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
openssl_conf = openssl_init

# Comment out the next line to ignore configuration errors
config_diagnostics = 1

[openssl_init]
providers = provider_sect

[provider_sect]
test = test_sect
default = default_sect

[test_sect]
module = ../test/p_test.so
activate = true

[default_sect]
activate = true
9 changes: 9 additions & 0 deletions test/p_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,21 @@ static const OSSL_ITEM *p_get_reason_strings(void *_)
return reason_strings;
}

static const OSSL_ALGORITHM *p_query(OSSL_PROVIDER *prov,
int operation_id,
int *no_cache)
{
*no_cache = 1;
return NULL;
}

static const OSSL_DISPATCH p_test_table[] = {
{ OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))p_gettable_params },
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))p_get_params },
{ OSSL_FUNC_PROVIDER_GET_REASON_STRINGS,
(void (*)(void))p_get_reason_strings},
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))p_teardown },
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))p_query },
OSSL_DISPATCH_END
};

Expand Down
34 changes: 34 additions & 0 deletions test/recipes/20-test_nocache.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env perl
# Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved.
#
# 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 warnings;

use OpenSSL::Test qw/:DEFAULT bldtop_file srctop_file bldtop_dir with/;
use OpenSSL::Test::Utils;

setup("test_nocache");

plan tests => 4;

ok(run(app(["openssl", "list", "-mac-algorithms"],
stdout => "listout.txt")),
"List mac algorithms - default configuration");
open DATA, "listout.txt";
my @match = grep /MAC/, <DATA>;
close DATA;
ok(scalar @match > 1 ? 1 : 0, "Several algorithms are listed - default configuration");

$ENV{OPENSSL_CONF} = bldtop_file("test", "nocache-and-default.cnf");
ok(run(app(["openssl", "list", "-mac-algorithms"],
stdout => "listout.txt")),
"List mac algorithms");
open DATA, "listout.txt";
my @match = grep /MAC/, <DATA>;
close DATA;
ok(scalar @match > 1 ? 1 : 0, "Several algorithms are listed - nocache-and-default");

0 comments on commit c125395

Please sign in to comment.