From 24f9dea287b42e19d655adcfbb02714d8207b0fe Mon Sep 17 00:00:00 2001 From: "James Truher [MSFT]" Date: Thu, 29 Sep 2016 16:23:12 -0700 Subject: [PATCH] Add tests for queries against userdata (#2388) add a custom evtx file for the userdata tests to use --- .../Get-WinEvent.Tests.ps1 | 33 +++++++++++++++++- .../assets/Saved-Events.evtx | Bin 0 -> 69632 bytes 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 index 8841f7181..77cfca748 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 @@ -73,8 +73,39 @@ Describe 'Get-WinEvent' -Tags "CI" { $results = Get-WinEvent -logname $logname -filterXPath $xpathFilter -max 3 $results | should Not BeNullOrEmpty } + } - # Get-WinEvent works only on windows + Context "Get-WinEvent UserData Queries" { + It 'Get-WinEvent can retrieve events with UserData queries using FilterXml' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = "" + $results = Get-WinEvent -FilterXml $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + <# + It 'Get-WinEvent can retrieve events with UserData queries using FilterHashtable' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = @{ path = "$eventLogFile"; Param2 = "Windows x64"} + $results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + #> + It 'Get-WinEvent can retrieve events with UserData queries using FilterXPath' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = "*/UserData/*/Param2='Windows x64'" + $results = Get-WinEvent -path $eventLogFile -filterXPath $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + } # Get-WinEvent works only on windows It 'can query a System log' { Get-WinEvent -LogName System -MaxEvents 1 | Should Not BeNullOrEmpty } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx new file mode 100644 index 0000000000000000000000000000000000000000..9427f037a0329aef851ebe0a37e2c03358a4e5f4 GIT binary patch literal 69632 zcmeI2e`wri9mhZ4%l*nFxg<*y=GfL-9ks2t>954rZfcg?xw55;YiBFQjazatX_8CG zU1wrd0^O`rkjgp)hq4JGgQ1|5l_LHjY%u?5QP9l^{!=C*2yXMo{u%N8e!kzQxjS36 zHVVP_b9{5p^L#(gkMHaA>-iqZ&rB4iW=hsr5>dx8z5{DA>j)Y}Zn*ueAARB38=gcH zh=2%)fCz|y2#A0Ph=2%)fCz|y2>eR|`I(8q$?`Pb@xv02z8l-i=-;xzEZ1Xp>8lUk z9EttMU!4CNUpaHBc7ofIX1{4Si*=Z7#dWHA_3nX;+1>aVqOtq|{l2uK{xHV8P&4ku zn)_a^_WMPw$#PrtgU8>n#=|XUuSfm7_YC?bJQ#MMd<5-xVqyIj+~0*Uz62>>GkZRo zcNnq-%y|LhewAIlzm~Pl(SC-~^|SuqpRBiSo7p7x?)80s=}Q~m>iR{{9t74J{OR#$ z@_ts<^W85WYySDfOK01@-TDTegi-@5E5AmS56E(%HDP&s%t}_aD%z)UC67lpf83t1 zMVqx5+^pb6BIvV8h*fRgK4iW4RBQ}ACCC&}-+}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