-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompendium.AclHelpers.Tests.ps1
66 lines (57 loc) · 2.3 KB
/
Compendium.AclHelpers.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
BeforeAll {
$ModuleRoot = $($PSCommandPath.Replace('.Tests.ps1', '').Replace('tests', 'src'))
Import-Module -name $ModuleRoot
}
AfterAll {
$ModuleRoot = $($PSCommandPath.Replace('.Tests.ps1', '').Replace('tests', 'src'))
$ModuleName = Split-Path $ModuleRoot -Leaf
Remove-Module -Name $ModuleName
}
Describe "Compendium.AclHelpers functions" {
It "sould export Protect-File" {
Get-Command -Name 'Protect-File' | Should -BeTrue
}
It "should export Enable-AclInheritance" {
Get-Command -Name 'Enable-AclInheritance' | Should -BeTrue
}
}
Describe "Compendium.AclHelpers Protect-File" {
BeforeAll {
$TestFile = 'TestDrive:\key.pem'
New-Item -Path $TestFile -Value 'Pester Test' -ItemType 'File'
Protect-File -Path $TestFile
$Acl = Get-Acl -Path $TestFile
}
It "should disable inheritance" {
$Acl.AreAccessRulesProtected | Should -BeTrue
}
It "should have one access rule" {
$Acl.GetAccessRules($True, $True, [System.Security.Principal.NTAccount]).Count | Should -Be 1
}
it "should grant owner full control" {
$Rule = $Acl.GetAccessRules($True, $True, [System.Security.Principal.NTAccount])[0]
$Rule.IdentityReference | Should -Be $Acl.Owner
$Rule.FileSystemRights | Should -Be 'FullControl'
}
}
Describe "Compendium.AclHelpers Enable-AclInheritance" {
Context "Compendium.AclHelpers Module" {
BeforeAll {
$ModuleRoot = $($PSCommandPath.Replace('.Tests.ps1', '').Replace('tests', 'src'))
$ModuleName = Split-Path $ModuleRoot -Leaf
Mock -ModuleName $ModuleName Set-Acl {} -Verifiable -ParameterFilter {
$AclObject.AreAccessRulesProtected -eq $False
}
$TestPath = 'TestDrive:\keys\key.pem'
$TestFile = 'key.pem'
$FullFilePath = Join-Path -Path $TestPath -ChildPath $TestFile
New-Item -Path $TestPath -ItemType 'Directory'
New-Item -Path $TestPath -Name $TestFile -Value 'Pester Test' -ItemType 'File'
Protect-File -Path $FullFilePath
Enable-AclInheritance -Path $TestPath -Recurse
}
It "should enable inheritance" {
Should -Invoke Set-Acl -ModuleName $ModuleName -Times 1 -Scope Context
}
}
}