-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to generate a config file template (#984)
* config file generation * Adding defender * Final generate config file * Ready for pull request * moved to support module * added to manifest file * pascal case and whitespace * linter hacks * linter test * "unused" variables * linter hacks part II * linter hacks part III * Unit Test added * added default value for unit testing various syntax fixes as well * fixed unit test, mock converting to yaml * fixed unit tests? * fixed? * more debugging * debugging * Update README.md for generating config
- Loading branch information
Showing
6 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,4 @@ InModuleScope CreateReport { | |
AfterAll { | ||
Remove-Module CreateReport -ErrorAction SilentlyContinue | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
PowerShell/ScubaGear/Testing/Unit/PowerShell/Support/New-Config.Tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath '../../../../Modules/Support') | ||
|
||
InModuleScope Support { | ||
Describe -Tag Support -Name 'New-Config' { | ||
BeforeAll { | ||
|
||
[Flags()] | ||
enum SerializationOptions { | ||
None = 0 | ||
Roundtrip = 1 | ||
DisableAliases = 2 | ||
EmitDefaults = 4 | ||
JsonCompatible = 8 | ||
DefaultToStaticType = 16 | ||
WithIndentedSequences = 32 | ||
} | ||
|
||
Mock -CommandName Write-Warning {} | ||
|
||
function ConvertTo-Yaml {throw 'this will be mocked'} | ||
Mock -ModuleName Support -CommandName ConvertTo-Yaml { $args[0] } | ||
|
||
$TestPath = New-Item -Path (Join-Path -Path "TestDrive:" -ChildPath "SampleConfig") -Name "CreateSampleConfigFolder" -ItemType Directory | ||
|
||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'CMDArgs')] | ||
$CMDArgs = @{ | ||
Description = "YAML configuration file with default description"; | ||
ProductNames = @("aad", "defender", "exo", "sharepoint", "teams"); | ||
M365Environment = "commercial"; | ||
OPAPath = "."; | ||
LogIn = $true; | ||
DisconnectOnExit = $false; | ||
OutPath = '.'; | ||
AppID = '0'; | ||
CertificateThumbprint = '0'; | ||
Organization = '0'; | ||
OutFolderName = "M365BaselineConformance"; | ||
OutProviderFileName = "ProviderSettingsExport"; | ||
OutRegoFileName = "TestResults"; | ||
OutReportName = "BaselineReports"; | ||
ConfigLocation = $TestPath; | ||
} | ||
} | ||
It 'Creates a sample configuration' { | ||
|
||
{ New-Config @CMDArgs } | Should -Not -Throw | ||
|
||
Test-Path -Path "$($TestPath)/SampleConfig.yaml" -PathType leaf | Should -Be $true | ||
} | ||
} | ||
|
||
AfterAll { | ||
Remove-Module Support -ErrorAction SilentlyContinue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters