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
9 changes: 5 additions & 4 deletions pode.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ param(

# Dependency Versions
$Versions = @{
Pester = '5.7.1'
Pester = '6.0.0'
MkDocs = '1.6.1'
DotNet = $SdkVersion
MkDocsTheme = '9.7.7'
Expand Down Expand Up @@ -386,7 +386,7 @@ function Install-PodeBuildModule($name) {

Write-Host "Installing $($name) v$($Versions[$name])"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module -Name "$($name)" -Scope CurrentUser -RequiredVersion "$($Versions[$name])" -Force -SkipPublisherCheck -AllowClobber
Install-Module -Name "$($name)" -Scope CurrentUser -RequiredVersion "$($Versions[$name])" -Force -SkipPublisherCheck -AllowClobber -AllowPrerelease
}

<#
Expand Down Expand Up @@ -1525,10 +1525,11 @@ Add-BuildTask TestNoBuild TestDeps, {
}

# ensure correct pester version is loaded
$pesterModuleVersion = [version]($Versions.Pester -replace '-.*$')
$p = Get-Command Invoke-Pester
if (($null -eq $p) -or ($p.Version -ine $Versions.Pester)) {
if (($null -eq $p) -or ($p.Version -ne $pesterModuleVersion)) {
Remove-Module Pester -Force -ErrorAction Ignore
Import-Module Pester -Force -RequiredVersion $Versions.Pester
Import-Module Pester -Force -RequiredVersion $pesterModuleVersion
}

# set UICulture if specified
Expand Down
10 changes: 5 additions & 5 deletions tests/compliance/Localization.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ Describe 'Localization Check' {
return $keys
}

Describe 'Verify Invalid Hashtable Keys in [<_>]' -ForEach ($sourceFiles) {
Describe 'Verify Invalid Hashtable Keys in [<_>]' -ForEach ($sourceFiles) -AllowNullOrEmptyForEach {
$keysInFile = Export-KeysFromFile -filePath $_
It "should find the key '[<_>]' in the hashtable" -ForEach ($keysInFile) {
It "should find the key '[<_>]' in the hashtable" -ForEach ($keysInFile) -AllowNullOrEmptyForEach {
$PodeLocale.Keys -contains $_ | Should -BeTrue
}
}

It "Check 'throw' is not using a static string in [<_>]" -ForEach ($sourceFiles) {
It "Check 'throw' is not using a static string in [<_>]" -ForEach ($sourceFiles) -AllowNullOrEmptyForEach {
(Get-Content -Path $_ -Raw -Force) -match 'throw\s*["\'']' | Should -BeFalse
}

Describe 'Verifying Language [<_>]' -ForEach ($languageDirs) {
Describe 'Verifying Language [<_>]' -ForEach ($languageDirs) -AllowNullOrEmptyForEach {
BeforeAll {
$content = Import-LocalizedData -FileName 'Pode.psd1' -BaseDirectory $localizationDir -UICulture (Split-Path $_ -Leaf)
}
Expand All @@ -63,7 +63,7 @@ Describe 'Localization Check' {
$content.Keys.Count | Should -be $PodeLocale.Count
}

It -Name 'Resource File contains <_>' -ForEach ( $LanguageOfReference.Keys) {
It -Name 'Resource File contains <_>' -ForEach ( $LanguageOfReference.Keys) -AllowNullOrEmptyForEach {
$content.Keys -contains $_ | Should -BeTrue
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/Authentication.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ InModuleScope -ModuleName 'Pode' {

It 'Redirects to a failure URL' {
Set-PodeAuthStatus -StatusCode 500 -Name ExampleAuth | Should -Be $false
Assert-MockCalled Move-PodeResponseUrl -Times 1 -Scope It
Assert-MockCalled Set-PodeResponseStatus -Times 0 -Scope It
Should -Invoke Move-PodeResponseUrl -Times 1 -Scope It
Should -Invoke Set-PodeResponseStatus -Times 0 -Scope It
}

It 'Sets status to failure' {
Set-PodeAuthStatus -StatusCode 500 -Name ExampleAuth | Should -Be $false
Assert-MockCalled Move-PodeResponseUrl -Times 1 -Scope It
Assert-MockCalled Set-PodeResponseStatus -Times 0 -Scope It
Should -Invoke Move-PodeResponseUrl -Times 1 -Scope It
Should -Invoke Set-PodeResponseStatus -Times 0 -Scope It
}

It 'Redirects to a success URL' {
Set-PodeAuthStatus -Name ExampleAuth -LoginRoute | Should -Be $false
Assert-MockCalled Move-PodeResponseUrl -Times 1 -Scope It
Assert-MockCalled Set-PodeResponseStatus -Times 0 -Scope It
Should -Invoke Move-PodeResponseUrl -Times 1 -Scope It
Should -Invoke Set-PodeResponseStatus -Times 0 -Scope It
}

It 'Returns true for next middleware' {
Set-PodeAuthStatus -Name ExampleAuth -NoSuccessRedirect | Should -Be $true
Assert-MockCalled Move-PodeResponseUrl -Times 0 -Scope It
Assert-MockCalled Set-PodeResponseStatus -Times 0 -Scope It
Should -Invoke Move-PodeResponseUrl -Times 0 -Scope It
Should -Invoke Set-PodeResponseStatus -Times 0 -Scope It
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ InModuleScope -ModuleName 'Pode' {
$WebEvent.Auth.User | Should -Be $null
$WebEvent.Session.Data.Auth | Should -Be $null

Assert-MockCalled Revoke-PodeSession -Times 1 -Scope It
Should -Invoke Revoke-PodeSession -Times 1 -Scope It
}

It 'Removes the user, and kills the session, redirecting to root' {
Expand All @@ -122,7 +122,7 @@ InModuleScope -ModuleName 'Pode' {
$WebEvent.Auth.User | Should -Be $null
$WebEvent.Session.Data.Auth | Should -Be $null

Assert-MockCalled Revoke-PodeSession -Times 1 -Scope It
Should -Invoke Revoke-PodeSession -Times 1 -Scope It
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Context.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ InModuleScope -ModuleName 'Pode' {

It 'Returns null for no shared state in context' {
Import-PodeModule -Path 'file.txt'
Assert-MockCalled Import-Module -Times 1 -Scope It
Should -Invoke Import-Module -Times 1 -Scope It
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/Cookies.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ InModuleScope -ModuleName 'Pode' {
}

{ Test-PodeCookieSigned -Name 'test' } | Should -Throw -ErrorId 'ParameterArgumentValidationError,Test-PodeCookieSigned'
Assert-MockCalled Invoke-PodeValueUnsign -Times 0 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 0 -Scope It
}

It 'Returns false for invalid signed cookie' {
Expand All @@ -59,7 +59,7 @@ InModuleScope -ModuleName 'Pode' {
}

Test-PodeCookieSigned -Name 'test' -Secret 'key' | Should -Be $false
Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}

It 'Returns true for valid signed cookie' {
Expand All @@ -71,7 +71,7 @@ InModuleScope -ModuleName 'Pode' {
}

Test-PodeCookieSigned -Name 'test' -Secret 'key' | Should -Be $true
Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}

It 'Returns true for valid signed cookie, using global secret' {
Expand All @@ -91,7 +91,7 @@ InModuleScope -ModuleName 'Pode' {
}

Test-PodeCookieSigned -Name 'test' -Secret (Get-PodeCookieSecret -Global) | Should -Be $true
Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ InModuleScope -ModuleName 'Pode' {
$c | Should -Not -Be $null
$c.Value | Should -Be 'example'

Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}

It 'Returns a cookie, with secret but valid signed' {
Expand All @@ -152,7 +152,7 @@ InModuleScope -ModuleName 'Pode' {
$c | Should -Not -Be $null
$c.Value | Should -Be 'some-id'

Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}

It 'Returns a cookie, with secret but valid signed, using global secret' {
Expand All @@ -175,7 +175,7 @@ InModuleScope -ModuleName 'Pode' {
$c | Should -Not -Be $null
$c.Value | Should -Be 'some-id'

Assert-MockCalled Invoke-PodeValueUnsign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueUnsign -Times 1 -Scope It
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ InModuleScope -ModuleName 'Pode' {
$h = $WebEvent.Response.Headers['Set-Cookie']
$h | Should -Not -Be $null

Assert-MockCalled Invoke-PodeValueSign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueSign -Times 1 -Scope It
}

It 'Adds signed cookie to response' {
Expand Down Expand Up @@ -272,7 +272,7 @@ InModuleScope -ModuleName 'Pode' {
$h = $WebEvent.Response.Headers['Set-Cookie']
$h | Should -Not -Be $null

Assert-MockCalled Invoke-PodeValueSign -Times 1 -Scope It
Should -Invoke Invoke-PodeValueSign -Times 1 -Scope It
}

It 'Adds cookie to response with options' {
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Endware.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ InModuleScope -ModuleName 'Pode' {
It 'Runs the logic for a single endware' {
Mock Invoke-PodeScriptBlock { }
Invoke-PodeEndware -Endware @(@{ Logic = { 'test' | Out-Null } })
Assert-MockCalled Invoke-PodeScriptBlock -Times 1 -Scope It
Should -Invoke Invoke-PodeScriptBlock -Times 1 -Scope It
}

It 'Runs the logic for 2 endwares' {
Expand All @@ -19,7 +19,7 @@ InModuleScope -ModuleName 'Pode' {
@{ Logic = { 'test' | Out-Null } },
@{ Logic = { 'test2' | Out-Null } }
)
Assert-MockCalled Invoke-PodeScriptBlock -Times 2 -Scope It
Should -Invoke Invoke-PodeScriptBlock -Times 2 -Scope It
}

It 'Runs the logic for a single endware and errors' {
Expand All @@ -28,8 +28,8 @@ InModuleScope -ModuleName 'Pode' {

Invoke-PodeEndware -Endware @(@{ Logic = { 'test' | Out-Null } })

Assert-MockCalled Invoke-PodeScriptBlock -Times 1 -Scope It
Assert-MockCalled Write-PodeErrorLog -Times 1 -Scope It
Should -Invoke Invoke-PodeScriptBlock -Times 1 -Scope It
Should -Invoke Write-PodeErrorLog -Times 1 -Scope It
}
}

Expand Down
32 changes: 16 additions & 16 deletions tests/unit/Helpers.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,47 +134,47 @@ InModuleScope -ModuleName 'Pode' {
It 'Returns false for non-unix' {
Mock Get-PodePSVersionTable { return @{ 'Platform' = 'Windows' } }
Test-PodeIsUnix | Should -Be $false
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}

It 'Returns true for unix' {
Mock Get-PodePSVersionTable { return @{ 'Platform' = 'Unix' } }
Test-PodeIsUnix | Should -Be $true
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}
}

Describe 'Test-PodeIsWindows' {
It 'Returns false for non-windows' {
Mock Get-PodePSVersionTable { return @{ 'Platform' = 'Unix' } }
Test-PodeIsWindows | Should -Be $false
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}

It 'Returns true for windows and desktop' {
Mock Get-PodePSVersionTable { return @{ 'PSEdition' = 'Desktop' } }
Test-PodeIsWindows | Should -Be $true
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}

It 'Returns true for windows and core' {
Mock Get-PodePSVersionTable { return @{ 'Platform' = 'Win32NT'; 'PSEdition' = 'Core' } }
Test-PodeIsWindows | Should -Be $true
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}
}

Describe 'Test-PodeIsPSCore' {
It 'Returns false for non-core' {
Mock Get-PodePSVersionTable { return @{ 'PSEdition' = 'Desktop' } }
Test-PodeIsPSCore | Should -Be $false
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}

It 'Returns true for unix' {
Mock Get-PodePSVersionTable { return @{ 'PSEdition' = 'Core' } }
Test-PodeIsPSCore | Should -Be $true
Assert-MockCalled Get-PodePSVersionTable -Times 1
Should -Invoke Get-PodePSVersionTable -Times 1
}
}

Expand Down Expand Up @@ -1141,8 +1141,8 @@ InModuleScope -ModuleName 'Pode' {
}

Close-PodeServerInternal
Assert-MockCalled Write-PodeHost -Times 0 -Scope It
Assert-MockCalled Close-PodeDisposable -Times 2 -Scope It
Should -Invoke Write-PodeHost -Times 0 -Scope It
Should -Invoke Close-PodeDisposable -Times 2 -Scope It
}

}
Expand Down Expand Up @@ -1280,22 +1280,22 @@ InModuleScope -ModuleName 'Pode' {
}
It 'Writes a message to the Host by parameters' {
Out-PodeHost -InputObject 'Hello'
Assert-MockCalled Out-Default -Scope It -Times 1
Should -Invoke Out-Default -Scope It -Times 1
}

It 'Writes a message to the Host by pipeline' {
'Hello' | Out-PodeHost
Assert-MockCalled Out-Default -Scope It -Times 1
Should -Invoke Out-Default -Scope It -Times 1
}

It 'Writes a hashtable to the Host by pipeline' {
@{ Name = 'Rick' } | Out-PodeHost
Assert-MockCalled Out-Default -Scope It -Times 1
Should -Invoke Out-Default -Scope It -Times 1
}

It 'Writes an Array to the Host by pipeline' {
@('France', 'Rick', 21 , 'male') | Out-PodeHost
Assert-MockCalled Out-Default -Scope It -Times 1
Should -Invoke Out-Default -Scope It -Times 1
}
}

Expand Down Expand Up @@ -1487,13 +1487,13 @@ InModuleScope -ModuleName 'Pode' {
It 'Errors when no encoding matches, and identity disabled' {
$PodeContext.Server.Web.Compression.Enabled = $true
{ Get-PodeAcceptEncoding -AcceptEncoding 'br,identity;q=0' -ThrowError } | Should -Throw -ExceptionType 'System.Net.Http.HttpRequestException'
Assert-MockCalled New-PodeRequestException -Scope It -Times 1
Should -Invoke New-PodeRequestException -Scope It -Times 1
}

It 'Errors when no encoding matches, and wildcard disabled' {
$PodeContext.Server.Web.Compression.Enabled = $true
{ Get-PodeAcceptEncoding -AcceptEncoding 'br,*;q=0' -ThrowError } | Should -Throw -ExceptionType 'System.Net.Http.HttpRequestException'
Assert-MockCalled New-PodeRequestException -Scope It -Times 1
Should -Invoke New-PodeRequestException -Scope It -Times 1
}

It 'Returns empty if identity is allowed, but wildcard disabled' {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ InModuleScope -ModuleName 'Pode' {

It 'Errors when no encoding matches' {
{ Get-PodeTransferEncoding -TransferEncoding 'compress,chunked' -ThrowError } | Should -Throw -ExceptionType 'System.Net.Http.HttpRequestException'
Assert-MockCalled New-PodeRequestException -Scope It -Times 1
Should -Invoke New-PodeRequestException -Scope It -Times 1
}
}

Expand Down
Loading