-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathActions.Tests.ps1
More file actions
127 lines (114 loc) · 5.16 KB
/
Copy pathActions.Tests.ps1
File metadata and controls
127 lines (114 loc) · 5.16 KB
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
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Pester grouping syntax: known issue.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '',
Justification = 'Log outputs to GitHub Actions logs.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidLongLines', '',
Justification = 'Long test descriptions and skip switches'
)]
[CmdletBinding()]
param()
BeforeAll {
$testName = 'Actions'
$os = $env:RUNNER_OS
$id = $env:GITHUB_RUN_ID
if (-not $id) {
throw 'GITHUB_RUN_ID is required for Actions tests because it is used to build repository-scoped names for OIDC operations.'
}
}
Describe 'Actions' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"
Context 'OIDC' {
Context 'Get-GitHubOidcClaim' {
It 'Get-GitHubOidcClaim - No context - Returns claim keys for github.com' {
$result = Get-GitHubOidcClaim
LogGroup 'Result' {
Write-Host ($result | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result | Should -Contain 'sub'
$result | Should -Contain 'repository'
$result | Should -BeOfType [string]
}
}
}
Context 'As <Type> using <Case> on <Target>' -ForEach $authCases {
BeforeAll {
$context = Connect-GitHubAccount @connectParams -PassThru -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
if ($AuthType -eq 'APP') {
LogGroup 'Context - Installation' {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
Write-Host ($context | Format-List | Out-String)
}
}
$repoPrefix = "Test-$os-$TokenType"
$repoName = "$repoPrefix-$id"
LogGroup "Using Repository - [$repoName]" {
if ($OwnerType -in ('repository', 'enterprise')) {
$repo = $null
} else {
$repo = Get-GitHubRepository -Owner $Owner -Name $repoName
if (-not $repo) {
throw "Shared test repository '$repoName' was not found for owner '$Owner' (OwnerType: '$OwnerType'). Ensure the repository was provisioned and the repository name is correct."
}
Write-Host ($repo | Select-Object * | Out-String)
}
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}
Context 'OIDC' {
It 'Get-GitHubOidcClaim - With context - Returns claim keys' {
$result = Get-GitHubOidcClaim -Context $context
LogGroup 'Result' {
Write-Host ($result | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result | Should -Contain 'sub'
$result | Should -BeOfType [string]
}
It 'Get-GitHubOidcSubjectClaim - Organization - Returns template' -Skip:($OwnerType -ne 'organization') {
$result = Get-GitHubOidcSubjectClaim -Owner $Owner -Context $context
LogGroup 'Result' {
Write-Host ($result | Format-List | Out-String)
}
$result | Should -Not -BeNullOrEmpty
$result.include_claim_keys | Should -Not -BeNullOrEmpty
}
It 'Get-GitHubOidcSubjectClaim - Repository - Returns template' -Skip:($OwnerType -in ('repository', 'enterprise')) {
$result = Get-GitHubOidcSubjectClaim -Owner $Owner -Repository $repoName -Context $context
LogGroup 'Result' {
Write-Host ($result | Format-List | Out-String)
}
$result | Should -Not -BeNullOrEmpty
}
It 'Set-GitHubOidcSubjectClaim - Organization - Sets template' -Skip:($OwnerType -ne 'organization') {
{
Set-GitHubOidcSubjectClaim -Owner $Owner -IncludeClaimKeys @('repo', 'context') -Context $context
} | Should -Not -Throw
}
It 'Set-GitHubOidcSubjectClaim - Repository - Sets template with custom keys' -Skip:($OwnerType -in ('repository', 'enterprise')) {
{
Set-GitHubOidcSubjectClaim -Owner $Owner -Repository $repoName `
-IncludeClaimKeys @('repo', 'ref') -Context $context
} | Should -Not -Throw
}
It 'Set-GitHubOidcSubjectClaim - Repository - Sets template with UseDefault' -Skip:($OwnerType -in ('repository', 'enterprise')) {
{
Set-GitHubOidcSubjectClaim -Owner $Owner -Repository $repoName `
-IncludeClaimKeys @('repo') -UseDefault -Context $context
} | Should -Not -Throw
}
}
}
}