-
Notifications
You must be signed in to change notification settings - Fork 134
/
MSFT_xDSCWebService.Tests.ps1
1620 lines (1351 loc) · 78.9 KB
/
MSFT_xDSCWebService.Tests.ps1
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$script:testsFolderFilePath = Split-Path $PSScriptRoot -Parent
$script:commonTestHelperFilePath = Join-Path -Path $testsFolderFilePath -ChildPath 'CommonTestHelper.psm1'
Import-Module -Name $commonTestHelperFilePath
$script:dscModuleName = 'xPSDesiredStateConfiguration'
$script:dscResourceName = 'MSFT_xDSCWebService'
if (Test-SkipContinuousIntegrationTask -Type 'Unit')
{
return
}
#region HEADER
# Integration Test Template Version: 1.1.0
[System.String] $script:moduleRoot = Split-Path -Parent -Path (Split-Path -Parent -Path $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git.exe @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests'))
}
Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:dscModuleName `
-DSCResourceName $script:dscResourceName `
-TestType Unit
#endregion
# Begin Testing
try
{
#region Pester Tests
InModuleScope -ModuleName $script:dscResourceName -ScriptBlock {
$dscResourceName = 'MSFT_xDSCWebService'
#region Test Data
$testParameters = @{
CertificateThumbPrint = 'AllowUnencryptedTraffic'
EndpointName = 'PesterTestSite'
UseSecurityBestPractices = $false
}
$serviceData = @{
ServiceName = 'PesterTest'
ModulePath = 'C:\Program Files\WindowsPowerShell\DscService\Modules'
ConfigurationPath = 'C:\Program Files\WindowsPowerShell\DscService\Configuration'
RegistrationKeyPath = 'C:\Program Files\WindowsPowerShell\DscService'
dbprovider = 'ESENT'
dbconnectionstr = 'C:\Program Files\WindowsPowerShell\DscService\Devices.edb'
oleDbConnectionstr = 'Data Source=TestDrive:\inetpub\PesterTestSite\Devices.mdb'
}
$websiteDataHTTP = [System.Management.Automation.PSObject] @{
bindings = [System.Management.Automation.PSObject] @{
collection = @(
@{
protocol = 'http'
bindingInformation = '*:8080:'
certificateHash = ''
}
)
}
physicalPath = 'TestDrive:\inetpub\PesterTestSite'
state = 'Started'
}
$websiteDataHTTPS = [System.Management.Automation.PSObject] @{
bindings = [System.Management.Automation.PSObject] @{
collection = @(
@{
protocol = 'https'
bindingInformation = '*:8080:'
certificateHash = 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTT'
}
)
}
physicalPath = 'TestDrive:\inetpub\PesterTestSite'
state = 'Started'
}
$certificateData = @(
[PSCustomObject] @{
Thumbprint = 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTT'
Subject = 'PesterTestCertificate'
Extensions = [System.Array] @(
[PSCustomObject] @{
Oid = [PSCustomObject] @{
FriendlyName = 'Certificate Template Name'
Value = '1.3.6.1.4.1.311.20.2'
}
}
[PSCustomObject] @{}
)
NotAfter = Get-Date
}
[PSCustomObject] @{
Thumbprint = 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTT'
Subject = 'PesterTestDuplicateCertificate'
Extensions = [System.Array] @(
[PSCustomObject] @{
Oid = [PSCustomObject] @{
FriendlyName = 'Certificate Template Name'
Value = '1.3.6.1.4.1.311.20.2'
}
}
[PSCustomObject] @{}
)
NotAfter = Get-Date
}
[PSCustomObject] @{
Thumbprint = 'AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTT'
Subject = 'PesterTestDuplicateCertificate'
Extensions = [System.Array] @(
[PSCustomObject] @{
Oid = [PSCustomObject] @{
FriendlyName = 'Certificate Template Name'
Value = '1.3.6.1.4.1.311.20.2'
}
}
[PSCustomObject] @{}
)
NotAfter = Get-Date
}
)
$certificateData.ForEach{
Add-Member -InputObject $_.Extensions[0] -MemberType ScriptMethod -Name Format -Value {'WebServer'}
}
$cerFileWithSan = "
-----BEGIN CER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SIb3DQEBCwUAA4IBAQBI
MyZvohjsm1wbxJvowp5QrKXvGs8XVl+97zY79h8QqtcZALtIHkZd8rj2Bvkd+qyU
o01rPj7+LS7HzkdqfmDRUxbAnDclOkUTCMskzxon9CzEsizomFyTq4khWh/p+7fE
mR2Rq/kA95aupS4Dm7HcncHn89nw9BKcP7WLgIzjRC3ZBzplEGCCL7aKDv66+dv/
HM2uI47A8kHCFMvaq6O0bjlJfmXvrX8OgVQlRDItiuM+pu9LMkWc0t8U4ekRRQdj
kVIXdpdvNQmud6JHv3OI0HrjtL7Da1dK7Q8qye3qHBzHwva6SMVbMmFC3ACxukBU
v+M0WvuaEOEmAQoYaY6K
-----END CERTIFICATE-----
"
$cerBytes = [System.Text.Encoding]::ASCII.GetBytes($cerFileWithSan)
$cerBytesWithoutSan = [System.Text.Encoding]::ASCII.GetBytes($cerFileWithoutSan)
$cerBytesWithAltTemplateName = [System.Text.Encoding]::ASCII.GetBytes($cerFileWithAltTemplateName)
$cerBytesWithAltTemplateInformation = [System.Text.Encoding]::ASCII.GetBytes($cerFileWithAltTemplateInformation)
$testCertificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($cerBytes)
$testCertificateWithoutSan = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($cerBytesWithoutSan)
$testCertificateWithAltTemplateName = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($cerBytesWithAltTemplateName)
$testCertificateWithAltTemplateInformation = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($cerBytesWithAltTemplateInformation)
$webConfig = @'
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="dbprovider" value="ESENT" />
<add key="dbconnectionstr" value="TestDrive:\DatabasePath\Devices.edb" />
<add key="ModulePath" value="TestDrive:\ModulePath" />
</appSettings>
<system.webServer>
<modules>
<add name="IISSelfSignedCertModule(32bit)" />
</modules>
</system.webServer>
</configuration>
'@
#endregion
Describe -Name "$dscResourceName\Get-TargetResource" -Fixture {
<# Create dummy functions so that Pester is able to mock them #>
function Get-Website {}
function Get-WebBinding {}
$webConfigPath = 'TestDrive:\inetpub\PesterTestSite\Web.config'
$null = New-Item -ItemType Directory -Path (Split-Path -Parent $webConfigPath)
$null = New-Item -Path $webConfigPath -Value $webConfig
Context -Name 'DSC Web Service is not installed' -Fixture {
Mock -CommandName Get-WebSite -MockWith {}
$script:result = $null
It 'Should not throw' {
{$script:result = Get-TargetResource @testParameters} | Should -Not -Throw
Assert-MockCalled -Exactly -Times 1 -CommandName Get-WebSite -Scope It
}
It 'Should return Ensure set to Absent' {
$script:result.Ensure | Should -Be 'Absent'
}
}
#region Mocks
Mock -CommandName Get-WebSite -MockWith {return $websiteDataHTTP}
Mock -CommandName Get-WebBinding -MockWith {return @{CertificateHash = $websiteDataHTTPS.bindings.collection[0].certificateHash}}
Mock -CommandName Get-ChildItem -ParameterFilter {$Path -eq $websiteDataHTTP.physicalPath -and $Filter -eq '*.svc'} -MockWith {return @{Name = $serviceData.ServiceName}}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'ModulePath'} -MockWith {return $serviceData.ModulePath}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'ConfigurationPath'} -MockWith {return $serviceData.ConfigurationPath}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'RegistrationKeyPath'} -MockWith {return $serviceData.RegistrationKeyPath}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'dbprovider'} -MockWith {return $serviceData.dbprovider}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -MockWith {return $serviceData.dbconnectionstr}
#endregion
Context -Name 'DSC Web Service is installed without certificate' -Fixture {
$script:result = $null
$ipProperties = [Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
if ($ipProperties.DomainName)
{
$fqdnComputerName = '{0}.{1}' -f $ipProperties.HostName, $ipProperties.DomainName
}
else
{
$fqdnComputerName = $ipProperties.HostName
}
$testData = @(
@{
Variable = 'EndpointName'
Data = $testParameters.EndpointName
}
@{
Variable = 'Port'
Data = ($websiteDataHTTP.bindings.collection[0].bindingInformation -split ':')[1]
}
@{
Variable = 'PhysicalPath'
Data = $websiteDataHTTP.physicalPath
}
@{
Variable = 'State'
Data = $websiteDataHTTP.state
}
@{
Variable = 'DatabasePath'
Data = Split-Path -Path $serviceData.dbconnectionstr -Parent
}
@{
Variable = 'ModulePath'
Data = $serviceData.ModulePath
}
@{
Variable = 'ConfigurationPath'
Data = $serviceData.ConfigurationPath
}
@{
Variable = 'DSCServerURL'
Data = '{0}://{1}:{2}/{3}' -f $websiteDataHTTP.bindings.collection[0].protocol,
$fqdnComputerName,
($websiteDataHTTP.bindings.collection[0].bindingInformation -split ':')[1],
$serviceData.ServiceName
}
@{
Variable = 'Ensure'
Data = 'Present'
}
@{
Variable = 'RegistrationKeyPath'
Data = $serviceData.RegistrationKeyPath
}
@{
Variable = 'AcceptSelfSignedCertificates'
Data = $true
}
@{
Variable = 'UseSecurityBestPractices'
Data = $false
}
@{
Variable = 'Enable32BitAppOnWin64'
Data = $false
}
)
It 'Should not throw' {
{$script:result = Get-TargetResource @testParameters} | Should -Not -Throw
}
It 'Should return <Variable> set to <Data>' -TestCases $testData {
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Variable,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSObject]
$Data
)
if ($Data -ne $null)
{
$script:result.$Variable | Should -Be $Data
}
else
{
$script:result.$Variable | Should -Be Null
}
}
It 'Should return ''DisableSecurityBestPractices'' set to $null' {
$script:result.DisableSecurityBestPractices | Should -BeNullOrEmpty
}
It 'Should call expected mocks' {
Assert-MockCalled -Exactly -Times 2 -CommandName Get-WebSite
Assert-MockCalled -Exactly -Times 1 -CommandName Get-WebBinding
Assert-MockCalled -Exactly -Times 1 -CommandName Get-ChildItem
Assert-MockCalled -Exactly -Times 5 -CommandName Get-WebConfigAppSetting
}
}
Mock -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -MockWith {return $serviceData.oleDbConnectionstr}
Context -Name 'DSC Web Service is installed and using OleDb' -Fixture {
$serviceData.dbprovider = 'System.Data.OleDb'
$script:result = $null
$testData = @(
@{
Variable = 'DatabasePath'
Data = $serviceData.oleDbConnectionstr
}
)
It 'Should not throw' {
{$script:result = Get-TargetResource @testParameters} | Should -Not -Throw
}
It 'Should return <Variable> set to <Data>' -TestCases $testData {
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Variable,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSObject]
$Data
)
$script:result.$Variable | Should -Be $Data
}
It 'Should call expected mocks' {
Assert-VerifiableMock
Assert-MockCalled -Exactly -Times 1 -CommandName Get-WebConfigAppSetting -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'}
}
}
#region Mocks
Mock -CommandName Get-WebSite -MockWith {return $websiteDataHTTPS}
Mock -CommandName Get-WebBinding -MockWith {return $websiteDataHTTPS.bindings.collection}
Mock -CommandName Get-ChildItem -ParameterFilter {$Path -eq 'Cert:\LocalMachine\My\'} -MockWith {return $certificateData[0]}
Mock -CommandName Get-CertificateTemplateName -MockWith {'WebServer'}
#endregion
Context -Name 'DSC Web Service is installed with certificate using thumbprint' -Fixture {
$altTestParameters = $testParameters.Clone()
$altTestParameters.CertificateThumbPrint = $certificateData[0].Thumbprint
$script:result = $null
$testData = @(
@{
Variable = 'CertificateThumbPrint'
Data = $certificateData[0].Thumbprint
}
@{
Variable = 'CertificateSubject'
Data = $certificateData[0].Subject
}
@{
Variable = 'CertificateTemplateName'
Data = $certificateData[0].Extensions.Where{$_.Oid.FriendlyName -eq 'Certificate Template Name'}.Format($false)
}
)
It 'Should not throw' {
{$script:result = Get-TargetResource @altTestParameters} | Should -Not -Throw
}
It 'Should return <Variable> set to <Data>' -TestCases $testData {
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Variable,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSObject]
$Data
)
if ($Data -ne $null)
{
$script:result.$Variable | Should -Be $Data
}
else
{
$script:result.$Variable | Should -Be Null
}
}
It 'Should call expected mocks' {
Assert-VerifiableMock
Assert-MockCalled -Exactly -Times 2 -CommandName Get-WebSite
Assert-MockCalled -Exactly -Times 1 -CommandName Get-WebBinding
Assert-MockCalled -Exactly -Times 2 -CommandName Get-ChildItem
}
}
Context -Name 'DSC Web Service is installed with certificate using subject' -Fixture {
$altTestParameters = $testParameters.Clone()
$altTestParameters.Remove('CertificateThumbPrint')
$altTestParameters.Add('CertificateSubject', $certificateData[0].Subject)
$script:result = $null
$testData = @(
@{
Variable = 'CertificateThumbPrint'
Data = $certificateData[0].Thumbprint
}
@{
Variable = 'CertificateSubject'
Data = $certificateData[0].Subject
}
@{
Variable = 'CertificateTemplateName'
Data = $certificateData[0].Extensions.Where{$_.Oid.FriendlyName -eq 'Certificate Template Name'}.Format($false)
}
)
It 'Should not throw' {
{$script:result = Get-TargetResource @altTestParameters} | Should -Not -Throw
}
It 'Should return <Variable> set to <Data>' -TestCases $testData {
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Variable,
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSObject]
$Data
)
if ($Data -ne $null)
{
$script:result.$Variable | Should -Be $Data
}
else
{
$script:result.$Variable | Should -Be Null
}
}
It 'Should call expected mocks' {
Assert-VerifiableMock
Assert-MockCalled -Exactly -Times 2 -CommandName Get-WebSite
Assert-MockCalled -Exactly -Times 1 -CommandName Get-WebBinding
Assert-MockCalled -Exactly -Times 2 -CommandName Get-ChildItem
}
}
Context -Name 'Function parameters contain invalid data' -Fixture {
It 'Should throw if CertificateThumbprint and CertificateSubject are not specifed' {
$altTestParameters = $testParameters.Clone()
$altTestParameters.Remove('CertificateThumbPrint')
{$script:result = Get-TargetResource @altTestParameters} | Should -Throw
}
It 'Should throw if CertificateThumbprint and CertificateSubject are both specifed' {
$altTestParameters = $testParameters.Clone()
$altTestParameters.Add('CertificateSubject', $certificateData[0].Subject)
{$script:result = Get-TargetResource @altTestParameters} | Should -Throw
}
}
}
Describe -Name "$dscResourceName\Set-TargetResource" -Fixture {
<# Create dummy functions so that Pester is able to mock them #>
function Get-Website {}
function Get-WebBinding {}
#region Mocks
Mock -CommandName Get-Command -ParameterFilter {$Name -eq '.\appcmd.exe'} -MockWith {
<#
We return a ScriptBlock here, so that the ScriptBlock is called with the parameters which are actually passed to appcmd.exe.
To verify the arguments which are passed to appcmd.exe the property UnboundArguments of $MyInvocation can be used. But
here's a catch: when Powershell parses the arguments into the UnboundArguments it splits arguments which start with -section:
into TWO separate array elements. So -section:system.webServer/globalModules ends up in [-section:, system.webServer/globalModules]
and not as [-section:system.webServer/globalModules]. If the arguments should later be verified in this mock this should be considered.
#>
{
$allowedArgs = @(
'('''' -ne ((& (Get-IISAppCmd) list config -section:system.webServer/globalModules) -like "*$iisSelfSignedModuleName*"))'
'& (Get-IISAppCmd) install module /name:$iisSelfSignedModuleName /image:$destinationFilePath /add:false /lock:false'
'& (Get-IISAppCmd) add module /name:$iisSelfSignedModuleName /app.name:"$EndpointName/" $preConditionBitnessArgumentFor32BitInstall'
'& (Get-IISAppCmd) delete module /name:$iisSelfSignedModuleName /app.name:"$EndpointName/"'
)
$line = $MyInvocation.Line.Trim() -replace '\s+', ' '
if ($allowedArgs -notcontains $line)
{
throw "Mock test failed. Invalid parameters [$line]"
}
}
}
Mock -CommandName Get-OSVersion -MockWith {@{Major = 6; Minor = 3}}
Mock -CommandName Get-Website
#endregion
Context -Name 'DSC Service is not installed and Ensure is Absent' -Fixture {
It 'Should call expected mocks' {
Set-TargetResource @testParameters -Ensure Absent
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Command
}
}
Context -Name 'DSC Service is installed and Ensure is Absent' -Fixture {
#region Mocks
Mock -CommandName Get-Website -MockWith {'Website'}
Mock -CommandName Remove-PSWSEndpoint
#endregion
It 'Should call expected mocks' {
Set-TargetResource @testParameters -Ensure Absent
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Remove-PSWSEndpoint
}
}
#region Mocks
Mock -CommandName Get-Culture -MockWith {@{TwoLetterISOLanguageName = 'en'}}
Mock -CommandName Test-Path -MockWith {$true}
Mock -CommandName New-PSWSEndpoint
Mock -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Mock -CommandName Set-AppSettingsInWebconfig
Mock -CommandName Set-BindingRedirectSettingInWebConfig
Mock -CommandName Copy-Item
Mock -CommandName Test-FilesDiffer -MockWith { $false }
#endregion
Context -Name 'Ensure is Present' -Fixture {
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @testParameters @setTargetPaths -Ensure Present
Assert-MockCalled -Exactly -Times 3 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Culture
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 2 -CommandName Test-Path
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName New-PSWSEndpoint
Assert-MockCalled -Exactly -Times 3 -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Assert-MockCalled -Exactly -Times 5 -CommandName Set-AppSettingsInWebconfig
Assert-MockCalled -Exactly -Times 1 -CommandName Set-BindingRedirectSettingInWebConfig
Assert-MockCalled -Exactly -Times 0 -CommandName Copy-Item
}
$testCases = $setTargetPaths.Keys.ForEach{@{Name = $_; Value = $setTargetPaths.$_}}
It 'Should create the <Name> directory' -TestCases $testCases {
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,
[Parameter(Mandatory = $true)]
[System.String]
$Value
)
Set-TargetResource @testParameters @setTargetPaths -Ensure Present
Test-Path -Path $Value | Should -Be $true
}
}
Context -Name 'Ensure is Present - isDownLevelOfBlue' -Fixture {
#region Mocks
Mock -CommandName Get-OSVersion -MockWith {@{Major = 6; Minor = 2}}
#endregion
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @testParameters @setTargetPaths -Ensure Present
Assert-MockCalled -Exactly -Times 3 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Culture
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 2 -CommandName Test-Path
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName New-PSWSEndpoint
Assert-MockCalled -Exactly -Times 3 -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Assert-MockCalled -Exactly -Times 5 -CommandName Set-AppSettingsInWebconfig
Assert-MockCalled -Exactly -Times 0 -CommandName Set-BindingRedirectSettingInWebConfig
Assert-MockCalled -Exactly -Times 1 -CommandName Copy-Item
}
}
Context -Name 'Ensure is Present - isUpLevelOfBlue' -Fixture {
#region Mocks
Mock -CommandName Get-OSVersion -MockWith {@{Major = 10; Minor = 0}}
#endregion
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @testParameters @setTargetPaths -Ensure Present
Assert-MockCalled -Exactly -Times 3 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Culture
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 2 -CommandName Test-Path
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName New-PSWSEndpoint
Assert-MockCalled -Exactly -Times 3 -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Assert-MockCalled -Exactly -Times 5 -CommandName Set-AppSettingsInWebconfig
Assert-MockCalled -Exactly -Times 0 -CommandName Set-BindingRedirectSettingInWebConfig
Assert-MockCalled -Exactly -Times 0 -CommandName Copy-Item
}
}
Context -Name 'Ensure is Present - Enable32BitAppOnWin64' -Fixture {
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @testParameters @setTargetPaths -Ensure Present -Enable32BitAppOnWin64 $true
Assert-MockCalled -Exactly -Times 3 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Culture
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 2 -CommandName Test-Path
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName New-PSWSEndpoint
Assert-MockCalled -Exactly -Times 3 -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Assert-MockCalled -Exactly -Times 5 -CommandName Set-AppSettingsInWebconfig
Assert-MockCalled -Exactly -Times 1 -CommandName Set-BindingRedirectSettingInWebConfig
Assert-MockCalled -Exactly -Times 1 -CommandName Copy-Item
}
}
Context -Name 'Ensure is Present - AcceptSelfSignedCertificates is $false' -Fixture {
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @testParameters @setTargetPaths -Ensure Present -AcceptSelfSignedCertificates $false
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Command
Assert-MockCalled -Exactly -Times 1 -CommandName Get-Culture
Assert-MockCalled -Exactly -Times 0 -CommandName Get-Website
Assert-MockCalled -Exactly -Times 1 -CommandName Test-Path
Assert-MockCalled -Exactly -Times 1 -CommandName Get-OSVersion
Assert-MockCalled -Exactly -Times 1 -CommandName New-PSWSEndpoint
Assert-MockCalled -Exactly -Times 3 -CommandName Update-LocationTagInApplicationHostConfigForAuthentication
Assert-MockCalled -Exactly -Times 5 -CommandName Set-AppSettingsInWebconfig
Assert-MockCalled -Exactly -Times 1 -CommandName Set-BindingRedirectSettingInWebConfig
Assert-MockCalled -Exactly -Times 0 -CommandName Copy-Item
}
}
Context -Name 'Ensure is Present - UseSecurityBestPractices is $true' -Fixture {
$altTestParameters = $testParameters.Clone()
$altTestParameters.UseSecurityBestPractices = $true
It 'Should throw an error because no certificate specified' {
$message = "Error: Cannot use best practice security settings with unencrypted traffic. Please set UseSecurityBestPractices to `$false or use a certificate to encrypt pull server traffic."
{Set-TargetResource @altTestParameters -Ensure Present} | Should -Throw -ExpectedMessage $message
}
}
#region Mocks
Mock -CommandName Find-CertificateThumbprintWithSubjectAndTemplateName -MockWith {$certificateData[0].Thumbprint}
#endregion
Context -Name 'Ensure is Present - CertificateSubject' -Fixture {
$altTestParameters = $testParameters.Clone()
$altTestParameters.Remove('CertificateThumbPrint')
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should call expected mocks' {
Set-TargetResource @altTestParameters @setTargetPaths -Ensure Present -CertificateSubject 'PesterTestCertificate'
Assert-MockCalled -Exactly -Times 1 -CommandName Find-CertificateThumbprintWithSubjectAndTemplateName
}
}
Context -Name 'Ensure is Present - CertificateThumbprint and UseSecurityBestPractices is $true' -Fixture {
#region Mocks
Mock -CommandName Set-UseSecurityBestPractice
#endregion
$altTestParameters = $testParameters.Clone()
$altTestParameters.UseSecurityBestPractices = $true
$altTestParameters.CertificateThumbPrint = $certificateData[0].Thumbprint
$setTargetPaths = @{
DatabasePath = 'TestDrive:\Database'
ConfigurationPath = 'TestDrive:\Configuration'
ModulePath = 'TestDrive:\Module'
RegistrationKeyPath = 'TestDrive:\RegistrationKey'
}
It 'Should not throw an error' {
{Set-TargetResource @altTestParameters @setTargetPaths -Ensure Present} | Should -Not -throw
}
It 'Should call expected mocks' {
Assert-MockCalled -Exactly -Times 0 -CommandName Find-CertificateThumbprintWithSubjectAndTemplateName
Assert-MockCalled -Exactly -Times 1 -CommandName Set-UseSecurityBestPractice
}
}
Context -Name 'Function parameters contain invalid data' -Fixture {
It 'Should throw if CertificateThumbprint and CertificateSubject are not specifed' {
$altTestParameters = $testParameters.Clone()
$altTestParameters.Remove('CertificateThumbPrint')
{Set-TargetResource @altTestParameters} | Should -Throw
}
}
}
Describe -Name "$dscResourceName\Test-TargetResource" -Fixture {
function Get-Website {}
function Get-WebBinding {}
#region Mocks
Mock -CommandName Get-Command -ParameterFilter {$Name -eq '.\appcmd.exe'} -MockWith {
{
$allowedArgs = @(
'('''' -ne ((& (Get-IISAppCmd) list config -section:system.webServer/globalModules) -like "*$iisSelfSignedModuleName*"))'
)
$line = $MyInvocation.Line.Trim() -replace '\s+', ' '
if ($allowedArgs -notcontains $line)
{
throw "Mock test failed. Invalid parameters [$line]"
}
}
}
#endregion
Context -Name 'DSC Service is not installed' -Fixture {
Mock -CommandName Get-Website
It 'Should return $true when Ensure is Absent' {
Test-TargetResource @testParameters -Ensure Absent | Should -Be $true
}
It 'Should return $false when Ensure is Present' {
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
}
}
Context -Name 'DSC Web Service is installed as HTTP' -Fixture {
Mock -CommandName Get-Website -MockWith {$WebsiteDataHTTP}
It 'Should return $false when Ensure is Absent' {
Test-TargetResource @testParameters -Ensure Absent | Should -Be $false
}
It 'Should return $false if Port doesn''t match' {
Test-TargetResource @testParameters -Ensure Present -Port 8081 | Should -Be $false
}
It 'Should return $false if Certificate Thumbprint is set' {
$altTestParameters = $testParameters.Clone()
$altTestParameters.CertificateThumbprint = $certificateData[0].Thumbprint
Test-TargetResource @altTestParameters -Ensure Present | Should -Be $false
}
It 'Should return $false if Physical Path doesn''t match' {
Mock -CommandName Test-WebsitePath -MockWith {$true} -Verifiable
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
Assert-VerifiableMock
}
Mock -CommandName Get-WebBinding -MockWith {return @{CertificateHash = $websiteDataHTTPS.bindings.collection[0].certificateHash}}
Mock -CommandName Test-WebsitePath -MockWith {$false} -Verifiable
It 'Should return $false when State is set to Stopped' {
Test-TargetResource @testParameters -Ensure Present -State Stopped | Should -Be $false
Assert-VerifiableMock
}
It 'Should return $false when dbProvider is not set' {
Mock -CommandName Get-WebConfigAppSetting -MockWith {''} -Verifiable
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
Assert-VerifiableMock
}
Mock -CommandName Test-WebConfigAppSetting -MockWith {Write-Verbose -Message 'Test-WebConfigAppSetting'; $true}
It 'Should return $true when dbProvider is set to ESENT and ConnectionString does not match the value in web.config' {
$DatabasePath = 'TestDrive:\DatabasePath'
Mock -CommandName Get-WebConfigAppSetting -MockWith {'ESENT'} -Verifiable
Mock -CommandName Test-WebConfigAppSetting -MockWith {param ($ExpectedAppSettingValue) Write-Verbose -Message 'Test-WebConfigAppSetting - dbconnectionstr (ESENT)'; ('{0}\Devices.edb' -f $DatabasePath) -eq $ExpectedAppSettingValue} -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -Verifiable
Test-TargetResource @testParameters -Ensure Present -DatabasePath $DatabasePath | Should -Be $true
Assert-VerifiableMock
}
It 'Should return $false when dbProvider is set to ESENT and ConnectionString does match the value in web.config' {
Mock -CommandName Get-WebConfigAppSetting -MockWith {'ESENT'} -Verifiable
Mock -CommandName Test-WebConfigAppSetting -MockWith {Write-Verbose -Message 'Test-WebConfigAppSetting - dbconnectionstr (ESENT)'; $false} -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -Verifiable
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
Assert-VerifiableMock
}
It 'Should return $true when dbProvider is set to System.Data.OleDb and ConnectionString does not match the value in web.config' {
$DatabasePath = 'TestDrive:\DatabasePath'
Mock -CommandName Get-WebConfigAppSetting -MockWith {'System.Data.OleDb'} -Verifiable
Mock -CommandName Test-WebConfigAppSetting -MockWith {param ($ExpectedAppSettingValue) Write-Verbose -Message 'Test-WebConfigAppSetting - dbconnectionstr (OLE)'; ('Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\Devices.mdb;' -f $DatabasePath) -eq $ExpectedAppSettingValue} -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -Verifiable
Test-TargetResource @testParameters -Ensure Present -DatabasePath $DatabasePath | Should -Be $true
Assert-VerifiableMock
}
It 'Should return $false when dbProvider is set to System.Data.OleDb and ConnectionString does match the value in web.config' {
Mock -CommandName Get-WebConfigAppSetting -MockWith {'System.Data.OleDb'} -Verifiable
Mock -CommandName Test-WebConfigAppSetting -MockWith {Write-Verbose -Message 'Test-WebConfigAppSetting - dbconnectionstr (OLE)'; $false} -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -Verifiable
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
Assert-VerifiableMock
}
Mock -CommandName Get-WebConfigAppSetting -MockWith {'ESENT'} -Verifiable
Mock -CommandName Test-WebConfigAppSetting -MockWith {$true} -ParameterFilter {$AppSettingName -eq 'dbconnectionstr'} -Verifiable
It 'Should return $true when ModulePath is set the same as in web.config' {
$modulePath = 'TestDrive:\ModulePath'
Mock -CommandName Test-WebConfigAppSetting -MockWith {param ($ExpectedAppSettingValue) Write-Verbose -Message 'Test-WebConfigAppSetting - ModulePath'; $modulePath -eq $ExpectedAppSettingValue} -ParameterFilter {$AppSettingName -eq 'ModulePath'} -Verifiable
Test-TargetResource @testParameters -Ensure Present -ModulePath $modulePath | Should -Be $true
Assert-VerifiableMock
}
It 'Should return $false when ModulePath is not set the same as in web.config' {
Mock -CommandName Test-WebConfigAppSetting -MockWith {Write-Verbose -Message 'Test-WebConfigAppSetting - ModulePath'; $false} -ParameterFilter {$AppSettingName -eq 'ModulePath'} -Verifiable
Test-TargetResource @testParameters -Ensure Present | Should -Be $false
Assert-VerifiableMock
}
Mock -CommandName Test-WebConfigAppSetting -MockWith {$true} -ParameterFilter {$AppSettingName -eq 'ModulePath'} -Verifiable
It 'Should return $true when ConfigurationPath is set the same as in web.config' {
$configurationPath = 'TestDrive:\ConfigurationPath'
Mock -CommandName Test-WebConfigAppSetting -MockWith {param ($ExpectedAppSettingValue) Write-Verbose -Message 'Test-WebConfigAppSetting - ConfigurationPath'; $configurationPath -eq $ExpectedAppSettingValue} -ParameterFilter {$AppSettingName -eq 'ConfigurationPath'} -Verifiable
Test-TargetResource @testParameters -Ensure Present -ConfigurationPath $configurationPath | Should -Be $true