-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-PASPlatformPackage.Tests.ps1
101 lines (85 loc) · 4.77 KB
/
New-PASPlatformPackage.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
BeforeAll {
. .\New-PASPlatformPackage.ps1
}
Describe 'New-PASPlatformPackage' {
BeforeAll {
# Set the generic details for the test
$PlatformId = 'SamplePlatform'
$CreatedArchivePath = Join-Path -Path $TestDrive -ChildPath "$PlatformId.zip"
$ExpandedArchivePath = Join-Path -Path $TestDrive -ChildPath $PlatformId
$CPMPolicyFile = Join-Path -Path $TestDrive -ChildPath "my-platforms-cpm-settings.ini"
$PVWASettingsFile = Join-Path -Path $TestDrive -ChildPath "my-platforms-pvwa-settings.xml"
# Create dummy files for the required platform files.
Out-File -Path $CPMPolicyFile -Force
Out-File -Path $PVWASettingsFile -Force
# Create a directory and populate it for optional platform files
$BuildDirectory = Join-Path -Path $TestDrive -ChildPath 'Build'
New-Item -Path $BuildDirectory -ItemType Directory
Out-File -Path (Join-Path -Path $BuildDirectory -ChildPath 'Prompts.ini') -Force
Out-File -Path (Join-Path -Path $BuildDirectory -ChildPath 'Processes.ini') -Force
Get-ChildItem -Path $BuildDirectory `
| New-PASPlatformPackage -PlatformId $PlatformId `
-CPMPolicyFile $CPMPolicyFile `
-PVWASettingsFile $PVWASettingsFile `
-DestinationPath $TestDrive
# Expand the archive as the tests depend on it.
Expand-Archive $CreatedArchivePath -DestinationPath $ExpandedArchivePath
}
Context 'when creating the package' {
It 'accepts the plug-in files from the pipeline' -ForEach 'Processes.ini', 'Prompts.ini' {
Test-Path -Path (Join-Path -Path $TestDrive -ChildPath $PlatformId -AdditionalChildPath "$_") | Should -Be $true
}
It 'it must contain a <Type> file named <Name>' {
Test-Path -Path (Join-Path -Path $TestDrive -ChildPath $PlatformId -AdditionalChildPath $Name) | Should -Be $true
} -ForEach @(
@{Type = 'CPM policy'; Name = "Policy-SamplePlatform.ini" }
@{Type = 'PVWA settings'; Name = "Policy-SamplePlatform.xml" }
)
}
Context 'when creating the PVWA settings file' {
BeforeAll {
$PlatformId = 'CyberArk'
$CreatedArchivePath = Join-Path -Path $TestDrive -ChildPath "$PlatformId.zip"
$ExpandedArchivePath = Join-Path -Path $TestDrive -ChildPath $PlatformId
$ExpectedPVWASettingsPath = Join-Path -Path $ExpandedArchivePath -ChildPath "Policy-$PlatformId.xml"
$CPMPolicyFile = Join-Path -Path $TestDrive -ChildPath "my-platforms-cpm-settings.ini"
Out-File -Path $CPMPolicyFile -Force
Copy-Item *.xml -Destination $TestDrive -Force
$DestinationPath = Join-Path -Path $TestDrive -ChildPath (New-Guid)
New-Item -Path $DestinationPath -ItemType Directory
New-PASPlatformPackage `
-PlatformId $PlatformId `
-CPMPolicyFile $CPMPolicyFile `
-ExtractPVWASettings $true `
-ExtractPlatform 'WinServerLocal' `
-PoliciesFile (Join-Path -Path $TestDrive -ChildPath 'Policies.xml') `
-DestinationPath $TestDrive `
-OverwritePolicyIds $true
Expand-Archive -Path $CreatedArchivePath -DestinationPath $ExpandedArchivePath
}
It 'names the PVWA settings file based on the platformid' {
Test-Path -Path $ExpectedPVWASettingsPath | Should -Be $true
}
It 'can create it based on an existing Policies.xml' {
[xml]$PlatformSettingsXml = Get-Content $ExpectedPVWASettingsPath
Select-Xml $PlatformSettingsXml -XPath "//Policies/Policy[@ID='CyberArk']/PrivilegedSessionManagement[@ID='PSMServer_2ab6ce8']" | Should -Be $true
}
}
}
Describe 'Get-PlatformPVWASettings' {
It 'extracts the PVWA settings for a <PlatformType> out of an existing Policies.xml' {
$PlatformSettings = Get-PlatformPVWASettings -PoliciesFile '.\Policies.xml' -PlatformId $PlatformId
$PlatformSettingsXml = [xml]$PlatformSettings
Select-Xml -Xml $PlatformSettingsXml -XPath "//$PlatformType[@ID='$PlatformId']" | Should -Be $true
} -ForEach @(
@{PlatformType = 'Usage'; PlatformId = 'INIFile' }
@{PlatformType = 'Policy'; PlatformId = 'CyberArk' }
)
Context 'when getting the PVWA settings for a Policy' {
It 'puts the PVWA settings as a child node to a policies node which is a child to a device node' {
$PlatformSettings = Get-PlatformPVWASettings -PoliciesFile '.\Policies.xml' -PlatformId CyberArk
$PlatformSettingsXml = [xml]$PlatformSettings
Select-Xml -Xml $PlatformSettingsXml -XPath "//Device[@Name='Application']/Policies/Policy[@ID='CyberArk']" | Should -Be $true
}
}
}