From 119a891c63d3ad7a33ed6981ebbbbe749c1a880f Mon Sep 17 00:00:00 2001 From: Oliver Lipkau Date: Wed, 6 Mar 2019 19:32:58 +0100 Subject: [PATCH] Fixed test to generate certificate when possible --- Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1 b/Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1 index 4689a71..e0bd2dd 100644 --- a/Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1 +++ b/Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1 @@ -14,10 +14,16 @@ Describe "[AtlassianPS.ServerData] Tests" -Tag Unit { } # ARRANGE + $testPath = (Get-PsDrive TestDrive).Root + if (Get-Command openssl -ErrorAction SilentlyContinue) { + openssl req -x509 -newkey rsa:4096 -sha256 -keyout "$testPath/openssl.key" -out "$testPath/openssl.crt" -subj "/CN=company.co.nz" -days 600 -passout pass:"hunter2" + $certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList "$testPath/openssl.crt" + } else { + $certificate = Get-ChildItem -Path "Cert:\LocalMachine\" -Recurse | + Where-Object { $_.GetType().Name -eq "X509Certificate2" } | + Select-Object -First 1 + } $session = New-Object -TypeName Microsoft.PowerShell.Commands.WebRequestSession - $certificate = Get-ChildItem -Path "Cert:\LocalMachine\" -Recurse | - Where-Object { $_.GetType().Name -eq "X509Certificate2" } | - Select-Object -First 1 It "does not allow for an empty object" { { [AtlassianPS.ServerData]::new() } | Should -Throw