diff --git a/src/classes/public/App/GitHubAppInstallation.ps1 b/src/classes/public/App/GitHubAppInstallation.ps1 index 6684d77f4..c0071d3ad 100644 --- a/src/classes/public/App/GitHubAppInstallation.ps1 +++ b/src/classes/public/App/GitHubAppInstallation.ps1 @@ -40,7 +40,7 @@ GitHubAppInstallation() {} - GitHubAppInstallation([PSCustomObject]$Object) { + GitHubAppInstallation([PSCustomObject] $Object) { $this.ID = $Object.id $this.App = [GitHubApp]::new( [PSCustomObject]@{ @@ -60,4 +60,25 @@ $this.SuspendedAt = $Object.suspended_at $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) } + + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type) { + $this.ID = $Object.id + $this.App = [GitHubApp]::new( + [PSCustomObject]@{ + client_id = $Object.client_id + app_id = $Object.app_id + app_slug = $Object.app_slug + } + ) + $this.Target = [GitHubOwner]::new($Target) + $this.Type = $Type + $this.RepositorySelection = $Object.repository_selection + $this.Permissions = $Object.permissions + $this.Events = , ($Object.events) + $this.FilePaths = $Object.single_file_paths + $this.CreatedAt = $Object.created_at + $this.UpdatedAt = $Object.updated_at + $this.SuspendedAt = $Object.suspended_at + $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) + } } diff --git a/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 b/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 index 9d61ff992..b7dc45a15 100644 --- a/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 +++ b/src/classes/public/Context/GitHubContext/InstallationGitHubContext.ps1 @@ -7,7 +7,7 @@ [datetime] $TokenExpirationDate # The installation ID. - [int] $InstallationID + [uint64] $InstallationID # The permissions that the app is requesting on the target [pscustomobject] $Permissions diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 index c179a6a3f..568e120f4 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 @@ -51,7 +51,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_) } + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization) + } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index bdad499f8..79b2f94d5 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -58,7 +58,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubAppInstallation]::new($_.Response) + foreach ($installation in $_.Response.installations) { + [GitHubAppInstallation]::new($installation, $Organization, 'Organization') + } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 index 90c442354..5c63a6866 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 @@ -50,8 +50,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.installations | ForEach-Object { - [GitHubAppInstallation]::new($_) + foreach ($installation in $_.Response.installations) { + [GitHubAppInstallation]::new($installation) } } } diff --git a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 index 856252aa0..69ae92370 100644 --- a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 +++ b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 @@ -56,6 +56,7 @@ PerPage = $PerPage Context = $Context } + Write-Debug "ParamSet: $($PSCmdlet.ParameterSetName)" switch ($PSCmdlet.ParameterSetName) { 'List installations on an Enterprise' { $params += @{ diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index dd11923d2..1bf29392e 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -153,8 +153,8 @@ $contextParams['Owner'] = [string]$installation.Target.Name } 'Enterprise' { - $contextParams['InstallationName'] = [string]$installation.account.slug - $contextParams['Enterprise'] = [string]$installation.account.slug + $contextParams['InstallationName'] = [string]$installation.Target.Name + $contextParams['Enterprise'] = [string]$installation.Target.Name } } Write-Verbose 'Logging in using a managed installation access token...' @@ -162,7 +162,7 @@ $contextObj = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) $contextObj | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose $_ } if (-not $Silent) { - $name = $contextObj.name + $name = $contextObj.Name if ($script:GitHub.EnvironmentType -eq 'GHA') { $green = $PSStyle.Foreground.Green $reset = $PSStyle.Reset diff --git a/tests/Apps.Tests.ps1 b/tests/Apps.Tests.ps1 new file mode 100644 index 000000000..e6613bb13 --- /dev/null +++ b/tests/Apps.Tests.ps1 @@ -0,0 +1,229 @@ +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', '', + Justification = 'Pester grouping syntax: known issue.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Used to create a secure string for testing.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', + Justification = 'Log outputs to GitHub Actions logs.' +)] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidLongLines', '', + Justification = 'Long test descriptions and skip switches' +)] +[CmdletBinding()] +param() + +Describe 'Apps' { + $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" + + Context 'As using on ' -ForEach $authCases { + BeforeAll { + $context = Connect-GitHubAccount @connectParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + } + + AfterAll { + Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent + Write-Host ('-' * 60) + } + + # Tests for APP goes here + if ($AuthType -eq 'APP') { + Context 'GitHub Apps' { + It 'Get-GitHubApp - Can get app details' { + $app = Get-GitHubApp + LogGroup 'App' { + Write-Host ($app | Format-List | Out-String) + } + $app | Should -Not -BeNullOrEmpty + $app | Should -BeOfType 'GitHubApp' + $app.ID | Should -Not -BeNullOrEmpty + $app.ClientID | Should -Not -BeNullOrEmpty + $app.Slug | Should -Not -BeNullOrEmpty + $app.NodeID | Should -Not -BeNullOrEmpty + $app.Owner | Should -BeOfType 'GitHubOwner' + $app.Name | Should -Not -BeNullOrEmpty + $app.Description | Should -Not -BeNullOrEmpty + $app.ExternalUrl | Should -Not -BeNullOrEmpty + $app.Url | Should -Not -BeNullOrEmpty + $app.CreatedAt | Should -Not -BeNullOrEmpty + $app.UpdatedAt | Should -Not -BeNullOrEmpty + $app.Permissions | Should -BeOfType 'PSCustomObject' + $app.Events | Should -BeOfType 'string' + $app.Installations | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { + $jwt = Get-GitHubAppJSONWebToken @connectParams + LogGroup 'JWT' { + Write-Host ($jwt | Format-Table | Out-String) + } + $jwt | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppInstallationRequest - Can get installation requests' { + $installationRequests = Get-GitHubAppInstallationRequest + LogGroup 'Installation requests' { + Write-Host ($installationRequests | Format-List | Out-String) + } + } + + It 'Get-GitHubAppInstallation - Can get app installations' { + $githubApp = Get-GitHubApp + $installations = Get-GitHubAppInstallation + LogGroup 'Installations' { + Write-Host ($installations | Format-List | Out-String) + } + $installations | Should -Not -BeNullOrEmpty + foreach ($installation in $installations) { + $installation | Should -BeOfType 'GitHubAppInstallation' + $installation.ID | Should -Not -BeNullOrEmpty + $installation.App | Should -BeOfType 'GitHubApp' + $installation.App.ClientID | Should -Be $githubApp.ClientID + $installation.App.AppID | Should -Not -BeNullOrEmpty + $installation.App.Slug | Should -Not -BeNullOrEmpty + $installation.Target | Should -BeOfType 'GitHubOwner' + $installation.Target | Should -Not -BeNullOrEmpty + $installation.Type | Should -BeIn @('Enterprise', 'Organization', 'User') + $installation.RepositorySelection | Should -Not -BeNullOrEmpty + $installation.Permissions | Should -BeOfType 'PSCustomObject' + $installation.Events | Should -BeOfType 'string' + $installation.CreatedAt | Should -Not -BeNullOrEmpty + $installation.UpdatedAt | Should -Not -BeNullOrEmpty + $installation.SuspendedAt | Should -BeNullOrEmpty + $installation.SuspendedBy | Should -BeOfType 'GitHubUser' + $installation.SuspendedBy | Should -BeNullOrEmpty + } + } + + It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { + $installations = Get-GitHubAppInstallation + LogGroup 'Tokens' { + $installations | ForEach-Object { + $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id + Write-Host ($token | Format-List | Out-String) + } + $token | Should -Not -BeNullOrEmpty + } + } + + It 'Get-GitHubAppInstallation - ' { + $githubApp = Get-GitHubApp + $installation = Get-GitHubAppInstallation | Where-Object { ($_.Target.Name -eq $owner) -and ($_.Type -eq $ownerType) } + LogGroup "Installation - $ownerType" { + Write-Host ($installation | Format-List | Out-String) + } + $installation | Should -Not -BeNullOrEmpty + $installation | Should -BeOfType 'GitHubAppInstallation' + $installation.ID | Should -Not -BeNullOrEmpty + $installation.App | Should -BeOfType 'GitHubApp' + $installation.App.ClientID | Should -Be $githubApp.ClientID + $installation.App.AppID | Should -Not -BeNullOrEmpty + $installation.App.Slug | Should -Not -BeNullOrEmpty + $installation.Target | Should -BeOfType 'GitHubOwner' + $installation.Target | Should -Be $owner + $installation.Type | Should -Be $ownerType + $installation.RepositorySelection | Should -Not -BeNullOrEmpty + $installation.Permissions | Should -BeOfType 'PSCustomObject' + $installation.Events | Should -BeOfType 'string' + $installation.CreatedAt | Should -Not -BeNullOrEmpty + $installation.UpdatedAt | Should -Not -BeNullOrEmpty + $installation.SuspendedAt | Should -BeNullOrEmpty + $installation.SuspendedBy | Should -BeOfType 'GitHubUser' + $installation.SuspendedBy | Should -BeNullOrEmpty + } + } + + Context 'Webhooks' { + It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + $webhookConfig | Should -Not -BeNullOrEmpty + } + + It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { + { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - form' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw + $webhookConfig = Get-GitHubAppWebhookConfiguration + LogGroup 'Webhook config - json' { + Write-Host ($webhookConfig | Format-Table | Out-String) + } + } + + It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { + $deliveries = Get-GitHubAppWebhookDelivery + LogGroup 'Deliveries' { + Write-Host ($deliveries | Format-Table | Out-String) + } + $deliveries | Should -Not -BeNullOrEmpty + } + + It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { + $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw + LogGroup 'Delivery - redeliver' { + Write-Host ($deliveries | Format-Table | Out-String) + } + } + } + It 'Connect-GitHubApp - Connects as a GitHub App to ' { + $githubApp = Get-GitHubApp + $config = Get-GitHubConfig + $context = Connect-GitHubApp @connectAppParams -PassThru -Silent + LogGroup 'Context' { + Write-Host ($context | Format-List | Out-String) + } + $context | Should -BeOfType 'InstallationGitHubContext' + $context.ClientID | Should -Be $githubApp.ClientID + $context.TokenExpirationDate | Should -BeOfType [datetime] + $context.InstallationID | Should -BeOfType [uint64] + $context.InstallationID | Should -BeGreaterThan 0 + $context.Permissions | Should -BeOfType [PSCustomObject] + $context.Events | Should -BeOfType 'string' + $context.InstallationType | Should -Be $ownertype + $context.InstallationName | Should -Be $owner + $context.ID | Should -Be "$($config.HostName)/$($githubApp.Slug)/$ownertype/$owner" + $context.Name | Should -Be "$($config.HostName)/$($githubApp.Slug)/$ownertype/$owner" + $context.DisplayName | Should -Be $githubApp.Name + $context.Type | Should -Be 'Installation' + $context.HostName | Should -Be $config.HostName + $context.ApiBaseUri | Should -Be $config.ApiBaseUri + $context.ApiVersion | Should -Be $config.ApiVersion + $context.AuthType | Should -Be 'IAT' + $context.NodeID | Should -Not -BeNullOrEmpty + $context.DatabaseID | Should -Not -BeNullOrEmpty + $context.UserName | Should -Be $githubApp.Slug + $context.Token | Should -BeOfType [System.Security.SecureString] + $context.TokenType | Should -Be 'ghs' + $context.HttpVersion | Should -Be $config.HttpVersion + $context.PerPage | Should -Be $config.PerPage + } + } + + # Tests for IAT UAT and PAT goes here + It 'Get-GitHubApp - Get an app by slug' -Skip:($AuthType -eq 'APP') { + $app = Get-GitHubApp -Slug 'github-actions' + LogGroup 'App by slug' { + Write-Host ($app | Format-List | Out-String) + } + $app | Should -Not -BeNullOrEmpty + } + } +} diff --git a/tests/Data/AuthCases.ps1 b/tests/Data/AuthCases.ps1 index 63c7f1438..ad252ae73 100644 --- a/tests/Data/AuthCases.ps1 +++ b/tests/Data/AuthCases.ps1 @@ -48,22 +48,6 @@ Token = $env:GITHUB_TOKEN } } - @{ - AuthType = 'App' - Type = 'a GitHub App from an Enterprise' - Case = 'PEM + IAT' - TokenType = 'APP_ENT' - Target = 'organization account' - Owner = 'psmodule-test-org3' - OwnerType = 'organization' - ConnectParams = @{ - ClientID = $env:TEST_APP_ENT_CLIENT_ID - PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY - } - ConnectAppParams = @{ - Organization = 'psmodule-test-org3' - } - } @{ AuthType = 'App' Type = 'a GitHub App from an Organization' @@ -81,3 +65,35 @@ } } ) +@{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'organization account' + Owner = 'psmodule-test-org3' + OwnerType = 'organization' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Organization = 'psmodule-test-org3' + } +} +@{ + AuthType = 'App' + Type = 'a GitHub App from an Enterprise' + Case = 'PEM + IAT' + TokenType = 'APP_ENT' + Target = 'enterprise account' + Owner = 'msx' + OwnerType = 'enterprise' + ConnectParams = @{ + ClientID = $env:TEST_APP_ENT_CLIENT_ID + PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY + } + ConnectAppParams = @{ + Enterprise = 'msx' + } +} diff --git a/tests/Environments.Tests.ps1 b/tests/Environments.Tests.ps1 index 0c2750c3e..762eab550 100644 --- a/tests/Environments.Tests.ps1 +++ b/tests/Environments.Tests.ps1 @@ -72,21 +72,21 @@ Describe 'Environments' { Write-Host ('-' * 60) } - It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return an empty list when no environments exist' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving a non-existent environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubEnvironment - should successfully create an environment with a wait timer of 10' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -WaitTimer 10 LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -96,7 +96,7 @@ Describe 'Environments' { $result.Name | Should -Be $environmentName $result.ProtectionRules.wait_timer | Should -Be 10 } - It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should retrieve the environment that was created' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -104,7 +104,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $environmentName } - It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubEnvironment - should successfully create an environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Set-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-List | Out-String) @@ -112,7 +112,7 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should retrieve the environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) @@ -120,29 +120,29 @@ Describe 'Environments' { $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be "$environmentName/$os" } - It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubEnvironment - should delete the environment with a slash in its name without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) { { Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" | Remove-GitHubEnvironment -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving the deleted environment with a slash in its name' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name "$environmentName/$os" LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result | Should -BeNullOrEmpty } - It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should list one remaining environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) } $result.Count | Should -Be 1 } - It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubEnvironment - should delete the remaining environment without errors' -Skip:($OwnerType -in ('repository', 'enterprise')) { { Remove-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName -Confirm:$false } | Should -Not -Throw } - It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubEnvironment - should return null when retrieving an environment that does not exist' -Skip:($OwnerType -in ('repository', 'enterprise')) { $result = Get-GitHubEnvironment -Owner $owner -Repository $repoName -Name $environmentName LogGroup 'Environment' { Write-Host ($result | Format-Table | Out-String) diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index cf42caafa..dc23e96c1 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -470,164 +470,6 @@ line } } -Describe 'Apps' { - $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" - - Context 'As using on ' -ForEach $authCases { - BeforeAll { - $context = Connect-GitHubAccount @connectParams -PassThru -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - - AfterAll { - Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent - Write-Host ('-' * 60) - } - - # Tests for APP goes here - if ($AuthType -eq 'APP') { - Context 'GitHub Apps' { - It 'Get-GitHubApp - Can get app details' { - $app = Get-GitHubApp - LogGroup 'App' { - Write-Host ($app | Format-List | Out-String) - } - $app | Should -Not -BeNullOrEmpty - $app | Should -BeOfType 'GitHubApp' - $app.ID | Should -Not -BeNullOrEmpty - $app.ClientID | Should -Not -BeNullOrEmpty - $app.Slug | Should -Not -BeNullOrEmpty - $app.NodeID | Should -Not -BeNullOrEmpty - $app.Owner | Should -BeOfType 'GitHubOwner' - $app.Name | Should -Not -BeNullOrEmpty - $app.Description | Should -Not -BeNullOrEmpty - $app.ExternalUrl | Should -Not -BeNullOrEmpty - $app.Url | Should -Not -BeNullOrEmpty - $app.CreatedAt | Should -Not -BeNullOrEmpty - $app.UpdatedAt | Should -Not -BeNullOrEmpty - $app.Permissions | Should -BeOfType 'PSCustomObject' - $app.Events | Should -BeOfType 'string' - $app.Installations | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppJSONWebToken - Can get a JWT for the app' { - $jwt = Get-GitHubAppJSONWebToken @connectParams - LogGroup 'JWT' { - Write-Host ($jwt | Format-Table | Out-String) - } - $jwt | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppInstallationRequest - Can get installation requests' { - $installationRequests = Get-GitHubAppInstallationRequest - LogGroup 'Installation requests' { - Write-Host ($installationRequests | Format-List | Out-String) - } - } - - It 'Get-GitHubAppInstallation - Can get app installations' { - $installations = Get-GitHubAppInstallation - LogGroup 'Installations' { - Write-Host ($installations | Format-List | Out-String) - } - $installations | Should -Not -BeNullOrEmpty - $githubApp = Get-GitHubApp - foreach ($installation in $installations) { - $installation | Should -BeOfType 'GitHubAppInstallation' - $installation.ID | Should -Not -BeNullOrEmpty - $installation.App | Should -BeOfType 'GitHubApp' - $installation.App.ClientID | Should -Be $githubApp.ClientID - $installation.App.AppID | Should -Not -BeNullOrEmpty - $installation.App.Slug | Should -Not -BeNullOrEmpty - $installation.Target | Should -BeOfType 'GitHubOwner' - $installation.Type | Should -Not -BeNullOrEmpty - $installation.RepositorySelection | Should -Not -BeNullOrEmpty - $installation.Permissions | Should -BeOfType 'PSCustomObject' - $installation.Events | Should -BeOfType 'string' - $installation.CreatedAt | Should -Not -BeNullOrEmpty - $installation.UpdatedAt | Should -Not -BeNullOrEmpty - $installation.SuspendedAt | Should -BeNullOrEmpty - $installation.SuspendedBy | Should -BeOfType 'GitHubUser' - } - } - - It 'New-GitHubAppInstallationAccessToken - Can get app installation access tokens' { - $installations = Get-GitHubAppInstallation - LogGroup 'Tokens' { - $installations | ForEach-Object { - $token = New-GitHubAppInstallationAccessToken -InstallationID $_.id - Write-Host ($token | Format-List | Out-String) - } - $token | Should -Not -BeNullOrEmpty - } - } - } - - Context 'Webhooks' { - It 'Get-GitHubAppWebhookConfiguration - Can get the webhook configuration' { - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - $webhookConfig | Should -Not -BeNullOrEmpty - } - - It 'Update-GitHubAppWebhookConfiguration - Can update the webhook configuration' { - { Update-GitHubAppWebhookConfiguration -ContentType 'form' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - form' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - { Update-GitHubAppWebhookConfiguration -ContentType 'json' } | Should -Not -Throw - $webhookConfig = Get-GitHubAppWebhookConfiguration - LogGroup 'Webhook config - json' { - Write-Host ($webhookConfig | Format-Table | Out-String) - } - } - - It 'Get-GitHubAppWebhookDelivery - Can get webhook deliveries' { - $deliveries = Get-GitHubAppWebhookDelivery - LogGroup 'Deliveries' { - Write-Host ($deliveries | Format-Table | Out-String) - } - $deliveries | Should -Not -BeNullOrEmpty - } - - It 'Get-GitHubAppWebhookDelivery - Can redeliver a webhook delivery' { - $deliveries = Get-GitHubAppWebhookDelivery | Select-Object -First 1 - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - { Invoke-GitHubAppWebhookReDelivery -ID $deliveries.id } | Should -Not -Throw - LogGroup 'Delivery - redeliver' { - Write-Host ($deliveries | Format-Table | Out-String) - } - } - } - It 'Connect-GitHubApp - Connects as a GitHub App to ' { - $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context' { - Write-Host ($context | Format-List | Out-String) - } - } - } - - # Tests for runners goes here - if ($Type -eq 'GitHub Actions') {} - - # Tests for IAT UAT and PAT goes here - It 'Get-GitHubApp - Get an app by slug' { - $app = Get-GitHubApp -Slug 'github-actions' - LogGroup 'App by slug' { - Write-Host ($app | Format-List | Out-String) - } - $app | Should -Not -BeNullOrEmpty - } - } -} - Describe 'API' { $authCases = . "$PSScriptRoot/Data/AuthCases.ps1" diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 07059997c..32ddb2b28 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -65,21 +65,17 @@ Describe 'Organizations' { } $organizations | Should -Not -BeNullOrEmpty } - if ($OwnerType -ne 'user') { - It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' { - $members = Get-GitHubOrganizationMember -Organization $owner - LogGroup 'Members' { - Write-Host ($members | Select-Object * | Out-String) - } - $members | Should -Not -BeNullOrEmpty + It 'Get-GitHubOrganizationMember - Gets the members of a specific organization' -Skip:($OwnerType -in ('user', 'enterprise')) { + $members = Get-GitHubOrganizationMember -Organization $owner + LogGroup 'Members' { + Write-Host ($members | Select-Object * | Out-String) } + $members | Should -Not -BeNullOrEmpty } # Tests for IAT UAT and PAT goes here - if ($OwnerType -eq 'user') { - It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' { - { Get-GitHubOrganization } | Should -Not -Throw - } + It 'Get-GitHubOrganization - Gets the organizations for the authenticated user' -Skip:($OwnerType -notin ('user')) { + { Get-GitHubOrganization } | Should -Not -Throw } if ($OwnerType -eq 'organization' -and $Type -ne 'GitHub Actions') { diff --git a/tests/Releases.Tests.ps1 b/tests/Releases.Tests.ps1 index bf6cec578..2837cabb6 100644 --- a/tests/Releases.Tests.ps1 +++ b/tests/Releases.Tests.ps1 @@ -78,7 +78,7 @@ Describe 'Releases' { Write-Host ('-' * 60) } - Context 'Releases' -Skip:($OwnerType -eq 'repository') { + Context 'Releases' -Skip:($OwnerType -in ('repository', 'enterprise')) { It 'New-GitHubRelease - Creates a new release' { $release = New-GitHubRelease -Owner $Owner -Repository $repo -Tag 'v1.0' -Latest LogGroup 'Release' { @@ -316,7 +316,7 @@ Describe 'Releases' { $notes.Notes | Should -Match $releaseTag } } - Context 'Release Assets' -Skip:($OwnerType -eq 'repository') { + Context 'Release Assets' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $testFolderGuid = [Guid]::NewGuid().ToString().Substring(0, 8) $testFolderName = "GHAssetTest-$testFolderGuid" diff --git a/tests/Repositories.Tests.ps1 b/tests/Repositories.Tests.ps1 index 417b66faf..3605ea829 100644 --- a/tests/Repositories.Tests.ps1 +++ b/tests/Repositories.Tests.ps1 @@ -66,7 +66,7 @@ Describe 'Repositories' { Write-Host ('-' * 60) } - It 'New-GitHubRepository - Creates a new repository' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Creation' { $params = @{ Name = $repoName @@ -111,7 +111,7 @@ Describe 'Repositories' { $repo.IsArchived | Should -Be $false } } - It 'New-GitHubRepository - Creates a new repository with settings' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository with settings' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-settings" LogGroup 'Repository - Creation + Settings' { $params = @{ @@ -179,7 +179,7 @@ Describe 'Repositories' { $repo.Homepage | Should -Be 'https://example.com' } } - It 'New-GitHubRepository - Creates a new repository from a template' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository from a template' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-template" LogGroup 'Repository - Template' { $params = @{ @@ -228,7 +228,7 @@ Describe 'Repositories' { $repo.IsArchived | Should -Be $false } } - It 'New-GitHubRepository - Creates a new repository as a fork' -Skip:($OwnerType -eq 'repository') { + It 'New-GitHubRepository - Creates a new repository as a fork' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-fork" LogGroup 'Repository - Fork' { $params = @{ @@ -297,7 +297,7 @@ Describe 'Repositories' { } $repos | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets a specific repository' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets a specific repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository' { switch ($OwnerType) { 'user' { @@ -311,7 +311,7 @@ Describe 'Repositories' { } $repo | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets repositories with properties' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with properties' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Property' { switch ($OwnerType) { 'user' { @@ -333,7 +333,7 @@ Describe 'Repositories' { $item.Owner | Should -BeNullOrEmpty } } - It 'Get-GitHubRepository - Gets repositories with additional properties' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with additional properties' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - AdditionalProperty' { switch ($OwnerType) { 'user' { @@ -349,7 +349,7 @@ Describe 'Repositories' { $repo.CreatedAt | Should -Not -BeNullOrEmpty $repo.UpdatedAt | Should -Not -BeNullOrEmpty } - It 'Get-GitHubRepository - Gets repositories with properties - only name' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets repositories with properties - only name' -Skip:($OwnerType -in ('repository', 'enterprise')) { LogGroup 'Repository - Property' { switch ($OwnerType) { 'user' { @@ -386,7 +386,7 @@ Describe 'Repositories' { } $repos.Count | Should -BeGreaterThan 0 } - It 'Set-GitHubRepository - Updates an existing repository' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Updates an existing repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { $description = 'Updated description' LogGroup 'Repository - Set update' { switch ($OwnerType) { @@ -412,7 +412,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 2 } } - It 'Set-GitHubRepository - Creates a new repository when missing' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates a new repository when missing' -Skip:($OwnerType -in ('repository', 'enterprise')) { $newRepoName = "$repoName-new" LogGroup 'Repository - Set create' { switch ($OwnerType) { @@ -433,7 +433,7 @@ Describe 'Repositories' { $repo | Should -Not -BeNullOrEmpty } } - It 'Update-GitHubRepository - Renames a repository' -Skip:($OwnerType -eq 'repository') { + It 'Update-GitHubRepository - Renames a repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { $newName = "$repoName-newname" LogGroup 'Repository - Renamed' { switch ($OwnerType) { @@ -465,7 +465,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 8 } } - It 'Remove-GitHubRepository - Removes all repositories' -Skip:($OwnerType -eq 'repository') { + It 'Remove-GitHubRepository - Removes all repositories' -Skip:($OwnerType -in ('repository', 'enterprise')) { switch ($OwnerType) { 'user' { Get-GitHubRepository | Where-Object { $_.Name -like "$repoPrefix*" } | Remove-GitHubRepository -Confirm:$false @@ -476,7 +476,7 @@ Describe 'Repositories' { } } } - It 'Get-GitHubRepository - Gets none repositories after removal' -Skip:($OwnerType -eq 'repository') { + It 'Get-GitHubRepository - Gets none repositories after removal' -Skip:($OwnerType -in ('repository', 'enterprise')) { switch ($OwnerType) { 'user' { $repos = Get-GitHubRepository -Username $Owner | Where-Object { $_.name -like "$repoName*" } @@ -490,7 +490,7 @@ Describe 'Repositories' { $repos | Should -BeNullOrEmpty } } - It 'Set-GitHubRepository - Creates and updates a repository from a template' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates and updates a repository from a template' -Skip:($OwnerType -in ('repository', 'enterprise')) { $templateRepoName = "$repoName-template" $templateParams = @{ Name = $templateRepoName @@ -541,7 +541,7 @@ Describe 'Repositories' { $changedProps.Count | Should -Be 4 } } - It 'Set-GitHubRepository - Creates and updates a repository as a fork' -Skip:($OwnerType -eq 'repository') { + It 'Set-GitHubRepository - Creates and updates a repository as a fork' -Skip:($OwnerType -in ('repository', 'enterprise')) { $name = "$repoName-fork3" $forkParams = @{ Name = $name diff --git a/tests/Secrets.Tests.ps1 b/tests/Secrets.Tests.ps1 index 152145535..2384187ab 100644 --- a/tests/Secrets.Tests.ps1 +++ b/tests/Secrets.Tests.ps1 @@ -307,7 +307,7 @@ Describe 'Secrets' { } } - Context 'Repository' -Skip:($OwnerType -eq 'repository') { + Context 'Repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner @@ -420,7 +420,7 @@ Describe 'Secrets' { } } - Context 'Environment' -Skip:($OwnerType -eq 'repository') { + Context 'Environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner diff --git a/tests/Variables.Tests.ps1 b/tests/Variables.Tests.ps1 index 41107a50a..2b039ce31 100644 --- a/tests/Variables.Tests.ps1 +++ b/tests/Variables.Tests.ps1 @@ -328,7 +328,7 @@ Describe 'Variables' { } } - Context 'Repository' -Skip:($OwnerType -eq 'repository') { + Context 'Repository' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner @@ -447,7 +447,7 @@ Describe 'Variables' { } } - Context 'Environment' -Skip:($OwnerType -eq 'repository') { + Context 'Environment' -Skip:($OwnerType -in ('repository', 'enterprise')) { BeforeAll { $scope = @{ Owner = $owner