From 0a5ebffc1ba6bbdbe7e21faa34db598604cef301 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 12:31:16 -0500 Subject: [PATCH 01/29] italics replace, but rest of line is italicized --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 6 ++++-- baselines/aad.md | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 3d7714224..23d0b0ce3 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -91,8 +91,9 @@ function New-Report { $Fragment = @() foreach ($Control in $BaselineGroup.Controls){ - + # test report details make an intercept function to $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id + #$Test.ReportRequirement = Replace-Text -Replace $Test.ReportRequirement if ($null -ne $Test){ $MissingCommands = @() @@ -265,7 +266,6 @@ function Import-SecureBaseline{ # Iterate over matched policy ids found foreach ($LineNumber in $LineNumbers) { - $Value = [System.Net.WebUtility]::HtmlEncode($Value) $Id = [string]$MdLines[$LineNumber].Substring(5) @@ -290,6 +290,8 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } + # Italics substitution + $Value = $Value.Replace("_", "") # Processing multiline description. # TODO: Improve processing GitHub issue #526 diff --git a/baselines/aad.md b/baselines/aad.md index 9de251fb9..936ef796c 100644 --- a/baselines/aad.md +++ b/baselines/aad.md @@ -95,7 +95,7 @@ This section provides policies that reduce security risks related to potentially ### Policies #### MS.AAD.2.1v1 -Users detected as high risk SHALL be blocked. +Users detected as high risk _SHALL_ be blocked. - _Rationale:_ Blocking high-risk users may prevent compromised accounts from accessing the tenant. @@ -366,7 +366,7 @@ Security logs SHALL be sent to the agency's security operations center for monit #### MS.AAD.4.1v1 Instructions -Follow the configuration instructions unique to the products and integration patterns at your organization to send the security logs to the security operations center for monitoring. +Follow the configuration instructions unique to the products and integration patterns at your organization to send the security logs to the security operations center for monitoring. ## 5. Application Registration and Consent @@ -524,7 +524,7 @@ Permanent active role assignments SHALL NOT be allowed for highly privileged rol - _Rationale:_ Instead of giving users permanent assignments to privileged roles, provisioning access just in time lessens exposure if those accounts become compromised. In Azure AD PIM or an alternative PAM system, just in time access can be provisioned by assigning users to roles as eligible instead of perpetually active. - _Last modified:_ June 2023 - _Note:_ Exceptions to this policy are: - - Emergency access accounts that need perpetual access to the tenant in the rare event of system degradation or other scenarios. + - Emergency access accounts that need perpetual access to the tenant in the rare event of system degradation or other scenarios. - Some types of service accounts that require a user account with privileged roles; since these accounts are used by software programs, they cannot perform role activation. #### MS.AAD.7.5v1 From 11d0bc27797aeb0962c7a6798f2549ef1bd91467 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 12:41:35 -0500 Subject: [PATCH 02/29] fix for cases with whitespaces --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 4 ++-- baselines/defender.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 23d0b0ce3..1ca795845 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -290,8 +290,8 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } - # Italics substitution - $Value = $Value.Replace("_", "") + # Description italics substitution + $Value = $Value -replace '(_)(.*?)(_)', '${2}' # Processing multiline description. # TODO: Improve processing GitHub issue #526 diff --git a/baselines/defender.md b/baselines/defender.md index 59d19d3e5..c1f12ce44 100644 --- a/baselines/defender.md +++ b/baselines/defender.md @@ -569,7 +569,7 @@ See [MS.DEFENDER.4.1v1 Instructions](#msdefender41v1-instructions) steps 1. Sign in to the **Microsoft Purview compliance portal**. 2. Under **Solutions**, select **Data loss prevention**. - + 3. Go to **Endpoint DLP Settings**. 4. Go to **Restricted apps and app groups**. @@ -639,7 +639,7 @@ real-time insight into possible security incidents. Guidance on specific alerts ### Policies #### MS.DEFENDER.5.1v1 -At a minimum, the alerts required by the CISA M365 Security Configuration Baseline for Exchange Online SHALL be enabled. +At a minimum, the alerts required by the _CISA M365 Security Configuration Baseline for Exchange Online_ SHALL be enabled. - _Rationale:_ Potentially malicious or service-impacting events may go undetected without a means of detecting these events. Setting up a mechanism to alert administrators to the list of events linked above draws attention to them to minimize any impact to users and the agency. From ef45d6482a6d7d72b6168ef6effce3c9aa9233ab Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 13:11:12 -0500 Subject: [PATCH 03/29] clean unused line --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 1ca795845..1a5c58cf0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -93,7 +93,6 @@ function New-Report { foreach ($Control in $BaselineGroup.Controls){ # test report details make an intercept function to $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id - #$Test.ReportRequirement = Replace-Text -Replace $Test.ReportRequirement if ($null -ne $Test){ $MissingCommands = @() From cda9ab1b20be4735d1c50ec2dd80c6e13821c61e Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 13:12:05 -0500 Subject: [PATCH 04/29] clean comment --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 1a5c58cf0..87cc775c7 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -91,7 +91,7 @@ function New-Report { $Fragment = @() foreach ($Control in $BaselineGroup.Controls){ - # test report details make an intercept function to + $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id if ($null -ne $Test){ From 4e50237f3616182bbf9d9e1584284ff435c695ba Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Wed, 13 Dec 2023 13:26:56 -0500 Subject: [PATCH 05/29] multiline list case processing --- .../Modules/CreateReport/CreateReport.psm1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 87cc775c7..e96b74275 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -282,6 +282,7 @@ function Import-SecureBaseline{ $MaxLineSearch = 20; $Value = ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() $IsMalformedDescription = $false + $IsList = $false try { if ([string]::IsNullOrWhiteSpace($Value)){ @@ -301,8 +302,20 @@ function Import-SecureBaseline{ # Reached Criticality comment so policy description is complete. break } + + # Policy description contains a list assuming list is denoted by a colon character. + if ($Value[-1] -eq ":") { + $isList = $true + } + if (-not [string]::IsNullOrWhiteSpace([string]$MdLines[$LineNumber+$LineAdvance])) { - $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + # List case, use newline character between value text + if ($isList) { + $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + } + else { # Value ending with newline char, use whitespace character between value text + $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + } } if ($LineAdvance -gt $MaxLineSearch){ From 57642926f5cb714bd631996eb72fa5995628a82f Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Wed, 13 Dec 2023 16:10:03 -0500 Subject: [PATCH 06/29] html italic function declaration --- .../Modules/CreateReport/CreateReport.psm1 | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index e96b74275..ee0cc88d0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -290,8 +290,6 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } - # Description italics substitution - $Value = $Value -replace '(_)(.*?)(_)', '${2}' # Processing multiline description. # TODO: Improve processing GitHub issue #526 @@ -312,9 +310,11 @@ function Import-SecureBaseline{ # List case, use newline character between value text if ($isList) { $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + #Write-Host $LineAdvance + $Value -BackgroundColor Blue } else { # Value ending with newline char, use whitespace character between value text $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + #Write-Host $LineAdvance + $Value -BackgroundColor Green } } @@ -324,6 +324,9 @@ function Import-SecureBaseline{ } } + # Description italics substitution + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "Italic" + $Group.Controls += @{"Id"=$Id; "Value"=$Value; "Deleted"=$Deleted; MalformedDescription=$IsMalformedDescription} } catch { @@ -366,6 +369,28 @@ function New-MarkdownAnchor{ } } +function Resolve-HTMLMarkdown{ + param ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] + $OriginalString, + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] + $HTMLReplace + ) + + # Replace markdown with italics substitution + # NOTE: This could eventually be a switch case function for other types of html subsitutions in markdown + if ($HTMLReplace.ToLower() -match "italic") { + $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' + return $ResolvedString + } else { + return $OriginalString + } +} + Export-ModuleMember -Function @( 'New-Report', 'Import-SecureBaseline' From 1020f6f1a3748fc0d75e4548f87e03f4a8d33832 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez <137103213+isab-m@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:11:43 -0500 Subject: [PATCH 07/29] Added bold option support for markdown transformation Added bold support for the transformation of markdown policy descriptions Co-authored-by: Addam Schroll <108814318+schrolla@users.noreply.github.com> --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index ee0cc88d0..24671b55d 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -386,6 +386,9 @@ function Resolve-HTMLMarkdown{ if ($HTMLReplace.ToLower() -match "italic") { $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString + } elseif($HTMLReplace.ToLower() -match "bold") { + $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' + return $ResolvedString } else { return $OriginalString } From 4110b6c153d6748037d39e7893ed7a43a1b7b42c Mon Sep 17 00:00:00 2001 From: Isabella Magallanez <137103213+isab-m@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:14:45 -0500 Subject: [PATCH 08/29] clean debug comments, add bold option support --- .../ScubaGear/Modules/CreateReport/CreateReport.psm1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 24671b55d..c9711621c 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -310,11 +310,9 @@ function Import-SecureBaseline{ # List case, use newline character between value text if ($isList) { $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() - #Write-Host $LineAdvance + $Value -BackgroundColor Blue } else { # Value ending with newline char, use whitespace character between value text $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() - #Write-Host $LineAdvance + $Value -BackgroundColor Green } } @@ -325,7 +323,10 @@ function Import-SecureBaseline{ } # Description italics substitution - $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "Italic" + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "italic" + + # Description bold substitution + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "bold" $Group.Controls += @{"Id"=$Id; "Value"=$Value; "Deleted"=$Deleted; MalformedDescription=$IsMalformedDescription} } @@ -382,13 +383,12 @@ function Resolve-HTMLMarkdown{ ) # Replace markdown with italics substitution - # NOTE: This could eventually be a switch case function for other types of html subsitutions in markdown if ($HTMLReplace.ToLower() -match "italic") { $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString } elseif($HTMLReplace.ToLower() -match "bold") { $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' - return $ResolvedString + return $ResolvedString } else { return $OriginalString } From 76aa64328df972625329de764f65762e34f8c46a Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:49:55 -0500 Subject: [PATCH 09/29] escape regex for bold translation --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index c9711621c..7381406a0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -387,7 +387,7 @@ function Resolve-HTMLMarkdown{ $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString } elseif($HTMLReplace.ToLower() -match "bold") { - $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' + $ResolvedString = $OriginalString -replace '(\*\*)(.*?)(\*\*)', '${2}' return $ResolvedString } else { return $OriginalString From 5f3000a9c052212896f31a06e2f3aad4126bdc51 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:56:36 -0500 Subject: [PATCH 10/29] Baseline revert --- baselines/aad.md | 2 +- baselines/defender.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/baselines/aad.md b/baselines/aad.md index 936ef796c..62553035f 100644 --- a/baselines/aad.md +++ b/baselines/aad.md @@ -95,7 +95,7 @@ This section provides policies that reduce security risks related to potentially ### Policies #### MS.AAD.2.1v1 -Users detected as high risk _SHALL_ be blocked. +Users detected as high risk SHALL be blocked. - _Rationale:_ Blocking high-risk users may prevent compromised accounts from accessing the tenant. diff --git a/baselines/defender.md b/baselines/defender.md index c1f12ce44..c5c78cebf 100644 --- a/baselines/defender.md +++ b/baselines/defender.md @@ -639,7 +639,7 @@ real-time insight into possible security incidents. Guidance on specific alerts ### Policies #### MS.DEFENDER.5.1v1 -At a minimum, the alerts required by the _CISA M365 Security Configuration Baseline for Exchange Online_ SHALL be enabled. +At a minimum, the alerts required by the CISA M365 Security Configuration Baseline for Exchange Online SHALL be enabled. - _Rationale:_ Potentially malicious or service-impacting events may go undetected without a means of detecting these events. Setting up a mechanism to alert administrators to the list of events linked above draws attention to them to minimize any impact to users and the agency. From 2d2bf9f23de0c12d6af2cbea4f418d6eb92edebe Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:13:00 -0500 Subject: [PATCH 11/29] initial resolve-htmlmarkdown unit tests --- .../Resolve-HTMLMarkdown.Tests.ps1 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 diff --git a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 new file mode 100644 index 000000000..ea1047a28 --- /dev/null +++ b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -0,0 +1,38 @@ +$CreateReportModulePath = Join-Path -Path $PSScriptRoot -ChildPath "../../../../PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1" +Import-Module $CreateReportModulePath + +InModuleScope CreateReport { + Describe -Tag "Resolve-HTMLMarkdown" -name "Parameter error handling" { + It "Empty original string" { + {Resolve-HTMLMarkdown -OriginalString "" -HTMLReplace "italic"} | + Should -Throw -Because "Invalid OriginalString parameter" + } + It "Empty html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace ""} | + Should -Throw -Because "Invalid HTMLReplace parameter" + } + It "Null original string" { + {Resolve-HTMLMarkdown -OriginalString $null -HTMLReplace "italic"} | + Should -Throw -Because "Invalid OriginalString parameter" + } + It "Null html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace $null} | + Should -Throw -Because "Invalid HTMLReplace parameter" + } + It "Bad html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace "underline"} | + Should -Throw -ExceptionType ArgumentException + } + } + + Describe -tag "Resolve-HTMLMarkdown" -name 'Test resolve HTML Markdown in baseline descriptions' { + It "Test Valid html markdown resolution: " -ForEach @( + @{ OriginalString = "__A test string.__"; HTMLReplace = "italic"; HTMLTranslation = "(.*?)"}, + @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "(.*?)"} + ){ + $ResolvedString = Resolve-HTMLMarkdown -OriginalString $OriginalString -HTMLReplace $HTMLReplace + #$ResolvedString.StartsWith("#$GoupNumber") | Should -BeTrue + $ResolvedString -Contains $HTMLTranslation | Should -BeTrue + } + } +} \ No newline at end of file From 5c8b52d1e9b6ef369c3206f8c1ae87901e7785c1 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:29:27 -0500 Subject: [PATCH 12/29] unit test logic fix --- .../CreateReport/Resolve-HTMLMarkdown.Tests.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 index ea1047a28..6070a03e6 100644 --- a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 +++ b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -31,8 +31,10 @@ InModuleScope CreateReport { @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "(.*?)"} ){ $ResolvedString = Resolve-HTMLMarkdown -OriginalString $OriginalString -HTMLReplace $HTMLReplace - #$ResolvedString.StartsWith("#$GoupNumber") | Should -BeTrue - $ResolvedString -Contains $HTMLTranslation | Should -BeTrue + $ResolvedString -Match $HTMLTranslation | Should -BeTrue } } -} \ No newline at end of file + AfterAll { + Remove-Module CreateReport -ErrorAction SilentlyContinue + } + } \ No newline at end of file From bd15b1cfa353fd14b183a272e534aeff2e897667 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:33:59 -0500 Subject: [PATCH 13/29] added invalid paramater throw error for resolve-htmlmarkdown --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 7381406a0..06b527f02 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -390,6 +390,8 @@ function Resolve-HTMLMarkdown{ $ResolvedString = $OriginalString -replace '(\*\*)(.*?)(\*\*)', '${2}' return $ResolvedString } else { + $InvalidHTMLReplace = New-Object System.ArgumentException "$HTMLReplace is not valid" + throw $InvalidHTMLReplace return $OriginalString } } From b6b3b36eaad9974d539ce4506ebaccbae191acb5 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 12:31:16 -0500 Subject: [PATCH 14/29] italics replace, but rest of line is italicized --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 6 ++++-- baselines/aad.md | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 3d7714224..23d0b0ce3 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -91,8 +91,9 @@ function New-Report { $Fragment = @() foreach ($Control in $BaselineGroup.Controls){ - + # test report details make an intercept function to $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id + #$Test.ReportRequirement = Replace-Text -Replace $Test.ReportRequirement if ($null -ne $Test){ $MissingCommands = @() @@ -265,7 +266,6 @@ function Import-SecureBaseline{ # Iterate over matched policy ids found foreach ($LineNumber in $LineNumbers) { - $Value = [System.Net.WebUtility]::HtmlEncode($Value) $Id = [string]$MdLines[$LineNumber].Substring(5) @@ -290,6 +290,8 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } + # Italics substitution + $Value = $Value.Replace("_", "") # Processing multiline description. # TODO: Improve processing GitHub issue #526 diff --git a/baselines/aad.md b/baselines/aad.md index 9de251fb9..936ef796c 100644 --- a/baselines/aad.md +++ b/baselines/aad.md @@ -95,7 +95,7 @@ This section provides policies that reduce security risks related to potentially ### Policies #### MS.AAD.2.1v1 -Users detected as high risk SHALL be blocked. +Users detected as high risk _SHALL_ be blocked. - _Rationale:_ Blocking high-risk users may prevent compromised accounts from accessing the tenant. @@ -366,7 +366,7 @@ Security logs SHALL be sent to the agency's security operations center for monit #### MS.AAD.4.1v1 Instructions -Follow the configuration instructions unique to the products and integration patterns at your organization to send the security logs to the security operations center for monitoring. +Follow the configuration instructions unique to the products and integration patterns at your organization to send the security logs to the security operations center for monitoring. ## 5. Application Registration and Consent @@ -524,7 +524,7 @@ Permanent active role assignments SHALL NOT be allowed for highly privileged rol - _Rationale:_ Instead of giving users permanent assignments to privileged roles, provisioning access just in time lessens exposure if those accounts become compromised. In Azure AD PIM or an alternative PAM system, just in time access can be provisioned by assigning users to roles as eligible instead of perpetually active. - _Last modified:_ June 2023 - _Note:_ Exceptions to this policy are: - - Emergency access accounts that need perpetual access to the tenant in the rare event of system degradation or other scenarios. + - Emergency access accounts that need perpetual access to the tenant in the rare event of system degradation or other scenarios. - Some types of service accounts that require a user account with privileged roles; since these accounts are used by software programs, they cannot perform role activation. #### MS.AAD.7.5v1 From 7dfdac7dd4e294078d3817e1a73e309694213f72 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 12:41:35 -0500 Subject: [PATCH 15/29] fix for cases with whitespaces --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 4 ++-- baselines/defender.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 23d0b0ce3..1ca795845 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -290,8 +290,8 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } - # Italics substitution - $Value = $Value.Replace("_", "") + # Description italics substitution + $Value = $Value -replace '(_)(.*?)(_)', '${2}' # Processing multiline description. # TODO: Improve processing GitHub issue #526 diff --git a/baselines/defender.md b/baselines/defender.md index 59d19d3e5..c1f12ce44 100644 --- a/baselines/defender.md +++ b/baselines/defender.md @@ -569,7 +569,7 @@ See [MS.DEFENDER.4.1v1 Instructions](#msdefender41v1-instructions) steps 1. Sign in to the **Microsoft Purview compliance portal**. 2. Under **Solutions**, select **Data loss prevention**. - + 3. Go to **Endpoint DLP Settings**. 4. Go to **Restricted apps and app groups**. @@ -639,7 +639,7 @@ real-time insight into possible security incidents. Guidance on specific alerts ### Policies #### MS.DEFENDER.5.1v1 -At a minimum, the alerts required by the CISA M365 Security Configuration Baseline for Exchange Online SHALL be enabled. +At a minimum, the alerts required by the _CISA M365 Security Configuration Baseline for Exchange Online_ SHALL be enabled. - _Rationale:_ Potentially malicious or service-impacting events may go undetected without a means of detecting these events. Setting up a mechanism to alert administrators to the list of events linked above draws attention to them to minimize any impact to users and the agency. From 789cf79a9d1358dacee4fbf89223dd79dee78792 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 13:11:12 -0500 Subject: [PATCH 16/29] clean unused line --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 1ca795845..1a5c58cf0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -93,7 +93,6 @@ function New-Report { foreach ($Control in $BaselineGroup.Controls){ # test report details make an intercept function to $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id - #$Test.ReportRequirement = Replace-Text -Replace $Test.ReportRequirement if ($null -ne $Test){ $MissingCommands = @() From 2dbbad3485e1476d580332d6388a411e3fef71b7 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Mon, 11 Dec 2023 13:12:05 -0500 Subject: [PATCH 17/29] clean comment --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 1a5c58cf0..87cc775c7 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -91,7 +91,7 @@ function New-Report { $Fragment = @() foreach ($Control in $BaselineGroup.Controls){ - # test report details make an intercept function to + $Test = $TestResults | Where-Object -Property PolicyId -eq $Control.Id if ($null -ne $Test){ From e7f5e282806b3772c0bdb519d149207880df1b51 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Wed, 13 Dec 2023 13:26:56 -0500 Subject: [PATCH 18/29] multiline list case processing --- .../Modules/CreateReport/CreateReport.psm1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 87cc775c7..e96b74275 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -282,6 +282,7 @@ function Import-SecureBaseline{ $MaxLineSearch = 20; $Value = ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() $IsMalformedDescription = $false + $IsList = $false try { if ([string]::IsNullOrWhiteSpace($Value)){ @@ -301,8 +302,20 @@ function Import-SecureBaseline{ # Reached Criticality comment so policy description is complete. break } + + # Policy description contains a list assuming list is denoted by a colon character. + if ($Value[-1] -eq ":") { + $isList = $true + } + if (-not [string]::IsNullOrWhiteSpace([string]$MdLines[$LineNumber+$LineAdvance])) { - $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + # List case, use newline character between value text + if ($isList) { + $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + } + else { # Value ending with newline char, use whitespace character between value text + $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + } } if ($LineAdvance -gt $MaxLineSearch){ From 3698043fb64acf58ff42804e07e7b44b4995224f Mon Sep 17 00:00:00 2001 From: Isabella Magallanez Date: Wed, 13 Dec 2023 16:10:03 -0500 Subject: [PATCH 19/29] html italic function declaration --- .../Modules/CreateReport/CreateReport.psm1 | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index e96b74275..ee0cc88d0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -290,8 +290,6 @@ function Import-SecureBaseline{ $Value = "Error - The baseline policy text is malformed. Description should start immediately after Policy Id." Write-Error "Expected description for $Id to start on line $($LineNumber+$LineAdvance)" } - # Description italics substitution - $Value = $Value -replace '(_)(.*?)(_)', '${2}' # Processing multiline description. # TODO: Improve processing GitHub issue #526 @@ -312,9 +310,11 @@ function Import-SecureBaseline{ # List case, use newline character between value text if ($isList) { $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + #Write-Host $LineAdvance + $Value -BackgroundColor Blue } else { # Value ending with newline char, use whitespace character between value text $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() + #Write-Host $LineAdvance + $Value -BackgroundColor Green } } @@ -324,6 +324,9 @@ function Import-SecureBaseline{ } } + # Description italics substitution + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "Italic" + $Group.Controls += @{"Id"=$Id; "Value"=$Value; "Deleted"=$Deleted; MalformedDescription=$IsMalformedDescription} } catch { @@ -366,6 +369,28 @@ function New-MarkdownAnchor{ } } +function Resolve-HTMLMarkdown{ + param ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] + $OriginalString, + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] + $HTMLReplace + ) + + # Replace markdown with italics substitution + # NOTE: This could eventually be a switch case function for other types of html subsitutions in markdown + if ($HTMLReplace.ToLower() -match "italic") { + $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' + return $ResolvedString + } else { + return $OriginalString + } +} + Export-ModuleMember -Function @( 'New-Report', 'Import-SecureBaseline' From dc14aefbd53273d7d8c60e00c51ad9287f60236f Mon Sep 17 00:00:00 2001 From: Isabella Magallanez <137103213+isab-m@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:11:43 -0500 Subject: [PATCH 20/29] Added bold option support for markdown transformation Added bold support for the transformation of markdown policy descriptions Co-authored-by: Addam Schroll <108814318+schrolla@users.noreply.github.com> --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index ee0cc88d0..24671b55d 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -386,6 +386,9 @@ function Resolve-HTMLMarkdown{ if ($HTMLReplace.ToLower() -match "italic") { $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString + } elseif($HTMLReplace.ToLower() -match "bold") { + $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' + return $ResolvedString } else { return $OriginalString } From d49a6bfc62907d8a1337b094c567ce02231c4659 Mon Sep 17 00:00:00 2001 From: Isabella Magallanez <137103213+isab-m@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:14:45 -0500 Subject: [PATCH 21/29] clean debug comments, add bold option support --- .../ScubaGear/Modules/CreateReport/CreateReport.psm1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 24671b55d..c9711621c 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -310,11 +310,9 @@ function Import-SecureBaseline{ # List case, use newline character between value text if ($isList) { $Value += "`n" + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() - #Write-Host $LineAdvance + $Value -BackgroundColor Blue } else { # Value ending with newline char, use whitespace character between value text $Value += " " + ([string]$MdLines[$LineNumber+$LineAdvance]).Trim() - #Write-Host $LineAdvance + $Value -BackgroundColor Green } } @@ -325,7 +323,10 @@ function Import-SecureBaseline{ } # Description italics substitution - $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "Italic" + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "italic" + + # Description bold substitution + $Value = Resolve-HTMLMarkdown -OriginalString $Value -HTMLReplace "bold" $Group.Controls += @{"Id"=$Id; "Value"=$Value; "Deleted"=$Deleted; MalformedDescription=$IsMalformedDescription} } @@ -382,13 +383,12 @@ function Resolve-HTMLMarkdown{ ) # Replace markdown with italics substitution - # NOTE: This could eventually be a switch case function for other types of html subsitutions in markdown if ($HTMLReplace.ToLower() -match "italic") { $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString } elseif($HTMLReplace.ToLower() -match "bold") { $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' - return $ResolvedString + return $ResolvedString } else { return $OriginalString } From 58ab285b5e92876e1d792039d96679d5d41763d9 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:49:55 -0500 Subject: [PATCH 22/29] escape regex for bold translation --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index c9711621c..7381406a0 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -387,7 +387,7 @@ function Resolve-HTMLMarkdown{ $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' return $ResolvedString } elseif($HTMLReplace.ToLower() -match "bold") { - $ResolvedString = $OriginalString -replace '(**)(.*?)(**)', '${2}' + $ResolvedString = $OriginalString -replace '(\*\*)(.*?)(\*\*)', '${2}' return $ResolvedString } else { return $OriginalString From 2f1d65b5f8cac5740426d5c48ef97ff474070198 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:56:36 -0500 Subject: [PATCH 23/29] Baseline revert --- baselines/aad.md | 2 +- baselines/defender.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/baselines/aad.md b/baselines/aad.md index 936ef796c..62553035f 100644 --- a/baselines/aad.md +++ b/baselines/aad.md @@ -95,7 +95,7 @@ This section provides policies that reduce security risks related to potentially ### Policies #### MS.AAD.2.1v1 -Users detected as high risk _SHALL_ be blocked. +Users detected as high risk SHALL be blocked. - _Rationale:_ Blocking high-risk users may prevent compromised accounts from accessing the tenant. diff --git a/baselines/defender.md b/baselines/defender.md index c1f12ce44..c5c78cebf 100644 --- a/baselines/defender.md +++ b/baselines/defender.md @@ -639,7 +639,7 @@ real-time insight into possible security incidents. Guidance on specific alerts ### Policies #### MS.DEFENDER.5.1v1 -At a minimum, the alerts required by the _CISA M365 Security Configuration Baseline for Exchange Online_ SHALL be enabled. +At a minimum, the alerts required by the CISA M365 Security Configuration Baseline for Exchange Online SHALL be enabled. - _Rationale:_ Potentially malicious or service-impacting events may go undetected without a means of detecting these events. Setting up a mechanism to alert administrators to the list of events linked above draws attention to them to minimize any impact to users and the agency. From a5a1e3bdbb7315e759de2a2e9bd5b6f5f425483b Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:13:00 -0500 Subject: [PATCH 24/29] initial resolve-htmlmarkdown unit tests --- .../Resolve-HTMLMarkdown.Tests.ps1 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 diff --git a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 new file mode 100644 index 000000000..ea1047a28 --- /dev/null +++ b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -0,0 +1,38 @@ +$CreateReportModulePath = Join-Path -Path $PSScriptRoot -ChildPath "../../../../PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1" +Import-Module $CreateReportModulePath + +InModuleScope CreateReport { + Describe -Tag "Resolve-HTMLMarkdown" -name "Parameter error handling" { + It "Empty original string" { + {Resolve-HTMLMarkdown -OriginalString "" -HTMLReplace "italic"} | + Should -Throw -Because "Invalid OriginalString parameter" + } + It "Empty html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace ""} | + Should -Throw -Because "Invalid HTMLReplace parameter" + } + It "Null original string" { + {Resolve-HTMLMarkdown -OriginalString $null -HTMLReplace "italic"} | + Should -Throw -Because "Invalid OriginalString parameter" + } + It "Null html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace $null} | + Should -Throw -Because "Invalid HTMLReplace parameter" + } + It "Bad html replacement string" { + {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace "underline"} | + Should -Throw -ExceptionType ArgumentException + } + } + + Describe -tag "Resolve-HTMLMarkdown" -name 'Test resolve HTML Markdown in baseline descriptions' { + It "Test Valid html markdown resolution: " -ForEach @( + @{ OriginalString = "__A test string.__"; HTMLReplace = "italic"; HTMLTranslation = "(.*?)"}, + @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "(.*?)"} + ){ + $ResolvedString = Resolve-HTMLMarkdown -OriginalString $OriginalString -HTMLReplace $HTMLReplace + #$ResolvedString.StartsWith("#$GoupNumber") | Should -BeTrue + $ResolvedString -Contains $HTMLTranslation | Should -BeTrue + } + } +} \ No newline at end of file From a5931518bd2f567e95053bdc3eac633e124d3c2c Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:29:27 -0500 Subject: [PATCH 25/29] unit test logic fix --- .../CreateReport/Resolve-HTMLMarkdown.Tests.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 index ea1047a28..6070a03e6 100644 --- a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 +++ b/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -31,8 +31,10 @@ InModuleScope CreateReport { @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "(.*?)"} ){ $ResolvedString = Resolve-HTMLMarkdown -OriginalString $OriginalString -HTMLReplace $HTMLReplace - #$ResolvedString.StartsWith("#$GoupNumber") | Should -BeTrue - $ResolvedString -Contains $HTMLTranslation | Should -BeTrue + $ResolvedString -Match $HTMLTranslation | Should -BeTrue } } -} \ No newline at end of file + AfterAll { + Remove-Module CreateReport -ErrorAction SilentlyContinue + } + } \ No newline at end of file From a13f4d775ef8a38733359607529f0f5d83f90c21 Mon Sep 17 00:00:00 2001 From: isab-m <137103213+isab-m@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:33:59 -0500 Subject: [PATCH 26/29] added invalid paramater throw error for resolve-htmlmarkdown --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 7381406a0..06b527f02 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -390,6 +390,8 @@ function Resolve-HTMLMarkdown{ $ResolvedString = $OriginalString -replace '(\*\*)(.*?)(\*\*)', '${2}' return $ResolvedString } else { + $InvalidHTMLReplace = New-Object System.ArgumentException "$HTMLReplace is not valid" + throw $InvalidHTMLReplace return $OriginalString } } From d2bb412308297f9411c62e4bc952002e537c8114 Mon Sep 17 00:00:00 2001 From: Addam Schroll <108814318+schrolla@users.noreply.github.com> Date: Thu, 25 Jan 2024 08:30:39 -0600 Subject: [PATCH 27/29] Move unit test to new package location --- .../PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {Testing => PowerShell/ScubaGear/Testing}/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 (99%) diff --git a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 similarity index 99% rename from Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 rename to PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 index 6070a03e6..cbabc3089 100644 --- a/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 +++ b/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -22,7 +22,7 @@ InModuleScope CreateReport { It "Bad html replacement string" { {Resolve-HTMLMarkdown -OriginalString "A valid string" -HTMLReplace "underline"} | Should -Throw -ExceptionType ArgumentException - } + } } Describe -tag "Resolve-HTMLMarkdown" -name 'Test resolve HTML Markdown in baseline descriptions' { @@ -37,4 +37,4 @@ InModuleScope CreateReport { AfterAll { Remove-Module CreateReport -ErrorAction SilentlyContinue } - } \ No newline at end of file + } From 25c59d26995703dfa175eb0160bb22478f638ffe Mon Sep 17 00:00:00 2001 From: Addam Schroll <108814318+schrolla@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:28:06 -0600 Subject: [PATCH 28/29] * Fix import path after test file move * Change italics test string to single underscores * Change test string match from regex to direct compare --- .../CreateReport/Resolve-HTMLMarkdown.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 b/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 index cbabc3089..6fba696ba 100644 --- a/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 +++ b/PowerShell/ScubaGear/Testing/Unit/PowerShell/CreateReport/Resolve-HTMLMarkdown.Tests.ps1 @@ -1,5 +1,5 @@ -$CreateReportModulePath = Join-Path -Path $PSScriptRoot -ChildPath "../../../../PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1" -Import-Module $CreateReportModulePath +$CreateReportModulePath = Join-Path -Path $PSScriptRoot -ChildPath "../../../../Modules/CreateReport/CreateReport.psm1" +Import-Module $CreateReportModulePath -Force InModuleScope CreateReport { Describe -Tag "Resolve-HTMLMarkdown" -name "Parameter error handling" { @@ -27,11 +27,11 @@ InModuleScope CreateReport { Describe -tag "Resolve-HTMLMarkdown" -name 'Test resolve HTML Markdown in baseline descriptions' { It "Test Valid html markdown resolution: " -ForEach @( - @{ OriginalString = "__A test string.__"; HTMLReplace = "italic"; HTMLTranslation = "(.*?)"}, - @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "(.*?)"} + @{ OriginalString = "_A test string._"; HTMLReplace = "italic"; HTMLTranslation = "A test string."}, + @{ OriginalString = "**A test string.**"; HTMLReplace = "bold"; HTMLTranslation = "A test string."} ){ $ResolvedString = Resolve-HTMLMarkdown -OriginalString $OriginalString -HTMLReplace $HTMLReplace - $ResolvedString -Match $HTMLTranslation | Should -BeTrue + $ResolvedString -eq $HTMLTranslation | Should -BeTrue } } AfterAll { From edef100ba000b953b7e74f6fad03950030b135b0 Mon Sep 17 00:00:00 2001 From: Addam Schroll <108814318+schrolla@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:29:20 -0600 Subject: [PATCH 29/29] Update italics regex match to address empty italics properly. --- PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 index 06b527f02..ad289e6fb 100644 --- a/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 +++ b/PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1 @@ -384,7 +384,7 @@ function Resolve-HTMLMarkdown{ # Replace markdown with italics substitution if ($HTMLReplace.ToLower() -match "italic") { - $ResolvedString = $OriginalString -replace '(_)(.*?)(_)', '${2}' + $ResolvedString = $OriginalString -replace '(_)([^\v][^_]*[^\v])?(_)', '${2}' return $ResolvedString } elseif($HTMLReplace.ToLower() -match "bold") { $ResolvedString = $OriginalString -replace '(\*\*)(.*?)(\*\*)', '${2}'