ticketmaster / poshspec

Infrastructure Testing DSL running in Pester
MIT License
183 stars 32 forks source link

Added functionality to test Local Security Policy Security Options #64

Closed markwragg closed 5 years ago

markwragg commented 5 years ago

Example usage:

Import-Module PoshSpec

Describe 'PoshSpec tests' {

    SecurityOption 'Domain member: Maximum machine account password age' { 
        Should -Be 30 
    }

    SecurityOption 'Accounts: Limit local account use of blank passwords to console logon only' {
        Should -Be Enabled
    }

    SecurityOption 'Devices: Allow undock without having to log on' {
        Should -Be Enabled
    }

    SecurityOption 'User Account Control: Virtualize file and registry write failures to per user locations' {
        Should -Be Enabled
    }

    SecurityOption  'Accounts: Administrator account status' { 
        Should -Be Disabled 
    }

    # Testing that a security option is in a "not defined" (e.g unset) state.
    SecurityOption 'Accounts: Block Microsoft accounts' {
        Should -Be $null 
    }
}

Happy to write a wiki article for this new functionality if/when this PR is accepted.

markwragg commented 5 years ago

It seems I can't contribute it directly, but here's the wiki page for this new function:


SecurityOption

SYNOPSIS

Test a Local Security Policy Security Option.

DESCRIPTION

Test the setting of a particular Local Security Policy Security Option, as visible in the Local Security Policy MMC under Local Policies > Security Options.

PARAMETERS

Target [String]

[Parameter(
  Mandatory = $true,
  Position = 1
)]

The value provided to -Target needs to be one of the following:

Should [ScriptBlock]

[Parameter(
  Mandatory = $true,
  Position = 2,
)]

You need to test against the friendly version of the result (as visible in the Local Security Policy MMC). For example Disabled or Enabled not 1 or 0 (per the registry).

If you want to validate that a setting is in a "Not Defined" state (e.g unset) you should test for $null.

Assertions

Assertions: Be, BeExactly, Match, MatchExactly

EXAMPLES

-------------------------- EXAMPLE 1 --------------------------

SecurityOption 'Accounts: Administrator account status' {
    Should -Be Disabled
}

-------------------------- EXAMPLE 2 --------------------------

SecurityOption 'Domain member: Maximum machine account password age' {
    Should -Be 30
}

-------------------------- EXAMPLE 3 --------------------------

SecurityOption 'Accounts: Block Microsoft accounts' {
    Should -Be $null
}

-------------------------- EXAMPLE 4 --------------------------

SecurityOption 'Network access: Sharing and security model for local accounts' {
    Should -Be 'Classic - local users authenticate as themselves'
}
markwragg commented 5 years ago

@cdhunt any news on whether this can be merged?