Add a unit test to validate the functionality of our reg key lookups

Add a test to check to make sure our registry key lookups work.  note
this test only runs on windows (clearly), but also only if the registry
keys are set via an installer or some other manual process (to be done
in the CI workflow)

Also add workflow steps to set registry keys for testing

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24450)
This commit is contained in:
Neil Horman 2024-06-06 14:39:36 -04:00
parent e6c77f2685
commit 1730918161
2 changed files with 100 additions and 3 deletions

View File

@ -41,7 +41,7 @@ jobs:
- name: config
working-directory: _build
run: |
perl ..\Configure --banner=Configured no-makedepend ${{ matrix.platform.config }}
perl ..\Configure --banner=Configured no-makedepend -DWININSTALLCONTEXT=openssl ${{ matrix.platform.config }}
perl configdata.pm --dump
- name: build
working-directory: _build
@ -51,6 +51,18 @@ jobs:
with:
url: "https://download.sysinternals.com/files/Coreinfo.zip"
target: _build/coreinfo/
- name: Gather openssl version info
working-directory: _build
run: |
echo "OSSL_VERSION=$(apps/openssl.exe version -v | awk '{print $2}' | sed -e's/-.*$//')" >> $GITHUB_ENV
- name: Set registry keys
working-directory: _build
run: |
echo $OSSL_VERSION
reg.exe add HKLM\SOFTWARE\OpenSSL-$OSSL_VERSION-openssl /v OPENSSLDIR /t REG_EXPAND_SZ /d TESTOPENSSLDIR /reg:32
reg.exe add HKLM\SOFTWARE\OpenSSL-$OSSL_VERSION-openssl /v ENGINESDIR /t REG_EXPAND_SZ /d TESTOPENSSLDIR /reg:32
reg.exe add HKLM\SOFTWARE\OpenSSL-$OSSL_VERSION-openssl /v MODULESDIR /t REG_EXPAND_SZ /d TESTOPENSSLDIR /reg:32
reg.exe query HKLM\SOFTWARE\OpenSSL-$OSSL_VERSION-openssl /v OPENSSLDIR /reg:32
- name: get cpu info
working-directory: _build
continue-on-error: true
@ -88,7 +100,7 @@ jobs:
- name: config
working-directory: _build
run: |
perl ..\Configure --banner=Configured enable-demos no-makedepend no-shared no-fips enable-md2 enable-rc5 enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers enable-trace enable-crypto-mdebug VC-WIN64A-masm
perl ..\Configure --banner=Configured enable-demos no-makedepend no-shared no-fips enable-md2 enable-rc5 enable-ssl3 enable-ssl3-method enable-weak-ssl-ciphers enable-trace enable-crypto-mdebug -DWININSTALLCONTEXT=openssl VC-WIN64A-masm
perl configdata.pm --dump
- name: build
working-directory: _build
@ -125,7 +137,7 @@ jobs:
- name: config
working-directory: _build
run: |
perl ..\Configure --banner=Configured enable-demos no-makedepend no-bulk no-deprecated no-fips no-asm no-threads -DOPENSSL_SMALL_FOOTPRINT
perl ..\Configure --banner=Configured enable-demos no-makedepend no-bulk no-deprecated no-fips no-asm no-threads -DOPENSSL_SMALL_FOOTPRINT -DWININSTALLCONTEXT=openssl
perl configdata.pm --dump
- name: build
working-directory: _build

View File

@ -0,0 +1,85 @@
#! /usr/bin/env perl
# Copyright 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 OpenSSL::Test;
use OpenSSL::Test::Utils;
use OpenSSL::Test qw/:DEFAULT bldtop_file data_file srctop_file cmdstr/;
setup("test_windows_registry");
plan skip_all => "Windows registry tests are only available on windows"
if $^O !~ /(MSWin)/;
my $actual;
my $expect;
my @tempout = run(app(["openssl", "version", "-w"]), capture => 1);
my $context = "@tempout";
$context =~ s/^.*: //;
@tempout = run(app(["openssl", "version", "-v"]), capture => 1);
my $version = "@tempout";
$version =~ s/^OpenSSL //;
$version =~ s/-.*\n//;
my $regkey = "HKLM\\SOFTWARE\\OpenSSL-".$version."-".$context;
$regkey =~ s/\n//g;
print "REGKEY IS $regkey\n";
my $exit = run(cmd(["reg.exe", "query", $regkey, "/v", "OPENSSLDIR", "/reg:32"]));
plan skip_all => "Skipping test as registry keys aren't set"
if $exit == 0;
plan tests => 3;
my @expectossldir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "OPENSSLDIR"]), capture => 1);
my @expectengdir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "ENGINESDIR"]), capture => 1);
my @expectmoddir = run(cmd(["reg.exe", "query", $regkey, "/reg:32", "/t", "REG_EXPAND_SZ", "/v", "MODULESDIR"]), capture => 1);
my @osslversion = run(app(["openssl", "version", "-d"]), capture => 1);
print "@osslversion";
$expect = "@expectossldir";
$actual = "@osslversion";
$expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
$expect =~ s/\n//g;
$expect =~ s/.*REG_EXPAND_SZ *//;
$expect =~ s/ .*$//;
$actual =~ s/OPENSSLDIR: *//;
ok(grep(/$expect/,$actual), "Confirming version output for openssldir from registry");
my @osslengineout = run(app(["openssl", "version", "-e"]), capture => 1);
$expect = "@expectengdir";
$actual = "@osslengineout";
$expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
$expect =~ s/\n//g;
$expect =~ s/.*REG_EXPAND_SZ *//;
$expect =~ s/ .*$//;
$actual =~ s/ENGINESDIR: *//;
ok(grep(/$expect/, $actual) == 1, "Confirming version output for enginesdir from registry");
my @osslmoduleout = run(app(["openssl", "version", "-m"]), capture => 1);
$expect = "@expectmoddir";
$actual = "@osslmoduleout";
$expect =~ s/HKEY_LOCAL_MACHINE.*\n*//;
$expect =~ s/\n//g;
$expect =~ s/.*REG_EXPAND_SZ *//;
$expect =~ s/ .*$//;
$actual =~ s/MODULESSDIR: *//;
ok(grep(/$expect/, $actual) == 1, "Confirming version output for modulesdir from registry");