mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-09-04 14:45:23 +00:00
Handle excluded domains and preserve GPO date filters (#91)
* Fix offline domain handling and date filters * Make AD regression tests runner-independent
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
Describe 'Get-ADAdministrativeGroups domain filtering' {
|
||||
BeforeAll {
|
||||
Import-Module $PSScriptRoot\..\GPOZaurr.psm1 -Force
|
||||
}
|
||||
|
||||
It 'skips excluded and unreachable domains without indexing missing query servers' {
|
||||
InModuleScope GPOZaurr {
|
||||
function Get-ADDomain {
|
||||
param([string] $Server)
|
||||
}
|
||||
function Get-ADGroup {
|
||||
param(
|
||||
[string] $Filter,
|
||||
[string] $Server,
|
||||
[System.Management.Automation.ActionPreference] $ErrorAction
|
||||
)
|
||||
}
|
||||
|
||||
Mock Get-WinADForestDetails {
|
||||
[ordered] @{
|
||||
Forest = [PSCustomObject] @{ Domains = @('root.contoso.com', 'excluded.contoso.com', 'offline.contoso.com') }
|
||||
Domains = @('root.contoso.com', 'offline.contoso.com')
|
||||
QueryServers = @{
|
||||
'root.contoso.com' = @{ HostName = @('dc1.root.contoso.com') }
|
||||
}
|
||||
}
|
||||
}
|
||||
Mock Get-ADDomain {
|
||||
[PSCustomObject] @{
|
||||
DomainSID = 'S-1-5-21-1-2-3'
|
||||
NetBIOSName = 'ROOT'
|
||||
}
|
||||
}
|
||||
Mock Get-ADGroup {
|
||||
[PSCustomObject] @{
|
||||
Name = if ($Filter -match '519') { 'Enterprise Admins' } else { 'Domain Admins' }
|
||||
ObjectClass = 'group'
|
||||
SID = [PSCustomObject] @{ Value = if ($Filter -match '519') { 'S-1-5-21-1-2-3-519' } else { 'S-1-5-21-1-2-3-512' } }
|
||||
}
|
||||
}
|
||||
|
||||
$Result = Get-ADAdministrativeGroups -Type DomainAdmins, EnterpriseAdmins -ExcludeDomains 'excluded.contoso.com'
|
||||
|
||||
$Result['ByNetBIOS'].Keys | Should -Contain 'ROOT\Domain Admins'
|
||||
$Result['ByNetBIOS'].Keys | Should -Contain 'ROOT\Enterprise Admins'
|
||||
$Result.Keys | Should -Not -Contain 'excluded.contoso.com'
|
||||
Should -Invoke -CommandName Get-ADDomain -Times 2 -Exactly -ParameterFilter { $Server -eq 'dc1.root.contoso.com' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
Describe 'GPO date filters' {
|
||||
BeforeAll {
|
||||
Import-Module $PSScriptRoot\..\GPOZaurr.psm1 -Force
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
InModuleScope GPOZaurr {
|
||||
Mock Get-WinADForestDetails {
|
||||
[ordered] @{
|
||||
Domains = @('root.contoso.com')
|
||||
QueryServers = @{ 'root.contoso.com' = @{ HostName = @('dc1.root.contoso.com') } }
|
||||
}
|
||||
}
|
||||
Mock Get-ChoosenDates {
|
||||
[PSCustomObject] @{
|
||||
DateFrom = [datetime] '2026-08-01'
|
||||
DateTo = [datetime] '2026-08-08'
|
||||
}
|
||||
}
|
||||
Mock Get-ADObject {}
|
||||
}
|
||||
}
|
||||
|
||||
It 'keeps DateTime variables intact in Get-GPOZaurrAD filters' {
|
||||
InModuleScope GPOZaurr {
|
||||
Get-GPOZaurrAD -DateRange Last7Days -DateProperty WhenCreated
|
||||
|
||||
Should -Invoke -CommandName Get-ADObject -Times 1 -Exactly -ParameterFilter {
|
||||
$Filter -eq "(objectClass -eq 'groupPolicyContainer') -and (WhenCreated -ge `$DateFrom -and WhenCreated -le `$DateTo)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
It 'keeps DateTime variables intact in Get-GPOZaurrRedirect filters' {
|
||||
InModuleScope GPOZaurr {
|
||||
Get-GPOZaurrRedirect -DateRange Last7Days -DateProperty WhenChanged
|
||||
|
||||
Should -Invoke -CommandName Get-ADObject -Times 1 -Exactly -ParameterFilter {
|
||||
$Filter -eq "(objectClass -eq 'groupPolicyContainer') -and (WhenChanged -ge `$DateFrom -and WhenChanged -le `$DateTo)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user