forked from PowerShell/PSScriptAnalyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvoidUsingAllowUnencryptedAuthentication.tests.ps1
38 lines (32 loc) · 1.56 KB
/
AvoidUsingAllowUnencryptedAuthentication.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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
BeforeAll {
$settings = @{
IncludeRules = @('PSAvoidUsingAllowUnencryptedAuthentication')
Rules = @{
PSAvoidUsingAllowUnencryptedAuthentication = @{
Enable = $true
}
}
}
}
Describe "AvoidUsingAllowUnencryptedAuthentication" {
Context "When there are violations" {
It "detects unencrypted authentication violations" {
(Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-WebRequest foo -AllowUnencryptedAuthentication' -Settings $settings).Count | Should -Be 1
(Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-RestMethod foo -AllowUnencryptedAuthentication' -Settings $settings).Count | Should -Be 1
(Invoke-ScriptAnalyzer -ScriptDefinition 'iwr foo -AllowUnencryptedAuthentication' -Settings $settings).Count | Should -Be 1
}
It "detects arbitrary cmdlets" {
(Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-CustomWebRequest foo -AllowUnencryptedAuthentication' -Settings $settings).Count | Should -Be 1
}
}
Context "When there are no violations" {
It "does not flag safe usage" {
(Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-WebRequest foo' -Settings $settings).Count | Should -Be 0
}
It "does not flag cases with unrelated parameters" {
(Invoke-ScriptAnalyzer -ScriptDefinition 'Invoke-WebRequest foo -Method Get' -Settings $settings).Count | Should -Be 0
}
}
}