Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions .github/workflows/test-installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,43 @@ jobs:
build-target/Installer64/${{ matrix.crt.package }}.msi
if-no-files-found: error

# The upgrade and side-by-side tests need newer installers of this
# project. Build them from the same binaries, stamped as the next patch
# release of the branch and as the first release of the next branch, so
# the tests never depend on what has been published. The action above
# put AdvancedInstaller.com on PATH and registered the license.
- name: Build upgrade test installers
shell: pwsh
run: |
$major = [int]'${{ steps.openssl_version.outputs.major }}'
$minor = [int]'${{ steps.openssl_version.outputs.minor }}'
$patch = [int]('${{ steps.openssl_version.outputs.version }}'.Split('.')[2])
$build = '${{ matrix.crt.msi_build }}'
$commands = @(';aic', 'ResetSig')
foreach ($next in @(
@{ Dir = 'patch'; Minor = $minor; Version = "$major.$minor.$($patch + 1)" },
@{ Dir = 'branch'; Minor = $minor + 1; Version = "$major.$($minor + 1).0" }
)) {
$commands += "SetVersion $($next.Version)"
$commands += "SetProperty VERSION_MAJOR=$major"
$commands += "SetProperty VERSION_MINOR=$($next.Minor)"
$commands += "SetProperty VERSION_REGISTRY=$major.$($next.Minor)-OpenSSLProject"
$commands += "SetOutputLocation -buildname $build -path `"$env:GITHUB_WORKSPACE\upgrade-target\$($next.Dir)`""
$commands += "Build -buildslist $build"
}
$commands | Set-Content -Encoding utf8 "$env:RUNNER_TEMP\upgrade.aic"
AdvancedInstaller.com /execute "$env:GITHUB_WORKSPACE\windows-installer\openssl.aip" "$env:RUNNER_TEMP\upgrade.aic"
if ($LASTEXITCODE -ne 0) { throw "AdvancedInstaller failed with exit code $LASTEXITCODE" }

- name: Upload upgrade test installers
uses: actions/upload-artifact@v4
with:
name: upgrade-test-installers-${{ matrix.crt.arch }}-${{ matrix.crt.flavor }}-${{ matrix.openssl-ref }}
path: |
upgrade-target/patch/${{ matrix.crt.package }}.msi
upgrade-target/branch/${{ matrix.crt.package }}.msi
if-no-files-found: error

test:
name: "Test ${{ matrix.package }}.${{ matrix.format }} on ${{ matrix.os }}${{ inputs.pr && format(' ({0})', matrix.openssl-ref) || '' }}"
needs: [plan, build]
Expand All @@ -341,6 +378,14 @@ jobs:
path: build
merge-multiple: true

- name: Download upgrade test installers
if: matrix.format == 'msi'
uses: actions/download-artifact@v4
with:
pattern: upgrade-test-installers-*-${{ matrix.openssl-ref }}
path: upgrade
merge-multiple: true

- name: Install uv
uses: astral-sh/setup-uv@caf0cab7a618c569241d31dcd442f54681755d39 # v3 (= release v3.2.4)
with:
Expand Down Expand Up @@ -382,8 +427,16 @@ jobs:
"path=$($file.FullName)" >> $env:GITHUB_OUTPUT

- name: Run pytest
env:
# The upgrade test lists openssl/installer releases; unauthenticated
# API calls are limited per IP, which hosted runners share.
GITHUB_TOKEN: ${{ github.token }}
run: uv run pytest tests --installer "${{ steps.installer.outputs.path }}" -v
shell: pwsh
run: |
$pytestArgs = @('tests', '--installer', '${{ steps.installer.outputs.path }}', '-v')
# The upgrade test installers are MSIs; with the EXE the upgrade tests skip.
if ('${{ matrix.format }}' -eq 'msi') {
foreach ($kind in 'patch', 'branch') {
$file = Get-ChildItem "upgrade\$kind" -File | Where-Object { $_.Name -like '${{ matrix.package }}.msi' } | Select-Object -First 1
if (-not $file) { throw "No $kind upgrade test installer matching '${{ matrix.package }}.msi' found in upgrade\$kind" }
$pytestArgs += "--newer-$kind-installer", $file.FullName
}
}
uv run pytest @pytestArgs
exit $LASTEXITCODE
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ markers = [
"signed: requires a signed installer artifact",
"fips: exercises FIPS provider behavior",
"gui: requires an interactive desktop session",
"upgrade: installs the previous published release first (downloaded from GitHub unless --previous-installer)",
"upgrade: installs a second installer of the same project (--newer-patch-installer, --newer-branch-installer; CI builds them from the same binaries) or --previous-installer",
"destructive: temporarily removes system dependencies (e.g., VC++ runtime)",
]
addopts = "-m 'not signed and not destructive'"
Expand Down
165 changes: 109 additions & 56 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,34 @@ def pytest_addoption(parser):
"Basic-auth credentials may be embedded as https://user:token@host/..."
),
)
parser.addoption(
"--newer-patch-installer",
action="store",
default=None,
help=(
"Path or URL of a newer installer of the same release branch, "
"architecture, flavor and type (CI: the same binaries stamped as the "
"next patch release), for the upgrade tests."
),
)
parser.addoption(
"--newer-branch-installer",
action="store",
default=None,
help=(
"Path or URL of an installer of a newer release branch, of the same "
"architecture, flavor and type (CI: the same binaries stamped as the "
"next branch), for the side-by-side test."
),
)
parser.addoption(
"--previous-installer",
action="store",
default=None,
help=(
"Path or URL of an older installer of the same architecture, flavor "
"and type for the upgrade test. Defaults to the newest published "
"openssl/installer release older than --installer."
"Path or URL of an older installer of the same release branch, such as "
"the last published release, to upgrade from instead of upgrading to "
"--newer-patch-installer."
),
)

Expand Down Expand Up @@ -374,69 +394,88 @@ def installer(request, tmp_path_factory) -> InstallerInfo:
return _installer_info(_installer_path(arg), tmp_path_factory)


INSTALLER_RELEASES_API = "https://api.github.com/repos/openssl/installer/releases"

# Release tags name what was published: publish/<openssl-version>-<installer revision>.
_PUBLISH_TAG = re.compile(r"^publish/(\d+\.\d+\.\d+)-(\d+)$")


def _version_key(version: str) -> tuple[int, ...]:
return tuple(int(p) for p in version.split("."))


def _branch(version: str) -> tuple[int, ...]:
"""The release branch of a version: 4.1.1 -> (4, 1)."""
return _version_key(version)[:2]


def artifact_name(info: InstallerInfo, version: str) -> str:
"""The file name of `info`'s architecture, flavor and type at `version`."""
flavor = "VS" if info.flavor == "vs" else "hybridCRT"
return f"OpenSSL-{info.arch}-{flavor}-{version}{info.path.suffix.lower()}"


def _previous_release_asset_url(info: InstallerInfo) -> str:
"""URL of `info`'s counterpart in the newest published release older than
`info`: the highest OpenSSL version below it, and of that, the highest
installer revision. Skips the test when there is no such release or the
release has no matching artifact."""
headers = {"Accept": "application/vnd.github+json"}
# Unauthenticated API calls are limited to 60 an hour per IP, which hosted
# runners share; CI passes its token.
if os.environ.get("GITHUB_TOKEN"):
headers["Authorization"] = f"Bearer {os.environ['GITHUB_TOKEN']}"
try:
resp = requests.get(INSTALLER_RELEASES_API, params={"per_page": 100}, headers=headers, timeout=60)
resp.raise_for_status()
except requests.RequestException as e:
pytest.fail(f"cannot list {INSTALLER_RELEASES_API} ({e}); pass --previous-installer or deselect with -m 'not upgrade'")
def _other_installer(request, installer: InstallerInfo, tmp_path_factory, option: str, fits, relation: str) -> InstallerInfo:
"""The installer passed with `option`, checked to be the same kind as the
installer under test and to satisfy `fits`; skips the test without it."""
arg = request.config.getoption(option)
if not arg:
pytest.skip(f"needs {option}")
other = _installer_info(_installer_path(arg), tmp_path_factory)
if artifact_name(other, installer.version) != installer.path.name:
pytest.exit(f"{option} {other.path.name} is not the same kind of installer as {installer.path.name}", returncode=2)
if not fits(other):
pytest.exit(f"{option} {other.path.name} is not {relation} {installer.path.name}", returncode=2)
return other

candidates = []
for release in resp.json():
m = _PUBLISH_TAG.match(release["tag_name"])
if release["draft"] or release["prerelease"] or not m:
continue
if _version_key(m[1]) < _version_key(info.version):
candidates.append(((_version_key(m[1]), int(m[2])), m[1], release))
if not candidates:
pytest.skip(f"no published installer release older than {info.version}")
_, version, release = max(candidates, key=lambda c: c[0])
name = artifact_name(info, version)
asset = next((a for a in release["assets"] if a["name"] == name), None)
if asset is None:
pytest.skip(f"release {release['tag_name']} has no {name}")
assert asset is not None # pytest.skip above raises; this narrows for mypy
return asset["browser_download_url"]

@pytest.fixture(scope="session")
def newer_patch_installer(request, installer: InstallerInfo, tmp_path_factory) -> InstallerInfo:
"""A newer version of the installer's release branch. CI builds it from the
same binaries, stamped as the next patch release, so the upgrade tests
check exactly this project."""
return _other_installer(
request,
installer,
tmp_path_factory,
"--newer-patch-installer",
lambda o: _branch(o.version) == _branch(installer.version) and _version_key(o.version) > _version_key(installer.version),
"a newer version of the release branch of",
)


@pytest.fixture(scope="session")
def newer_branch_installer(request, installer: InstallerInfo, tmp_path_factory) -> InstallerInfo:
"""An installer of a newer release branch. CI builds it from the same
binaries, stamped as the first release of the next branch."""
return _other_installer(
request,
installer,
tmp_path_factory,
"--newer-branch-installer",
lambda o: _branch(o.version) > _branch(installer.version),
"from a newer release branch than",
)


class UpgradePair(NamedTuple):
old: InstallerInfo # installed first
new: InstallerInfo # installed over it; its binaries are at the installer under test's version


@pytest.fixture(scope="session")
def previous_installer(request, installer: InstallerInfo, tmp_path_factory) -> InstallerInfo:
"""An older installer of the same architecture, flavor and type, for the
upgrade test: --previous-installer, or the previous published release."""
arg = request.config.getoption("--previous-installer") or _previous_release_asset_url(installer)
previous = _installer_info(_installer_path(arg), tmp_path_factory)
if artifact_name(previous, installer.version) != installer.path.name:
pytest.exit(
f"--previous-installer {previous.path.name} is not the same kind of installer as {installer.path.name}", returncode=2
def upgrade_pair(request, installer: InstallerInfo, tmp_path_factory) -> UpgradePair:
"""The two installers of an upgrade within a release branch. By default the
installer under test is upgraded to --newer-patch-installer. With
--previous-installer (a release users may have installed, such as the
last published one), that release is upgraded to the installer under
test instead, which checks compatibility with what is in the field."""
if request.config.getoption("--previous-installer"):
previous = _other_installer(
request,
installer,
tmp_path_factory,
"--previous-installer",
lambda o: _branch(o.version) == _branch(installer.version)
and _version_key(o.version) < _version_key(installer.version),
"an older version of the release branch of",
)
if _version_key(previous.version) >= _version_key(installer.version):
pytest.exit(f"--previous-installer {previous.path.name} is not older than {installer.path.name}", returncode=2)
return previous
return UpgradePair(previous, installer)
return UpgradePair(installer, request.getfixturevalue("newer_patch_installer"))


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -614,6 +653,14 @@ def uninstall(info: InstallerInfo) -> None:
_uninstall_all_openssl_products()


def uninstall_product(version: str) -> None:
"""Uninstall the one installed product at `version`, leaving other release
branches installed."""
codes = [p.code for p in installed_openssl_products() if p.version == version]
assert len(codes) == 1, f"expected one installed product at {version}, found {installed_openssl_products()}"
_msiexec(["/x", codes[0], "/qn"], check=True)


def repair(info: InstallerInfo) -> None:
"""msiexec /fa by product code — Windows Installer reinstalls from its cache."""
products = installed_openssl_products()
Expand Down Expand Up @@ -726,6 +773,16 @@ def check_legacy_provider(install_dir: Path):
)


def fips_enabled_cnf(content: str, install_dir: Path) -> str:
"""openssl.cnf content with the FIPS lines uncommented, as the installer's
text updates do for a FIPS install: include config\\fipsmodule.cnf, load
the fips provider and keep the default provider active."""
fips_inc = f".include {install_dir}\\config\\fipsmodule.cnf"
content = content.replace("# .include fipsmodule.cnf", fips_inc)
content = content.replace("# fips = fips_sect", "fips = fips_sect")
return content.replace("# activate = 1", "activate = 1")


def check_fips_provider(install_dir: Path, expected_fips_version: str):
"""List the FIPS provider using a temporary openssl.cnf.

Expand All @@ -735,11 +792,7 @@ def check_fips_provider(install_dir: Path, expected_fips_version: str):
the installed config in a partially-patched state.
"""
src_cnf = install_dir / "config" / "openssl.cnf"
content = src_cnf.read_text(encoding="utf-8")
fips_inc = f".include {install_dir}\\config\\fipsmodule.cnf"
content = content.replace("# .include fipsmodule.cnf", fips_inc)
content = content.replace("# fips = fips_sect", "fips = fips_sect")
content = content.replace("# activate = 1", "activate = 1")
content = fips_enabled_cnf(src_cnf.read_text(encoding="utf-8"), install_dir)

with tempfile.NamedTemporaryFile(mode="w", suffix=".cnf", delete=False, encoding="utf-8") as tf:
tf.write(content)
Expand Down
12 changes: 10 additions & 2 deletions tests/msi_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Consumed by tests/test_package.py through conftest.msi_package_facts().
#
# Reports what a silent install cannot observe: the platform the package
# declares, the bitness of every component, the upgrade detection rows and the
# feature list the SDK dialog hands to UpdateFeaturesInstallStates.
# declares, the bitness of every component, the upgrade detection rows, the
# launch conditions and the feature list the SDK dialog hands to
# UpdateFeaturesInstallStates.
#
# Driven through reflection (InvokeMember), like msi_query.ps1: that is the
# reliable way to reach MSI's parameterized properties from PowerShell.
Expand Down Expand Up @@ -64,6 +65,12 @@ if (Test-Table $database "Upgrade") {
ForEach-Object { [ordered]@{ action_property = $_[0]; attributes = [int]$_[1]; version_min = $_[2]; version_max = $_[3] } })
}

$launchConditions = @()
if (Test-Table $database "LaunchCondition") {
$launchConditions = @(Get-Rows $database "SELECT ``Condition``, ``Description`` FROM ``LaunchCondition``" |
ForEach-Object { [ordered]@{ condition = $_[0]; description = $_[1] } })
}

$features = @(Get-Rows $database "SELECT ``Feature`` FROM ``Feature``" | ForEach-Object { $_[0] })

$conditions = @()
Expand All @@ -79,6 +86,7 @@ $sdkFeatureLists = @(Get-Rows $database "SELECT ``Argument`` FROM ``ControlEvent
template = $template
components = $components
upgrade = $upgrade
launch_conditions = $launchConditions
features = $features
feature_conditions = $conditions
sdk_next_custom_action_data = $sdkFeatureLists
Expand Down
Loading
Loading