forked from cisagov/ScubaGear
-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (193 loc) · 7.4 KB
/
test_production_function.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Purpose: Run the product functional tests every night
# The testing params are stored as a string in a CSV-like format.
# Pipes separate products, and commas separate key/value pairs.
# key1=value1,key2=value2|key3=value3,key4=value4...
name: Nightly Product Functional Tests
# Run this workflow at 12:15 am
# on every Sun to Thr (b/c GMT -5)
on:
schedule:
- cron: "15 4 * * 0-4"
workflow_dispatch:
jobs:
# Build a matrix of aliases for testing.
build-matrix:
name: Build Matrix
runs-on: windows-latest
defaults:
run:
shell: powershell
steps:
- name: Checkout Repo
uses: actions/checkout@v4
# This job parses out the aliases and puts them in an array
# that will be used as a matrix for testing each product combination.
- name: Generate Matrix
id: generate-matrix
run: |
$params = $env:TestParams
# Powershell doesn't build arrays in the format that a matrix
# wants, so this builds it using a string instead. It's ugly.
$aliases = "["
# Split into products
$products = $params.split("|")
foreach ($product in $products)
{
$attributes = $product.split(",")
foreach ($attribute in $attributes)
{
# Split the key from the value
$keyAndValue = $attribute.split("=")
$key = $keyAndValue[0]
$value = $keyAndValue[1]
if($key.ToLower() -eq "alias")
{
echo "Testing the following alias: $value"
$aliases += '"'
$aliases += $value.Trim()
$aliases += '",'
}
}
}
$aliases = $aliases.Substring(0, $aliases.Length-1)
$aliases += "]"
echo $aliases
echo aliases=$aliases >> $env:GITHUB_OUTPUT
env:
TestParams: ${{ secrets.NIGHTLY_TEST_BUILD_PARAMS }}
outputs:
aliases: ${{ steps.generate-matrix.outputs.aliases }}
# Use ScubaGear to test each service.
# This job runs once per alias in the matrix.
test-products:
name: Test
runs-on: windows-latest
defaults:
run:
shell: powershell
needs:
- build-matrix
strategy:
fail-fast: false
matrix:
# Each item in the matrix is one alias and thus should cause
# one step in this job. This should make it easier to debug
# when a product is failing the functional tests.
product: ${{ fromJson(needs.build-matrix.outputs.aliases) }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Create PFX
run: |
New-Item -ItemType file -Path ./key.txt
Set-Content -Path ./key.txt -Value $env:PfxBase64
certutil -decode ./key.txt ./key.pfx
env:
PfxBase64: ${{ secrets.NIGHTLY_TEST_BUILD_PFX }}
- name: Import PFX
# Pipe to Out-Null to hide the thumbprint
run: Import-PfxCertificate -Password (ConvertTo-SecureString -String $env:PfxPassword -AsPlainText -Force) -CertStoreLocation Cert:\CurrentUser\My -FilePath ./key.pfx | Out-Null
env:
PfxPassword: ${{ secrets.NIGHTLY_TEST_BUILD_PW }}
- name: Get Thumbprint
id: get-thumbprint
run: |
$x509 = Get-PfxCertificate -FilePath ./key.pfx -Password (ConvertTo-SecureString -String $env:PfxPassword -AsPlainText -Force)
$Thumbprint = $x509.ThumbPrint
# Pass thumbprint to later job.
echo thumbprint=$Thumbprint >> $env:GITHUB_OUTPUT
shell: pwsh # -Password flag requires PS 6+
env:
PfxPassword: ${{ secrets.NIGHTLY_TEST_BUILD_PW }}
# Selenium is an interface that allows for
# the programmatic control of web browsers
- name: Install Selenium & Update Webdriver
run: |
Install-Module -Name Selenium -Scope CurrentUser -Force
Import-Module -Name Selenium
./Testing/Functional/SmokeTest/UpdateSelenium.ps1
# Import-Module -Name .\PowerShell\ScubaGear\ScubaGear.psd1
Import-Module -Name .\PowerShell\ScubaGear
Initialize-SCuBA
# Workaround for Selenium. Loading psm1 instead of psd1
Import-Module -Name (Get-Module -Name Selenium -ListAvailable).Path -Force
- name: Test Product
id: test-product
run: |
# Read thumbprint from previous step.
$thumbprint = "${{ steps.get-thumbprint.outputs.thumbprint }}"
echo "Product alias is: ${{ matrix.product }}"
$params = $env:TestParams
# Split into products
$products = $params.split("|")
foreach ($product in $products)
{
[String]$alias = ""
[String]$domain = ""
[String]$display = ""
[String]$appid = ""
[String]$productname = ""
[String]$variant = ""
[String]$m365 = ""
$paramsAsHashTable = @{}
$attributes = $product.split(",")
foreach ($attribute in $attributes)
{
# Split the key from the value
$keyAndValue = $attribute.split("=")
$key = $keyAndValue[0]
$value = $keyAndValue[1]
if($key.ToLower() -eq "alias")
{
$alias = $value
}
elseif($key.ToLower() -eq "tenantdomain")
{
$domain = $attribute
}
elseif($key.ToLower() -eq "tenantdisplayname")
{
$display = $attribute
}
elseif($key.ToLower() -eq "appid")
{
$appid = $attribute
}
elseif($key.ToLower() -eq "productname")
{
$productname = $attribute
}
elseif($key.ToLower() -eq "variant")
{
$variant = $attribute
}
elseif($key.ToLower() -eq "m365environment")
{
$m365 = $attribute
}
}
if($alias -eq "${{ matrix.product }}")
{
# Split out the key and value for each parameter
$domainKeyAndValue = $domain.split("=")
$displayKeyAndValue = $display.split("=")
$appidKeyAndValue = $appid.split("=")
$productnameKeyAndValue = $productname.split("=")
$variantKeyAndValue = $variant.split("=")
$m365KeyAndValue =$m365.split("=")
# Add both to the hash table
$paramsAsHashTable.Add($domainKeyAndValue[0], $domainKeyAndValue[1])
$paramsAsHashTable.Add($displayKeyAndValue[0], $displayKeyAndValue[1])
$paramsAsHashTable.Add($appidKeyAndValue[0], $appidKeyAndValue[1])
$paramsAsHashTable.Add($productnameKeyAndValue[0], $productnameKeyAndValue[1])
if($variantKeyAndValue[0] -ne "")
{
$paramsAsHashTable.Add($variantKeyAndValue[0], $variantKeyAndValue[1])
}
$paramsAsHashTable.Add($m365KeyAndValue[0], $m365KeyAndValue[1])
# Test the product
./Testing/Functional/Products/Tests/CallProductTests.ps1 -params $paramsAsHashTable -thumbprint $thumbprint
}
}
env:
TestParams: ${{ secrets.NIGHTLY_TEST_BUILD_PARAMS }}