Skip to content

Commit cd06cd5

Browse files
authored
Adds common unit tests (#313)
* fixed spelling * rem extra return * moved to common tests * added tests * added remaining tests * rem spaces * update registry rule path * updated exclude list * added PR feedback
1 parent 9caf6f4 commit cd06cd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1222
-3171
lines changed

Module/Rule.AccountPolicy/AccountPolicyRule.psm1

+18
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,28 @@ Class AccountPolicyRule : Rule
1919
[string] $PolicyName
2020
[string] $PolicyValue <#(ExceptionValue)#>
2121

22+
<#
23+
.SYNOPSIS
24+
Default constructor to support the AsRule cast method
25+
#>
2226
AccountPolicyRule () {}
2327

28+
<#
29+
.SYNOPSIS
30+
The Convert child class constructor
31+
.PARAMETER Rule
32+
The STIG rule to convert
33+
.PARAMETER Convert
34+
A simple bool flag to create a unique constructor signature
35+
#>
2436
AccountPolicyRule ([xml.xmlelement] $Rule, [bool] $Convert) : Base ($Rule, $Convert) {}
2537

38+
<#
39+
.SYNOPSIS
40+
Used to load PowerSTIG data from the processed data directory
41+
.PARAMETER Rule
42+
The STIG rule to load
43+
#>
2644
AccountPolicyRule ([xml.xmlelement] $Rule) : Base ($Rule)
2745
{
2846
$this.PolicyName = $Rule.PolicyName

Module/Rule.AuditPolicy/AuditPolicyRule.psm1

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Class AuditPolicyRule : Rule
3434
.PARAMETER Rule
3535
The STIG rule to convert
3636
.PARAMETER Convert
37-
A simple bool falg to create a unique constructor signature
37+
A simple bool flag to create a unique constructor signature
3838
#>
3939
AuditPolicyRule ([xml.xmlelement] $Rule, [bool] $Convert) : Base ($Rule, $Convert) {}
4040

@@ -67,10 +67,9 @@ Class AuditPolicyRule : Rule
6767
$value = 'Absent'
6868
}
6969

70-
$return = @{
70+
return @{
7171
Value = $value
7272
Notes = "'Present' and 'Absent' are the only valid values"
7373
}
74-
return $return
7574
}
7675
}

