Home | History | Annotate | Line # | Download | only in recipes
      1 #! /usr/bin/env perl
      2 # Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
      3 #
      4 # Licensed under the Apache License 2.0 (the "License").  You may not use
      5 # this file except in compliance with the License.  You can obtain a copy
      6 # in the file LICENSE in the source distribution or at
      7 # https://www.openssl.org/source/license.html
      8 
      9 
     10 use OpenSSL::Test;
     11 use OpenSSL::Test::Utils;
     12 use OpenSSL::Test qw/:DEFAULT bldtop_file data_file srctop_file cmdstr/;
     13 
     14 setup("test_windows_registry");
     15 
     16 plan skip_all => "Windows registry tests are only available on windows"
     17     if $^O !~ /(MSWin)/;
     18 
     19 my $actual;
     20 my $expect;
     21 
     22 my @tempout = run(app(["openssl", "version", "-w"]), capture => 1);
     23 my $context = "@tempout";
     24 $context =~ s/^.*: //;
     25 
     26 
     27 @tempout = run(app(["openssl", "version", "-v"]), capture => 1);
     28 my $version = "@tempout";
     29 $version =~ s/^OpenSSL //;
     30 $version =~ s/(^[0-9]+\.[0-9]+)(.*$)/\1/;
     31 
     32 my $regkey = "HKLM\\SOFTWARE\\OpenSSL-".$version."-".$context;
     33 $regkey =~ s/\n//g;
     34 print "REGKEY IS $regkey\n";
     35 
     36 my $exit = run(cmd(["reg.exe", "query", $regkey, "/v", "OPENSSLDIR", "/reg:32"]));
     37 
     38 plan skip_all => "Skipping test as registry keys aren't set"
     39     if $exit == 0;
     40 
     41 plan tests => 3;
     42 
     43 my @expectossldir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "OPENSSLDIR"]), capture => 1);
     44 
     45 my @expectengdir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "ENGINESDIR"]), capture => 1);
     46 
     47 my @expectmoddir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "MODULESDIR"]), capture => 1);
     48 
     49 my @ossldir = run(app(["openssl", "version", "-d"]), capture => 1);
     50 
     51 print "@ossldir";
     52 $expect = "@expectossldir";
     53 $actual = "@ossldir";
     54 $expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
     55 $expect =~ s/\n//g;
     56 $expect =~ s/.*REG_EXPAND_SZ *//;
     57 $expect =~ s/ .*$//;
     58 $actual =~ s/OPENSSLDIR: *//;
     59 
     60 ok(grep(/$expect/,$actual), "Confirming version output for openssldir from registry");
     61 
     62 my @osslengineout = run(app(["openssl", "version", "-e"]), capture => 1);
     63 
     64 $expect = "@expectengdir";
     65 $actual = "@osslengineout";
     66 $expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
     67 $expect =~ s/\n//g;
     68 $expect =~ s/.*REG_EXPAND_SZ *//;
     69 $expect =~ s/ .*$//;
     70 $actual =~ s/ENGINESDIR: *//;
     71 
     72 ok(grep(/$expect/, $actual) == 1, "Confirming version output for enginesdir from registry");
     73 
     74 my @osslmoduleout = run(app(["openssl", "version", "-m"]), capture => 1);
     75 
     76 $expect = "@expectmoddir";
     77 $actual = "@osslmoduleout";
     78 $expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
     79 $expect =~ s/\n//g;
     80 $expect =~ s/.*REG_EXPAND_SZ *//;
     81 $expect =~ s/ .*$//;
     82 $actual =~ s/MODULESSDIR: *//;
     83 ok(grep(/$expect/, $actual) == 1, "Confirming version output for modulesdir from registry");
     84