Skip to content

Commit 0834e33

Browse files
committed
Enhance SSL certificate binding tests by ensuring test certificate retrieval and validation before execution
1 parent b925495 commit 0834e33

2 files changed

Lines changed: 48 additions & 62 deletions

File tree

tests/Integration/Commands/Remove-SqlDscRSSslCertificateBinding.Integration.Tests.ps1

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,67 +46,60 @@ BeforeAll {
4646
left removed after these tests complete.
4747
#>
4848
Describe 'Remove-SqlDscRSSslCertificateBinding' {
49+
BeforeAll {
50+
# Get the test certificate that was created by Add-SqlDscRSSslCertificateBinding tests
51+
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
52+
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
53+
Select-Object -First 1
54+
55+
if (-not $script:testCertificate)
56+
{
57+
throw 'Test certificate not found. Ensure Add-SqlDscRSSslCertificateBinding integration tests have run first to create the certificate.'
58+
}
59+
60+
$script:testCertificateHash = $script:testCertificate.Thumbprint
61+
$script:testIPAddress = '0.0.0.0'
62+
$script:testPort = 443
63+
64+
Write-Verbose -Message ('Using self-signed certificate ''{0}'' with thumbprint ''{1}''.' -f $script:testCertificate.Subject, $script:testCertificateHash) -Verbose
65+
}
66+
4967
Context 'When removing SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS') {
5068
BeforeAll {
5169
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
52-
53-
# Get the test certificate that was created by Add-SqlDscRSSslCertificateBinding tests
54-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
55-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
56-
Select-Object -First 1
57-
58-
$script:testCertificateHash = $script:testCertificate.Thumbprint
5970
}
6071

61-
It 'Should remove SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
72+
It 'Should remove SSL certificate binding' {
6273
{ $script:configuration | Remove-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
6374
}
6475
}
6576

6677
Context 'When removing SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2019_RS') {
6778
BeforeAll {
6879
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
69-
70-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
71-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
72-
Select-Object -First 1
73-
74-
$script:testCertificateHash = $script:testCertificate.Thumbprint
7580
}
7681

77-
It 'Should remove SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
82+
It 'Should remove SSL certificate binding' {
7883
{ $script:configuration | Remove-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
7984
}
8085
}
8186

8287
Context 'When removing SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2022_RS') {
8388
BeforeAll {
8489
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
85-
86-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
87-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
88-
Select-Object -First 1
89-
90-
$script:testCertificateHash = $script:testCertificate.Thumbprint
9190
}
9291

93-
It 'Should remove SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
92+
It 'Should remove SSL certificate binding' {
9493
{ $script:configuration | Remove-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
9594
}
9695
}
9796

9897
Context 'When removing SSL certificate binding for Power BI Report Server' -Tag @('Integration_PowerBI') {
9998
BeforeAll {
10099
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop'
101-
102-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
103-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
104-
Select-Object -First 1
105-
106-
$script:testCertificateHash = $script:testCertificate.Thumbprint
107100
}
108101

109-
It 'Should remove SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
102+
It 'Should remove SSL certificate binding' {
110103
{ $script:configuration | Remove-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
111104
}
112105
}

tests/Integration/Commands/Set-SqlDscRSSslCertificateBinding.Integration.Tests.ps1

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,34 @@ BeforeAll {
4747
and sets the binding after Remove-SqlDscRSSslCertificateBinding has removed it.
4848
#>
4949
Describe 'Set-SqlDscRSSslCertificateBinding' {
50+
BeforeAll {
51+
# Get the test certificate that was created by Add-SqlDscRSSslCertificateBinding tests
52+
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
53+
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
54+
Select-Object -First 1
55+
56+
if (-not $script:testCertificate)
57+
{
58+
throw 'Test certificate not found. Ensure Add-SqlDscRSSslCertificateBinding integration tests have run first to create the certificate.'
59+
}
60+
61+
$script:testCertificateHash = $script:testCertificate.Thumbprint
62+
$script:testIPAddress = '0.0.0.0'
63+
$script:testPort = 443
64+
65+
Write-Verbose -Message ('Using self-signed certificate ''{0}'' with thumbprint ''{1}''.' -f $script:testCertificate.Subject, $script:testCertificateHash) -Verbose
66+
}
67+
5068
Context 'When setting SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2017_RS') {
5169
BeforeAll {
5270
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
53-
54-
# Get the test certificate that was created by Add-SqlDscRSSslCertificateBinding tests
55-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
56-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
57-
Select-Object -First 1
58-
59-
$script:testCertificateHash = $script:testCertificate.Thumbprint
6071
}
6172

62-
It 'Should set SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
73+
It 'Should set SSL certificate binding' {
6374
{ $script:configuration | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
6475
}
6576

66-
It 'Should return configuration when using PassThru' -Skip:(-not $script:testCertificateHash) {
77+
It 'Should return configuration when using PassThru' {
6778
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
6879
$result = $config | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -PassThru -ErrorAction 'Stop'
6980

@@ -75,19 +86,13 @@ Describe 'Set-SqlDscRSSslCertificateBinding' {
7586
Context 'When setting SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2019_RS') {
7687
BeforeAll {
7788
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
78-
79-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
80-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
81-
Select-Object -First 1
82-
83-
$script:testCertificateHash = $script:testCertificate.Thumbprint
8489
}
8590

86-
It 'Should set SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
91+
It 'Should set SSL certificate binding' {
8792
{ $script:configuration | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
8893
}
8994

90-
It 'Should return configuration when using PassThru' -Skip:(-not $script:testCertificateHash) {
95+
It 'Should return configuration when using PassThru' {
9196
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
9297
$result = $config | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -PassThru -ErrorAction 'Stop'
9398

@@ -99,19 +104,13 @@ Describe 'Set-SqlDscRSSslCertificateBinding' {
99104
Context 'When setting SSL certificate binding for SQL Server Reporting Services' -Tag @('Integration_SQL2022_RS') {
100105
BeforeAll {
101106
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
102-
103-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
104-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
105-
Select-Object -First 1
106-
107-
$script:testCertificateHash = $script:testCertificate.Thumbprint
108107
}
109108

110-
It 'Should set SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
109+
It 'Should set SSL certificate binding' {
111110
{ $script:configuration | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
112111
}
113112

114-
It 'Should return configuration when using PassThru' -Skip:(-not $script:testCertificateHash) {
113+
It 'Should return configuration when using PassThru' {
115114
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' -ErrorAction 'Stop'
116115
$result = $config | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -PassThru -ErrorAction 'Stop'
117116

@@ -123,19 +122,13 @@ Describe 'Set-SqlDscRSSslCertificateBinding' {
123122
Context 'When setting SSL certificate binding for Power BI Report Server' -Tag @('Integration_PowerBI') {
124123
BeforeAll {
125124
$script:configuration = Get-SqlDscRSConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop'
126-
127-
$script:testCertificate = Get-ChildItem -Path 'Cert:\LocalMachine\My' |
128-
Where-Object -FilterScript { $_.FriendlyName -eq $script:testCertificateFriendlyName } |
129-
Select-Object -First 1
130-
131-
$script:testCertificateHash = $script:testCertificate.Thumbprint
132125
}
133126

134-
It 'Should set SSL certificate binding' -Skip:(-not $script:testCertificateHash) {
127+
It 'Should set SSL certificate binding' {
135128
{ $script:configuration | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -ErrorAction 'Stop' } | Should -Not -Throw
136129
}
137130

138-
It 'Should return configuration when using PassThru' -Skip:(-not $script:testCertificateHash) {
131+
It 'Should return configuration when using PassThru' {
139132
$config = Get-SqlDscRSConfiguration -InstanceName 'PBIRS' -ErrorAction 'Stop'
140133
$result = $config | Set-SqlDscRSSslCertificateBinding -Application 'ReportServerWebService' -CertificateHash $script:testCertificateHash -IPAddress $script:testIPAddress -Port $script:testPort -Force -PassThru -ErrorAction 'Stop'
141134

0 commit comments

Comments
 (0)