]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - test/00-provider.t
Making a gost provider - Refactor the testing foundation
[openssl-gost/engine.git] / test / 00-provider.t
1 #!/usr/bin/perl 
2 use Test2::V0;
3 skip_all('This test is only suitable for the provider')
4     unless $ARGV[0] eq 'provider';
5 plan(1);
6 use Cwd 'abs_path';
7
8 my $provider = 'gostprov';
9 my $provider_info = <<EOINF;
10 Providers:
11   gostprov
12 EOINF
13
14 # Normally, this test recipe tests the default GOST provider.  However, it's
15 # also possible to test a different provider as well, possibly a custom build.
16 # In that case, use the environment variable PROVIDER_NAME to name it.  This
17 # overrides a few things:
18 #
19 # - if it exists, we get the text that 'openssl provider -c ${PROVIDER_NAME}'
20 #   should print from the file "${PROVIDER_NAME}.info".
21 # - we create an OpenSSL config file for that provider, and use that instead
22 #   of the default.  We do this by overriding the environment variable
23 #   OPENSSL_CONF
24 #
25 # If PROVIDER_NAME isn't set, we rely on an existing OPENSSL_CONF
26 #
27 if ($ENV{'PROVIDER_NAME'}) {
28     $provider=$ENV{'PROVIDER_NAME'};
29
30     if ( -f $provider . ".info") {
31         diag("Reading $provider.info");
32         open my $F, "<", $provider . ".info";
33         read $F,$provider_info,1024;
34         close $F;
35     }
36
37     open my $F,">","$provider.cnf";
38     print $F <<EOCFG;
39 openssl_conf = openssl_def
40 [openssl_def]
41 providers = providers
42 [providers]
43 ${provider}=gost_conf
44 [gost_conf]
45 default_algorithms = ALL
46 EOCFG
47     close $F;
48     $ENV{'OPENSSL_CONF'}=abs_path("$provider.cnf");
49 }
50
51 # Let's check that we can load the provider without config file
52 # Note that this still requires a properly defined OPENSSL_MODULES
53 {
54     local $ENV{'OPENSSL_CONF'}=abs_path("no_such_file.cfg");
55     my $cmd = "openssl list -provider $provider -providers";
56     unless (is(`$cmd`, $provider_info,
57                "load provider without any config")) {
58         diag("Command was: $cmd");
59     }
60 }