Module/Rule.AuditPolicy/Convert/AuditPolicyRule.Convert.psm1

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ Class AuditPolicyRuleConvert : AuditPolicyRule
4747
#>
4848
[RegularExpressions.MatchCollection] ExtractProperties ()
4949
{
50-
$regex = [regex]::Matches(
50+
return [regex]::Matches(
5151
$this.RawString,
5252
'(?:(?:\w+(?:\s|\/))+(?:(?:>|-)>(?:\s+)?))(?<subcategory>(?:\w+\s)+)(?:-(?:\s+)?)(?<auditflag>(?:\w+)+)'
5353
)
54-
55-
return $regex
5654
}
5755

5856
<#

Module/Rule.Document/DocumentRule.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ using module .\..\Rule\Rule.psm1
66

77
<#
88
.SYNOPSIS
9-
An Account Policy Rule object
9+
An Document Rule object
1010
.DESCRIPTION
11-
The DocumentRule class is used to maange the Account Policy Settings.
11+
The DocumentRule class is used to maange the Document Settings.
1212
1313
#>
1414
Class DocumentRule : Rule

Module/Rule.ProcessMitigation/Convert/ProcessMitigationRule.Convert.psm1

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Class ProcessMitigationRuleConvert : ProcessMitigationRule
3939
.PARAMETER XccdfRule
4040
The STIG rule to convert
4141
#>
42-
hidden ProcessMitigationRuleConvert ([xml.xmlelement] $XccdfRule) : Base ($XccdfRule, $true)
42+
ProcessMitigationRuleConvert ([xml.xmlelement] $XccdfRule) : Base ($XccdfRule, $true)
4343
{
44-
$this.SetMitigationTargetName()
44+
$this.SetMitigationTarget()
4545
$this.SetMitigationToEnable()
4646
if ($this.conversionstatus -eq 'pass')
4747
{
@@ -64,13 +64,13 @@ Class ProcessMitigationRuleConvert : ProcessMitigationRule
6464
value. If the mitigation target name that is returned is not valid,
6565
the parser status is set to fail
6666
#>
67-
[void] SetMitigationTargetName ()
67+
[void] SetMitigationTarget ()
6868
{
69-
$thisMitigationTargetName = Get-MitigationTargetName -CheckContent $this.SplitCheckContent
69+
$thisMitigationTarget = Get-MitigationTargetName -CheckContent $this.SplitCheckContent
7070

71-
if (-not $this.SetStatus($thisMitigationTargetName))
71+
if (-not $this.SetStatus($thisMitigationTarget))
7272
{
73-
$this.set_MitigationTarget($thisMitigationTargetName)
73+
$this.set_MitigationTarget($thisMitigationTarget)
7474
}
7575
}
7676

Module/Rule.Registry/Convert/RegistryRule.Convert.psm1

-3
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,7 @@ Class RegistryRuleConvert : RegistryRule
365365
(
366366
$CheckContent -Match "HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER" -and
367367
$CheckContent -NotMatch "Permission(s|)" -and
368-
# removed for Server 2012R2 V2R14 change on rule id V-21954
369-
#$CheckContent -NotMatch "SupportedEncryptionTypes" -and
370368
$CheckContent -NotMatch "Sql Server" -and
371-
$CheckContent -NotMatch "v1607 of Windows 10" -and
372369
$CheckContent -NotMatch "Review the Catalog" -and
373370
$CheckContent -NotMatch "For 32.bit (production systems|applications)" -and
374371
$CheckContent -NotMatch 'If the "AllowStrongNameBypass" registry key' -and

Module/Rule.Registry/RegistryRule.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Class RegistryRule : Rule
4343
.PARAMETER Rule
4444
The STIG rule to convert
4545
.PARAMETER Convert
46-
A simple bool falg to create a unique constructor signature
46+
A simple bool flag to create a unique constructor signature
4747
#>
4848
RegistryRule ([xml.xmlelement] $Rule, [bool] $Convert) : Base ($Rule, $Convert) {}
4949

Module/Rule.WebAppPool/Convert/Methods.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Get-KeyValuePair
7272
.PARAMETER Key
7373
Key property from the WebAppPoolrule.
7474
#>
75-
function Get-OrganizationValueTestString
75+
function Get-WebAppPoolOrganizationValueTestString
7676
{
7777
[CmdletBinding()]
7878
[OutputType([string])]
@@ -83,6 +83,7 @@ function Get-OrganizationValueTestString
8383
$Key
8484
)
8585

86+
# TO DO - This should not be a static list
8687
switch ( $Key )
8788
{
8889
{ $PsItem -match 'idleTimeout' }

Module/Rule.WebAppPool/Convert/WebAppPoolRule.Convert.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Class WebAppPoolRuleConvert : WebAppPoolRule
102102
#>
103103
[void] SetOrganizationValueTestString ()
104104
{
105-
$thisOrganizationValueTestString = Get-OrganizationValueTestString -Key $this.key
105+
$thisOrganizationValueTestString = Get-WebAppPoolOrganizationValueTestString -Key $this.key
106106

107107
if (-not $this.SetStatus($thisOrganizationValueTestString))
108108
{

Module/Rule.WebConfigurationProperty/Convert/Methods.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ function Split-MultipleWebConfigurationPropertyRule
422422
.PARAMETER Key
423423
Key property from the WebConfigurationPropertyRule.
424424
#>
425-
function Get-OrganizationValueTestString
425+
function Get-WebConfigOrganizationValueTestString
426426
{
427427
[CmdletBinding()]
428428
[OutputType([string])]
@@ -432,7 +432,7 @@ function Get-OrganizationValueTestString
432432
[string]
433433
$Key
434434
)
435-
435+
# TO DO - This should not be a static list
436436
switch ( $Key )
437437
{
438438
{ $PsItem -match 'maxUrl' }

Module/Rule.WebConfigurationProperty/Convert/WebConfigurationPropertyRule.Convert.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Class WebConfigurationPropertyRuleConvert : WebConfigurationPropertyRule
123123
#>
124124
[void] SetOrganizationValueTestString ()
125125
{
126-
$thisOrganizationValueTestString = Get-OrganizationValueTestString -Key $this.key
126+
$thisOrganizationValueTestString = Get-WebConfigOrganizationValueTestString -Key $this.key
127127

128128
if (-not $this.SetStatus($thisOrganizationValueTestString))
129129
{
File renamed without changes.
File renamed without changes.

Module/Rule/Rule.psm1

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License.
33
using module .\..\Common\Common.psm1
44

5-
$exclude = @($MyInvocation.MyCommand.Name,'Template.*.txt', '*.md', '*.psm1')
5+
$exclude = @($MyInvocation.MyCommand.Name,'Template.*.txt', '*.md', '*.psm1', 'data.*.ps1')
66
$supportFileList = Get-ChildItem -Path $PSScriptRoot -Recurse -File -Exclude $exclude
77
foreach ($supportFile in $supportFileList)
88
{
@@ -55,7 +55,6 @@ Class Rule : ICloneable
5555
[string] $RawString
5656
hidden [string[]] $SplitCheckContent
5757

58-
5958
<#
6059
.SYNOPSIS
6160
Default constructor

Module/STIG/Convert/Data.Windows.Defender.ps1

-23
This file was deleted.

Module/STIG/Convert/Functions.XccdfXml.ps1

+8-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,14 @@ function Get-RegistryRuleExpressions
167167
Process
168168
{
169169
# Load specific and core expression sets
170-
$spSupportFileList = Get-ChildItem -Path $PSScriptRoot -Exclude $spExclude -Recurse -Include $spInclude | Sort-Object -Descending
170+
$childItemParams = @{
171+
Path = "$PSScriptRoot\..\..\Rule\Convert"
172+
Exclude = $spExclude
173+
Include = $spInclude
174+
Recurse = $true
175+
}
176+
177+
$spSupportFileList = Get-ChildItem @childItemParams | Sort-Object -Descending
171178
Clear-Variable SingleLine* -Scope Global
172179
foreach ($supportFile in $spSupportFileList)
173180
{

0 commit comments

Comments
 (0)