Test the storeutl searching options
authorRichard Levitte <levitte@openssl.org>
Mon, 20 Feb 2017 01:49:13 +0000 (02:49 +0100)
committerRichard Levitte <levitte@openssl.org>
Fri, 23 Feb 2018 06:40:42 +0000 (07:40 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2688)

test/recipes/90-test_store.t

index 94f2c1aca648825fcea65d145b1c7957f5c83525..2a6414bd888962c969826ab0d72d4d24ab63229e 100644 (file)
@@ -6,7 +6,7 @@
 # in the file LICENSE in the source distribution or at
 # https://www.openssl.org/source/license.html
 
-use File::Spec;
+use File::Spec::Functions;
 use File::Copy;
 use MIME::Base64;
 use OpenSSL::Test qw(:DEFAULT srctop_file srctop_dir bldtop_file data_file);
@@ -75,7 +75,7 @@ my $n = (3 * scalar @noexist_files)
     + (scalar keys %generated_file_files)
     + (scalar @noexist_file_files)
     + 3
-    + 4;
+    + 11;
 
 plan tests => $n;
 
@@ -84,9 +84,7 @@ indir "store_$$" => sub {
     {
         skip "failed initialisation", $n unless init();
 
-        # test PEM_read_bio_PrivateKey
-        ok(run(app(["openssl", "rsa", "-in", "rsa-key-pkcs8-pbes2-sha256.pem",
-                    "-passin", "pass:password"])));
+        my $rehash = init_rehash();
 
         foreach (@noexist_files) {
             my $file = srctop_file($_);
@@ -153,6 +151,11 @@ indir "store_$$" => sub {
             }
         }
 
+        ok(!run(app(['openssl', 'storeutl',
+                     '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+                     srctop_file('test', 'testx509.pem')])),
+           "Checking that -subject can't be used with a single file");
+
         ok(run(app(['openssl', 'storeutl', '-certs',
                     srctop_file('test', 'testx509.pem')])),
            "Checking that -certs returns 1 object on a certificate file");
@@ -166,6 +169,36 @@ indir "store_$$" => sub {
         ok(run(app(['openssl', 'storeutl', '-crls',
                     srctop_file('test', 'testcrl.pem')])),
            "Checking that -crls returns 1 object on a CRL file");
+
+    SKIP: {
+            skip "failed rehash initialisation", 6 unless $rehash;
+
+            # subject from testx509.pem:
+            # '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert'
+            # issuer from testcrl.pem:
+            # '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority'
+            ok(run(app(['openssl', 'storeutl',
+                        '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+                        catdir(curdir(), 'rehash')])));
+            ok(run(app(['openssl', 'storeutl',
+                        '-subject',
+                        '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+                        catdir(curdir(), 'rehash')])));
+            ok(run(app(['openssl', 'storeutl', '-certs',
+                        '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+                        catdir(curdir(), 'rehash')])));
+            ok(run(app(['openssl', 'storeutl', '-crls',
+                        '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
+                        catdir(curdir(), 'rehash')])));
+            ok(run(app(['openssl', 'storeutl', '-certs',
+                        '-subject',
+                        '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+                        catdir(curdir(), 'rehash')])));
+            ok(run(app(['openssl', 'storeutl', '-crls',
+                        '-subject',
+                        '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
+                        catdir(curdir(), 'rehash')])));
+        }
     }
 }, create => 1, cleanup => 1;
 
@@ -364,6 +397,17 @@ sub init {
            );
 }
 
+sub init_rehash {
+    return (
+            mkdir(catdir(curdir(), 'rehash'))
+            && copy(srctop_file('test', 'testx509.pem'),
+                    catdir(curdir(), 'rehash'))
+            && copy(srctop_file('test', 'testcrl.pem'),
+                    catdir(curdir(), 'rehash'))
+            && run(app(['openssl', 'rehash', catdir(curdir(), 'rehash')]))
+           );
+}
+
 sub runall {
     my ($function, @items) = @_;