Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PowerSTIG to Provide Rule Data from Processed xml #777

Merged
merged 15 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

* Update PowerSTIG to Provide Rule Data from Processed xml: [#747](https://github.com/microsoft/PowerStig/issues/747)
* Update PowerSTIG to send a warning to the user when using a composite that leverages the new DISA Ids: [#772](https://github.com/microsoft/PowerStig/issues/772)
* Update PowerSTIG to successfully parse/apply Microsoft Office System 2013 STIG - Ver 2, Rel 1: [#769](https://github.com/microsoft/PowerStig/issues/769)
* Update PowerSTIG to successfully parse/apply Microsoft Windows 2012 Server DNS STIG - Ver 2, Rel 1: [#760](https://github.com/microsoft/PowerStig/issues/760)
Expand Down
12 changes: 11 additions & 1 deletion Tests/Integration/Module/PowerStig.Integration.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ Describe "$moduleName module" {
Context 'Exported Commands' {

$commands = (Get-Command -Module $moduleName).Name
$exportedCommands = @('Get-DomainName', 'Get-Stig', 'New-StigCheckList', 'Get-StigRuleList', 'Get-StigVersionNumber', 'Get-PowerStigFileList', 'Split-BenchmarkId')
$exportedCommands = @(
'Get-DomainName',
'Get-Stig',
'New-StigCheckList',
'Get-StigRuleList',
'Get-StigVersionNumber',
'Get-PowerStigFileList',
'Split-BenchmarkId',
'Get-StigRule',
'Get-StigRuleExceptionString'
)

foreach ($export in $exportedCommands)
{
Expand Down
12 changes: 10 additions & 2 deletions Tests/Unit/Module/.tests.header.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ switch ($psStackCommand)
. $functionDomainName
}

'STIG.RuleQuery'
{
$functionRuleQuery = Join-Path -Path $script:moduleRoot -ChildPath '\Module\STIG\Functions.RuleQuery.ps1'
. $functionRuleQuery
}

'STIG.PowerStigXml'
{
$functionPowerStigXml = Join-Path -Path $script:moduleRoot -ChildPath '\Module\STIG\Convert\Functions.PowerStigXml.ps1'
Expand All @@ -84,7 +90,6 @@ switch ($psStackCommand)
[void] $setDynamicClassFileParams.Add('ClassModuleFileName', @('Rule.psm1', 'ConvertFactory.psm1','DocumentRule.Convert.psm1','Stig.psm1'))
}


'STIG'
{
$destinationPath = Join-Path -Path $PSScriptRoot -ChildPath '..\.DynamicClassImport\Convert.Main.ps1'
Expand All @@ -101,7 +106,10 @@ switch ($psStackCommand)
}
}

if ($global:moduleName -ne 'STIG.Checklist' -and $global:moduleName -ne 'STIG.DomainName')
if
(
$global:moduleName -notmatch 'STIG.(Checklist|DomainName|RuleQuery)'
)
{
Set-DynamicClassFile @setDynamicClassFileParams
. $setDynamicClassFileParams.DestinationPath
Expand Down
86 changes: 86 additions & 0 deletions Tests/Unit/Module/STIG.RuleQuery.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#region Header
. $PSScriptRoot\.tests.header.ps1
#endregion

$xmlTestData = @'
<DISASTIG version="1" classification="UNCLASSIFIED" customname="" stigid="TestSTIGData" description="Test STIG Data" filename="U_Test_Data_STIG_V1R1_Manual-xccdf.xml" releaseinfo="Release: 1 Benchmark Date: 14 Nov 2016" title="Test STIG Data Security Technical Implementation Guide" notice="terms-of-use" source="STIG.DOD.MIL" fullversion="1.1" created="9/6/2019">
<RegistryRule dscresourcemodule="PSDscResources">
<Rule id="V-1000" severity="medium" conversionstatus="pass" title="SRG-APP-000000" dscresource="Registry">
<Description>&lt;VulnDiscussion&gt;Test STIG Description&lt;/VulnDiscussion&gt;&lt;</Description>
<DuplicateOf />
<Ensure>Present</Ensure>
<IsNullOrEmpty>False</IsNullOrEmpty>
<Key>HKEY_LOCAL_MACHINE\Software\Microsoft\TestKeyData</Key>
<OrganizationValueRequired>False</OrganizationValueRequired>
<OrganizationValueTestString />
<RawString>Test Data RawString</RawString>
<ValueData>TestValueData</ValueData>
<ValueName>TestValueName</ValueName>
<ValueType>String</ValueType>
</Rule>
</RegistryRule>
</DISASTIG>
'@

$exceptionString = "V-1000 = @{Ensure = 'Present'; Key = 'HKEY_LOCAL_MACHINE\Software\Microsoft\TestKeyData'; ValueData = 'TestValueData'; ValueName = 'TestValueName'; ValueType = 'String'}"


try
{
Describe 'Rule Query Functions' {

$testProcessedXml = Join-Path -Path $TestDrive -ChildPath 'TestProcessedXml.xml'
Set-Content -Path $testProcessedXml -Value $xmlTestData

Context 'Get-StigRule' {
It 'Should return a V-1000 Rule PSCustomObject Non-Detailed' {
$getStigRuleResult = Get-StigRule -VulnId 'V-1000' -ProcessedXmlPath $testProcessedXml
$getStigRuleResult.RuleType | Should -Be 'RegistryRule'
$getStigRuleResult.VulnId | Should -Be 'V-1000'
$getStigRuleResult.Ensure | Should -Be 'Present'
$getStigRuleResult.Key | Should -Be 'HKEY_LOCAL_MACHINE\Software\Microsoft\TestKeyData'
$getStigRuleResult.ValueData | Should -Be 'TestValueData'
$getStigRuleResult.ValueName | Should -Be 'TestValueName'
$getStigRuleResult.ValueType | Should -Be 'String'
}

It 'Should return a V-1000 Rule PSCustomObject Detailed' {
$getStigRuleResult = Get-StigRule -VulnId 'V-1000' -ProcessedXmlPath $testProcessedXml -Detailed
$getStigRuleResult.StigId | Should -Be 'TestSTIGData'
$getStigRuleResult.StigVersion | Should -Be '1.1'
$getStigRuleResult.Severity | Should -Be 'medium'
$getStigRuleResult.Title | Should -Be 'SRG-APP-000000'
$getStigRuleResult.Description | Should -Be 'Test STIG Description'
$getStigRuleResult.RuleType | Should -Be 'RegistryRule'
$getStigRuleResult.DscResource | Should -Be 'Registry'
$getStigRuleResult.DuplicateOf | Should -Be $([string]::Empty)
$getStigRuleResult.OrganizationValueRequired | Should -Be 'False'
$getStigRuleResult.OrganizationValueTestString | Should -Be $([string]::Empty)
$getStigRuleResult.VulnId | Should -Be 'V-1000'
$getStigRuleResult.Ensure | Should -Be 'Present'
$getStigRuleResult.Key | Should -Be 'HKEY_LOCAL_MACHINE\Software\Microsoft\TestKeyData'
$getStigRuleResult.ValueData | Should -Be 'TestValueData'
$getStigRuleResult.ValueName | Should -Be 'TestValueName'
$getStigRuleResult.ValueType | Should -Be 'String'
}
}

Context 'Get-StigRuleExceptionString' {
It 'Should return a valid unformatted exception string' {
$ruleData = Get-StigRule -VulnId 'V-1000' -ProcessedXmlPath $testProcessedXml
$getStigRuleExceptionString = Get-StigRuleExceptionString -Rule $ruleData
$getStigRuleExceptionString | Should -Be $exceptionString
}

It 'Should return a valid formatted exception string' {
$ruleData = Get-StigRule -VulnId 'V-1000' -ProcessedXmlPath $testProcessedXml
$getStigRuleExceptionStringFormatted = Get-StigRuleExceptionString -Rule $ruleData -Formatted
$getStigRuleExceptionStringFormatted | Should -BeOfType System.String
}
}
}
}
finally
{
. $PSScriptRoot\.tests.footer.ps1
}
erjenkin marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ DscTest:
ExcludeTag:
- "Common Tests - New Error-Level Script Analyzer Rules"
- "Common Tests - Validate Localization"
- "Changelog"
Tag:
ExcludeSourceFile:
- output
Expand Down
Loading