Skip to content

Commit c93bd87

Browse files
authored
New-StigChecklist path validation (#307)
* rem unused files * added path validation * added notes * added initial test * fixed path
1 parent cdfdee7 commit c93bd87

File tree

7 files changed

+39
-29
lines changed

7 files changed

+39
-29
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This fixes #
1616

1717
**Task list:**
1818

19-
- [ ] Change details added to Unreleased section of README.md (Not required for Convert modules)?
19+
- [ ] Change details added to Unreleased section of CHANGELOG.md (Not required for Convert modules)?
2020
- [ ] Added/updated documentation, comment-based help and descriptions where appropriate?
2121
- [ ] Examples appropriately updated?
2222
- [ ] New/changed code adheres to [Style Guidelines](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md)?

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NEW
1818

1919
UPDATES
2020

21+
* Fixed [#258](https://github.com/Microsoft/PowerStig/issues/258): New-StigChecklist will not accept a path without an explicit filename
2122
* Fixed [#243](https://github.com/Microsoft/PowerStig/issues/243): [V-46515] Windows-All-IE11-1.15 Rawstring typo
2223
* Fixed [#289](https://github.com/Microsoft/PowerStig/issues/289): Updated DocumentRule and DocumentRuleConvert Classes to parse correctly.
2324
* Fixed [#284](https://github.com/Microsoft/PowerStig/issues/284): [V-74415] [V-74413] Windows 10 STIG rule V-74415 and V-74413 should not contain white space in key

Module/Rule.DnsServerRootHint/Convert/Methods.ps1

-5
This file was deleted.

Module/Rule.Manual/Convert/Methods.ps1

-5
This file was deleted.

Module/Rule.Wmi/Convert/Methods.ps1

-5
This file was deleted.

Module/STIG/Functions.Checklist.ps1

+23-13
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,25 @@ function New-StigCheckList
4242
$XccdfPath,
4343

4444
[Parameter(Mandatory = $true)]
45-
[string]
45+
[System.IO.FileInfo]
4646
$OutputPath
4747
)
4848

49+
if (-not (Test-Path -Path $OutputPath.DirectoryName))
50+
{
51+
throw "$($OutputPath.DirectoryName) is not a valid directory. Please provide a valid directory."
52+
}
53+
54+
if ($OutputPath.Extension -ne '.ckl')
55+
{
56+
throw "$($OutputPath.FullName) is not a valid checklist extension. Please provide a full valid path ending in .ckl"
57+
}
58+
4959
$xmlWriterSettings = [System.Xml.XmlWriterSettings]::new()
5060
$xmlWriterSettings.Indent = $true
5161
$xmlWriterSettings.IndentChars = "`t"
5262
$xmlWriterSettings.NewLineChars = "`n"
53-
$writer = [System.Xml.XmlWriter]::Create($outputPath, $xmlWriterSettings)
63+
$writer = [System.Xml.XmlWriter]::Create($OutputPath.FullName, $xmlWriterSettings)
5464

5565
$writer.WriteStartElement('CHECKLIST')
5666

@@ -94,17 +104,17 @@ function New-StigCheckList
94104
$xccdfBenchmarkContent = Get-StigXccdfBenchmarkContent -Path $xccdfPath
95105

96106
$stigInfoElements = [ordered] @{
97-
'version' = $xccdfBenchmarkContent.version
107+
'version' = $xccdfBenchmarkContent.version
98108
'classification' = 'UNCLASSIFIED'
99-
'customname' = ''
100-
'stigid' = $xccdfBenchmarkContent.id
101-
'description' = $xccdfBenchmarkContent.description
102-
'filename' = Split-Path -Path $xccdfPath -Leaf
103-
'releaseinfo' = $xccdfBenchmarkContent.'plain-text'.InnerText
104-
'title' = $xccdfBenchmarkContent.title
105-
'uuid' = (New-Guid).Guid
106-
'notice' = $xccdfBenchmarkContent.notice.InnerText
107-
'source' = $xccdfBenchmarkContent.reference.source
109+
'customname' = ''
110+
'stigid' = $xccdfBenchmarkContent.id
111+
'description' = $xccdfBenchmarkContent.description
112+
'filename' = Split-Path -Path $xccdfPath -Leaf
113+
'releaseinfo' = $xccdfBenchmarkContent.'plain-text'.InnerText
114+
'title' = $xccdfBenchmarkContent.title
115+
'uuid' = (New-Guid).Guid
116+
'notice' = $xccdfBenchmarkContent.notice.InnerText
117+
'source' = $xccdfBenchmarkContent.reference.source
108118
}
109119

110120
foreach ($StigInfoElement in $stigInfoElements.GetEnumerator())
@@ -134,7 +144,7 @@ function New-StigCheckList
134144

135145
foreach ($attribute in $vulnerability.GetEnumerator())
136146
{
137-
$status = $null
147+
$status = $null
138148
$comments = $null
139149

140150
if ($attribute.Name -eq 'Vuln_Num')
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
. $PSScriptRoot\..\..\..\Module\STIG\Functions.Checklist.ps1
2+
3+
Describe 'New-StigCheckList' {
4+
5+
It 'Should throw if an invalid path is provided' {
6+
Mock Test-Path {return $false}
7+
{New-StigCheckList -ReferenceConfiguration 'test' -XccdfPath 'test' -OutputPath 'c:\test'} | Should Throw
8+
}
9+
10+
It 'Should throw if the full path to a .ckl file is not provided' {
11+
Mock Test-Path {return $true}
12+
{New-StigCheckList -ReferenceConfiguration 'test' -XccdfPath 'test' -OutputPath 'c:\test\test.ck'} | Should Throw
13+
}
14+
}

0 commit comments

Comments
 (0)