From 8116ff334e80cdc8baa8eba8a86aa08a18d15029 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Fri, 11 Mar 2022 04:22:55 +0000 Subject: [PATCH] Add Firefox Nightly Windows tests Refs https://github.com/namecoin/pkcs11mod/issues/24 --- .cirrus.yml | 16 ++++++ testdata/assert-proxy-log.ps1 | 25 +++++++++ testdata/ci-firefox-tests.ps1 | 91 ++++++++++++++++++++++++++++++++ testdata/try-firefox-connect.ps1 | 35 ++++++++++++ 4 files changed, 167 insertions(+) create mode 100755 testdata/assert-proxy-log.ps1 create mode 100755 testdata/ci-firefox-tests.ps1 create mode 100755 testdata/try-firefox-connect.ps1 diff --git a/.cirrus.yml b/.cirrus.yml index fa2ee22..b736269 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -206,6 +206,22 @@ task: depends_on: - "Compile Go latest linux amd64" +task: + name: "firefox windows" + windows_container: + image: cirrusci/windowsservercore:2019 + cpu: 1 + memory: 1G + install_script: + - choco install firefox-nightly --pre + - curl -o pkcs11mod.tar.gz --location https://api.cirrus-ci.com/v1/artifact/build/%CIRRUS_BUILD_ID%/Compile%%%%20Go%%%%20latest%%%%20windows%%%%20%GOARCH%/binaries/dist/pkcs11mod.tar.gz + - tar -xf pkcs11mod.tar.gz + test_script: + - SET PATH=%PATH%;%cd% + - powershell -ExecutionPolicy Unrestricted -File "testdata/ci-firefox-tests.ps1" + depends_on: + - "Compile Go latest windows amd64" + task: name: "gnutls-cli" container: diff --git a/testdata/assert-proxy-log.ps1 b/testdata/assert-proxy-log.ps1 new file mode 100755 index 0000000..a49223a --- /dev/null +++ b/testdata/assert-proxy-log.ps1 @@ -0,0 +1,25 @@ +param ( + $desired +) + +if ( ("$desired" -ne "present" ) -and ( "$desired" -ne "missing" ) ) { + Write-Host "Invalid DESIRED value; should be present or missing" + exit 1 +} + +if ( Test-Path -Path "$Env:USERPROFILE/pkcs11mod.log" ) { + $result="present" +} +else { + $result="missing" +} + +Remove-Item -Force "$Env:USERPROFILE/pkcs11mod.log" + +if ( "$result" -ne "$desired" ) { + Write-Host "Log test failed" + Write-Host "Got $result, wanted $desired" + exit 1 +} + +exit 0 diff --git a/testdata/ci-firefox-tests.ps1 b/testdata/ci-firefox-tests.ps1 new file mode 100755 index 0000000..f39370a --- /dev/null +++ b/testdata/ci-firefox-tests.ps1 @@ -0,0 +1,91 @@ +Write-Host "===== Default System CKBI =====" + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "www.namecoin.org" -desired "success" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "missing" +If (!$?) { + exit 222 +} + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "untrusted-root.badssl.com" -desired "fail" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "missing" +If (!$?) { + exit 222 +} + +Write-Host "===== Deleted System CKBI =====" + +Move-Item -Path "$Env:CI_MAIN_MODULE" -Destination "$Env:CI_BAK_MODULE" + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "www.namecoin.org" -desired "fail" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "missing" +If (!$?) { + exit 222 +} + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "untrusted-root.badssl.com" -desired "fail" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "missing" +If (!$?) { + exit 222 +} + +# TODO: No env var, -desired "missing" default target + +# TODO: Env var pointing to -desired "missing" target + +Write-Host "===== System CKBI via pkcs11proxy =====" + +$Env:PKCS11PROXY_CKBI_TARGET = "$Env:CI_BAK_MODULE" +Copy-Item libpkcs11proxy.so -Destination "$Env:CI_MAIN_MODULE" + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "www.namecoin.org" -desired "success" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "present" +If (!$?) { + exit 222 +} + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "untrusted-root.badssl.com" -desired "fail" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "present" +If (!$?) { + exit 222 +} + +Write-Host "===== System CKBI via p11proxy =====" + +$Env:P11PROXY_CKBI_TARGET = "$Env:CI_BAK_MODULE" +Copy-Item libp11proxy.so -Destination "$Env:CI_MAIN_MODULE" + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "www.namecoin.org" -desired "success" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "present" +If (!$?) { + exit 222 +} + +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/try-firefox-connect.ps1" -host "untrusted-root.badssl.com" -desired "fail" +If (!$?) { + exit 222 +} +& "powershell" "-ExecutionPolicy" "Unrestricted" "-File" "testdata/assert-proxy-log.ps1" -desired "present" +If (!$?) { + exit 222 +} diff --git a/testdata/try-firefox-connect.ps1 b/testdata/try-firefox-connect.ps1 new file mode 100755 index 0000000..5a2e99d --- /dev/null +++ b/testdata/try-firefox-connect.ps1 @@ -0,0 +1,35 @@ +param ( + $host, + $desired +) + +Write-Host "$host" + +if ( ("$desired" -ne "success" ) -and ( "$desired" -ne "fail" ) ) { + Write-Host "Invalid DESIRED value; should be success or fail" + exit 1 +} + +# Nuke whatever cached state might exist... +Remove-Item -Recurse -Force "%APPDATA%/Mozilla" + +& "C:\Program Files\Firefox Nightly\firefox.exe" --screenshot "https://$host" +Start-Sleep -seconds 10 +Stop-Process -Name "firefox" + +if ( Test-Path -Path "screenshot.png" ) { + $result = "success" +} +else { + $result = "fail" +} + +Remove-Item -Force "screenshot.png" + +if ( "$result" -ne "$desired" ) { + Write-Host "TLS test failed" + Write-Host "Got $result, wanted $desired" + exit 1 +} + +exit 0