Add tests for TimeZone cmdlets and FileCatalog cmdlets [SD:717473]

This commit is contained in:
PowerShell Team
2016-07-06 13:04:32 -07:00
committed by Dongbo Wang
parent b4641986a2
commit 45791aa030
21 changed files with 927 additions and 13 deletions
@@ -1,4 +1,4 @@
if ($IsWindows) {
if ($IsWindows -and !$IsCore) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
@@ -28,4 +28,4 @@ if ($IsWindows) {
} catch {$_.FullyQualifiedErrorId | Should Be "Microsoft.PowerShell.Commands.ClearEventLogCommand"}
}
}
}
}
@@ -1,4 +1,4 @@
if ($IsWindows) {
if ($IsWindows -and !$IsCore) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
@@ -0,0 +1,118 @@
# This is a Pester test suite to validate the cmdlets in the TimeZone module
#
# Copyright (c) Microsoft Corporation, 2016
<#
--------------------------------------
Script Notes: opportunities for improving this test script
--------------------------------------
Localization
Many of the tests below looking-up timezones by Name do not support localization.
That is, the current tests use us english versions of StandardName and DaylighName for tests.
ref: https://msdn.microsoft.com/en-us/library/windows/desktop/ms725481.aspx
[snippet] Both StandardName and DaylightName are localized according to the current user default UI language.
#>
function Assert-ListsSame
{
param([object[]] $expected, [object[]] $observed )
$compResult = Compare-Object $observed $expected | Select-Object -ExpandProperty InputObject
if ($compResult)
{
$observedList = ([string]::Join("|",$observed))
$expectedList = ([string]::Join("|",$expected))
$observedList | Should Be $expectedList
}
}
Describe "Get-Timezone test case no switches" -tags 'BVT' {
It "Call without ListAvailable switch returns current TimeZoneInfo" {
$observed = (Get-TimeZone).Id
$expected = ([System.TimeZoneInfo]::Local).Id
$observed -eq $expected | Should Be $true
}
}
Describe "Get-Timezone test cases" -tags 'Innerloop','RI' {
It "Call without ListAvailable switch returns an object of type TimeZoneInfo" {
$result = (Get-TimeZone).GetType().Name
$result | Should Be "TimeZoneInfo"
}
It "Call WITH ListAvailable switch returns ArrayList of TimeZoneInfo objects where the list is greater than 0 item" {
$list = Get-TimeZone -ListAvailable
$list.Count -gt 0 | Should Be $true
$list.GetType().Name | Should Be "Object[]"
$list[0].GetType().Name | Should Be "TimeZoneInfo"
}
It "Call with ListAvailable switch returns a list containing TimeZoneInfo.Local" {
$observedIdList = Get-TimeZone -ListAvailable | select -ExpandProperty Id
$oneExpectedId = ([System.TimeZoneInfo]::Local).Id
$observedIdList -contains $oneExpectedId | Should Be $true
}
It "Call with ListAvailable switch returns a list containing one returned by Get-TimeZone" {
$observedIdList = Get-TimeZone -ListAvailable | select -ExpandProperty Id
$oneExpectedId = (Get-TimeZone).Id
$observedIdList -contains $oneExpectedId | Should Be $true
}
It "Call Get-TimeZone using ID param and single item" {
(Get-TimeZone -Id "Cape Verde Standard Time").Id -eq "Cape Verde Standard Time" | Should Be $true
}
It "Call Get-TimeZone using ID param and multiple items" {
$idList = @("Cape Verde Standard Time","Morocco Standard Time","Azores Standard Time")
$result = (Get-TimeZone -Id $idList).Id
Assert-ListsSame $result $idList
}
It "Call Get-TimeZone using ID param and multiple items, where first and third are invalid ids - expect error" {
$null = Get-TimeZone -Id @("Cape Verde Standard","Morocco Standard Time","Azores Standard") `
-ErrorVariable errVar -ErrorAction SilentlyContinue
$errVar.Count -eq 2 | Should Be $true
$errVar[0].FullyQualifiedErrorID | Should Be "TimeZoneNotFound,Microsoft.PowerShell.Commands.GetTimeZoneCommand"
}
It "Call Get-TimeZone using ID param and multiple items, one is wild card but error action ignore works as expected" {
$result = Get-TimeZone -Id @("Cape Verde Standard Time","Morocco Standard Time","*","Azores Standard Time") `
-ErrorAction SilentlyContinue | % Id
$expectedIdList = @("Cape Verde Standard Time","Morocco Standard Time","Azores Standard Time")
Assert-ListsSame $expectedIdList $result
}
It "Call Get-TimeZone using Name param and singe item" {
$timezoneList = Get-TimeZone -ListAvailable
$timezoneName = $timezoneList[0].StandardName
$observed = Get-TimeZone -Name $timezoneName
$observed.StandardName -eq $timezoneName | Should Be $true
}
It "Call Get-TimeZone using Name param with wild card" {
$result = (Get-TimeZone -Name "Pacific*").Id
$expectedIdList = @("Pacific Standard Time (Mexico)","Pacific Standard Time","Pacific SA Standard Time")
Assert-ListsSame $expectedIdList $result
}
It "Verify that alias 'gtz' exists" {
(Get-Alias -Name "gtz").Name | Should Be "gtz"
}
It "Call Get-TimeZone Name parameter from pipeline by value " {
$result = ("Pacific*" | Get-TimeZone).Id
$expectedIdList = @("Pacific Standard Time (Mexico)","Pacific Standard Time","Pacific SA Standard Time")
Assert-ListsSame $expectedIdList $result
}
It "Call Get-TimeZone Id parameter from pipeline by ByPropertyName" {
$timezoneList = Get-TimeZone -ListAvailable
$timezone = $timezoneList[0]
$observed = $timezone | Get-TimeZone
$observed.StandardName -eq $timezone.StandardName | Should Be $true
}
}
@@ -1,4 +1,4 @@
if ($IsWindows) {
if ($IsWindows -and !$IsCore) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
@@ -44,4 +44,4 @@
$result.EventID | Should be 4
}
}
}
}
@@ -1,4 +1,4 @@
if ($IsWindows) {
if ($IsWindows -and !$IsCore) {
#check to see whether we're running as admin in Windows...
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
@@ -28,4 +28,4 @@
} catch {$_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
}
}
}
}
@@ -0,0 +1,133 @@
# This is a Pester test suite to validate the cmdlets in the TimeZone module
#
# Copyright (c) Microsoft Corporation, 2016
<#
--------------------------------------
Script Notes: opportunities for improving this test script
--------------------------------------
Localization
Many of the tests below looking-up timezones by Name do not support localization.
That is, the current tests use us english versions of StandardName and DaylighName for tests.
ref: https://msdn.microsoft.com/en-us/library/windows/desktop/ms725481.aspx
[snippet] Both StandardName and DaylightName are localized according to the current user default UI language.
#>
function Assert-ListsSame
{
param([object[]] $expected, [object[]] $observed )
$compResult = Compare-Object $observed $expected | Select-Object -ExpandProperty InputObject
if ($compResult)
{
$observedList = ([string]::Join("|",$observed))
$expectedList = ([string]::Join("|",$expected))
$observedList | Should Be $expectedList
}
}
Describe "Set-Timezone test case: call by single Id" -tags 'BVT' {
$originalTimeZoneId
BeforeAll {
$originalTimeZoneId = (Get-TimeZone).Id
}
AfterAll {
Set-TimeZone -ID $originalTimeZoneId
}
It "Call Set-TimeZone by Id" {
$origTimeZoneID = (Get-TimeZone).Id
$timezoneList = Get-TimeZone -ListAvailable
$testTimezone = $null
foreach($timezone in $timezoneList)
{
if ($timezone.Id -ne $origTimeZoneID)
{
$testTimezone = $timezone
break
}
}
Set-TimeZone -Id $testTimezone.Id
$observed = Get-TimeZone
$testTimezone.Id -eq $observed.Id | Should Be $true
}
}
Describe "Set-Timezone test cases" -tags 'Innerloop','RI' {
$originalTimeZoneId
BeforeAll {
$originalTimeZoneId = (Get-TimeZone).Id
}
AfterAll {
Set-TimeZone -ID $originalTimeZoneId
}
It "Call Set-TimeZone with invalid Id" {
$exception = $null
try { Set-TimeZone -Id "zzInvalidID" } catch { $exception = $_ }
$exception.FullyQualifiedErrorID | Should Be "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand"
}
It "Call Set-TimeZone by Name" {
$origTimeZoneName = (Get-TimeZone).StandardName
$timezoneList = Get-TimeZone -ListAvailable
$testTimezone = $null
foreach($timezone in $timezoneList)
{
if ($timezone.StandardName -ne $origTimeZoneName)
{
$testTimezone = $timezone
break
}
}
Set-TimeZone -Name $testTimezone.StandardName
$observed = Get-TimeZone
$testTimezone.StandardName -eq $observed.StandardName | Should Be $true
}
It "Call Set-TimeZone with invalid Name" {
$exception = $null
try { Set-TimeZone -Name "zzINVALID_Name" } catch { $exception = $_ }
$exception.FullyQualifiedErrorID | Should Be "TimeZoneNotFound,Microsoft.PowerShell.Commands.SetTimeZoneCommand"
}
It "Verify that alias 'stz' exists" {
(Get-Alias -Name "stz").Name | Should Be "stz"
}
It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo" {
$origTimeZoneID = (Get-TimeZone).Id
$timezoneList = Get-TimeZone -ListAvailable
$testTimezone = $null
foreach($timezone in $timezoneList)
{
if ($timezone.Id -ne $origTimeZoneID)
{
$testTimezone = $timezone
break
}
}
$testTimezone | Set-TimeZone
$observed = Get-TimeZone
$observed.ID -eq $testTimezone.Id | Should Be $true
}
It "Call Set-TimeZone from pipeline input object of type TimeZoneInfo, verify supports whatif" {
$origTimeZoneID = (Get-TimeZone).Id
$timezoneList = Get-TimeZone -ListAvailable
$testTimezone = $null
foreach($timezone in $timezoneList)
{
if ($timezone.Id -ne $origTimeZoneID)
{
$testTimezone = $timezone
break
}
}
Set-TimeZone -Id $testTimezone.Id -WhatIf > $null
$observed = Get-TimeZone
$observed.Id -eq $origTimeZoneID | Should Be $true
}
}
@@ -0,0 +1,377 @@
# This is a Pester test suite to validate the New-FileCatalog & Test-FileCatalog cmdlets on PowerShell Core.
#
# Copyright (c) Microsoft Corporation, 2016
#
$script:catalogPath = ""
Describe "Test suite for NewFileCatalogAndTestFileCatalogCmdlets" -Tags "Innerloop","BVT" {
#compare two hashtables
function CompareHashTables
{
param
(
$hashTable1,
$hashTable2
)
foreach ($key in $hashTable1.keys)
{
$keyValue1 = $hashTable1["$key"]
if($hashTable2.ContainsKey($key))
{
$keyValue2 = $hashTable2["$key"]
$keyValue1 | Should Be $keyValue2
}
else
{
throw "Failed to find the file $keyValue1 for $key in Hashtable"
}
}
}
BeforeAll {
$testDataPath = "$PSScriptRoot\TestData\CatalogTestData"
}
Context "NewAndTestCatalogTests PositiveTestCases when validation Succeeds" {
It "NewFileCatalogFolder" {
$sourcePath = Join-Path $testDataPath 'UserConfigProv\DSCResources\scriptdsc'
$catalogPath = "$testDataPath\NewFileCatalogFolder.cat"
try
{
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -Detailed
}
finally
{
Remove-Item $catalogPath -Force -ErrorAction SilentlyContinue
}
# Validate result properties
$result.Status | Should Be "Valid"
$result.Signature.Status | Should Be "NotSigned"
$result.HashAlgorithm | Should Be "SHA1"
}
It "NewFileCatalogFolderWithSubFolders" {
$sourcePath = Join-Path $testDataPath 'UserConfigProv'
# use non existant Path for the directory when .cat file name is specified
$catalogPath = "$testDataPath\OutPutCatalog\NewFileCatalogFolderWithSubFolders.cat"
try
{
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath
$result = Test-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath -Detailed
}
finally
{
Remove-Item "$sourcePath\OutPutCatalog" -Force -ErrorAction SilentlyContinue -Recurse
}
# Validate result properties
$result.Status | Should Be "Valid"
$result.Signature.Status | Should Be "NotSigned"
$result.HashAlgorithm | Should Be "SHA1"
}
It "NewFileCatalogWithSingleFile" {
$sourcePath = Join-Path $testDataPath '\CatalogTestFile1.mof'
# use existant Path for the directory when .cat file name is not specified
$catalogPath = $testDataPath
try
{
$null = New-FileCatalog -Path $sourcePath -CatalogFilePath $catalogPath
$result = Test-FileCatalog -Path $sourcePath -CatalogFilePath ($catalogPath + "\catalog.cat")
}
finally
{
Remove-Item "$catalogPath\catalog.cat" -Force -ErrorAction SilentlyContinue
}
# Validate result properties
$result | Should Be "Valid"
}
It "NewFileCatalogForFilesThatDoNotSupportEmbeddedSignatures" {
$expectedPathsAndHashes = @{ "TestImage.gif" = "B0E4B9F0BB21284AA0AF0D525C913420AD73DA6A" ;
"TestFileCatalog.txt" = "925834D22A8AEB8E0A5EAFABC739F8AFAAD3E490" }
# use non existant Path for the directory when .cat file name is not specified
$catalogPath = "$testDataPath\OutPutCatalog"
try
{
$null = New-FileCatalog -Path "$testDataPath\TestImage.gif","$testDataPath\TestFileCatalog.txt" -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path "$testDataPath\TestImage.gif","$testDataPath\TestFileCatalog.txt" -CatalogFilePath ($catalogPath + "\catalog.cat") -Detailed
}
finally
{
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue -Recurse
}
$result.Status | Should Be "Valid"
$result.CatalogItems.Count | Should Be 2
$result.PathItems.Count | Should Be 2
CompareHashTables $result.CatalogItems $result.PathItems
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
}
It "NewFileCatalogWithMutipleFoldersAndFiles" {
$expectedPathsAndHashes = @{
"UserConfigProv.psd1" = "748E5486814051DA3DFB79FE8964152727213248" ;
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.schema.mof" ="F7CAB050E32CF0C9B2AC2807C4F24D31EFCC8B61";
"dscresources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.psm1" = "F9DD6B02C7BD0FB98A25BE0D41210B2A2333E139";
"DSCResources\scriptdsc\scriptDSC.schema.psm1"= "CDBAF85FEDE2E0CD09B1AEA0532010CEFCECBC12";
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1" = "7599777B85B60377B1F3E492C817190090A754A7"
"DSCResources\scriptdsc\scriptdsc.psd1"= "CDDC68AF9B863760A14031772DC9ADDAFD209D80";
"DSCResources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.schema.mof" ="AFEB46104F506FC64CAB4B0B2A9C6C50622B487A";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.psm1"= "60CB9C8AEDA7A64127D34361ED4F30DEAFE37022";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.schema.mof" = "E33FBFEA28E9A8FBA793FBC3D8015BCC9A10944B";
"CatalogTestFile1.mof" = "083B0953D0D70FFF62710F0356FEB86BCE327FE7";
"CatalogTestFile2.xml" = "E73BB7A0DD9FAC6A8182F67B750D9CA3094490F1" }
$catalogPath = "$env:TEMP\NewFileCatalogWithMutipleFoldersAndFiles.cat"
$catalogDataPath = @("$testDataPath\UserConfigProv\","$testDataPath\CatalogTestFile1.mof","$testDataPath\CatalogTestFile2.xml")
try
{
$null =New-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -Detailed
}
finally
{
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue
}
$result.Status | Should Be "Valid"
$result.Signature.Status | Should Be "NotSigned"
$result.HashAlgorithm | Should Be "SHA1"
$result.CatalogItems.Count | Should Be 11
$result.PathItems.Count | Should Be 11
CompareHashTables $result.CatalogItems $result.PathItems
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
}
It "NewFileCatalogVersion2WithMutipleFoldersAndFiles" {
$expectedPathsAndHashes = @{
"UserConfigProv.psd1" = "9FFE4CA2873CD91CDC9D71362526446ECACDA64D26DEA768E6CE489B84D888E4" ;
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.schema.mof" ="517F625CB6C465928586F5C613F768B33C20F477DAF843C179071B8C74B992AA";
"DSCResources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.psm1" = "0774A539E73B1A480E38CFFE2CF0B8AC46120A0B2E0377E0DE2630031BE83347";
"DSCResources\scriptdsc\scriptdsc.schema.psm1"= "7DE80DED0F96FA7D34CF34089A1B088E91CD7B1D80251949FC7C78A6308D51C3";
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1" = "EB0310C630EDFDFBDD1D993A636EC9B75BB1F04DF7E7FFE39CF6357679C852C7"
"DSCResources\scriptdsc\scriptdsc.psd1"= "AB8E8D0840D4854CDCDE25058872413AF417FC016BD77FD5EC677BBB7393532B";
"DSCResources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.schema.mof" ="7163E607F067A3C4F91D3AFF3C466ECA47C0CF84B5F0DDA22B2C0E99929B5E21";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.psm1"= "6591FE02528D7FB66F00E09D7F1A025D5D5BAF30A49C5FF1EC562FAE39B38F43";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.schema.mof" = "679318201B012CC5936B29C095956B2131FAF828C0CCA4342A5914F721480FB9";
"CatalogTestFile1.mof" = "7C1885AE5F76F58DAA232A5E962875F90308C3CB8580400EE12F999B4E10F940";
"CatalogTestFile2.xml" = "00B7DA28CD285F796660D36B77B2EC6054F21A44D5B329EB6BC4EC7687D70B13";
"TestImage.gif" = "2D938D255D0D6D547747BD21447CF7295318D34D9B4105D04C1C27487D2FF402" }
$catalogPath = "$env:TEMP\NewFileCatalogVersion2WithMutipleFoldersAndFiles.cat"
$catalogDataPath = @("$testDataPath\UserConfigProv\","$testDataPath\CatalogTestFile1.mof","$testDataPath\CatalogTestFile2.xml", "$testDataPath\TestImage.gif")
try
{
$null = New-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -CatalogVersion 2.0
$result = Test-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -Detailed
}
finally
{
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue
}
$result.Status | Should Be "Valid"
$result.Signature.Status | Should Be "NotSigned"
$result.HashAlgorithm | Should Be "SHA256"
$result.CatalogItems.Count | Should Be 12
$result.PathItems.Count | Should Be 12
CompareHashTables $result.CatalogItems $result.PathItems
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
}
It "NewFileCatalogFolderWhenCatlogFileIsCreatedInsideSameFolder" {
$catalogPath = "$env:TEMP\UserConfigProv\NewFileCatalogFolderWhenCatlogFileIsCreatedInsideSameFolder.cat"
try
{
copy-item $testDataPath\UserConfigProv $env:temp -Recurse -ErrorAction SilentlyContinue
$null = New-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $env:temp\UserConfigProv\ -CatalogFilePath $catalogPath
}
finally
{
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue
Remove-Item "$env:temp\UserConfigProv\" -Force -ErrorAction SilentlyContinue -Recurse
}
$result | Should Be "Valid"
}
It "NewFileCatalogWithUnicodeCharactersInFileNames" {
$expectedPathsAndHashes = @{
"UserConfigProv.psd1" = "9FFE4CA2873CD91CDC9D71362526446ECACDA64D26DEA768E6CE489B84D888E4" ;
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.schema.mof" ="517F625CB6C465928586F5C613F768B33C20F477DAF843C179071B8C74B992AA";
"DSCResources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.psm1" = "0774A539E73B1A480E38CFFE2CF0B8AC46120A0B2E0377E0DE2630031BE83347";
"DSCResources\scriptdsc\scriptdsc.schema.psm1"= "7DE80DED0F96FA7D34CF34089A1B088E91CD7B1D80251949FC7C78A6308D51C3";
"DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1" = "EB0310C630EDFDFBDD1D993A636EC9B75BB1F04DF7E7FFE39CF6357679C852C7"
"DSCResources\scriptdsc\scriptdsc.psd1"= "AB8E8D0840D4854CDCDE25058872413AF417FC016BD77FD5EC677BBB7393532B";
"DSCResources\UserConfigProviderModVersion3\UserConfigProviderModVersion3.schema.mof" ="7163E607F067A3C4F91D3AFF3C466ECA47C0CF84B5F0DDA22B2C0E99929B5E21";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.psm1"= "6591FE02528D7FB66F00E09D7F1A025D5D5BAF30A49C5FF1EC562FAE39B38F43";
"DSCResources\UserConfigProviderModVersion2\UserConfigProviderModVersion2.schema.mof" = "679318201B012CC5936B29C095956B2131FAF828C0CCA4342A5914F721480FB9";
"ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ.txt" = "EFD0AE8FF12C7387D51FFC03259B60E06DA012BF7D3B7B9D3480FAB2864846CE";
"ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ.txt" = "9FB57660EDD8DA898A9F1E7F5A36B8B760B4A21625F9968D87A32A55B3546BF9"}
# Create Test Files with unicode characters in names and content
$unicodeTempDir = Join-Path -Path $testDataPath -ChildPath "UnicodeTestDir"
$null = New-Item -ItemType Directory -Path $unicodeTempDir -Force
$null = New-Item -ItemType File -Path "$unicodeTempDir\ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ.txt" -Force -ErrorAction SilentlyContinue
$null = Add-Content -Path "$unicodeTempDir\ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ.txt" -Value "Testing unicode"
$null = Out-File -FilePath "$unicodeTempDir\ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ.txt" -Encoding unicode -InputObject "ɗ ɘ ə ɚ ɛ ɜ ɝ ɞ ɟ ɠ ɡ ɢ ɣ ɤ ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ ɭ ɮ ɯ ɰ ɱ ɲ ɳ ɴ ɵ ɶ ɷ ɸ ɹ ɺ ɻ ɼ ɽ ɾ ɿ ʀ ʁ ʂ ʃ ʄ ʅ" -Append
$null = New-Item -ItemType File -Path "$unicodeTempDir\ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ.txt" -Force -ErrorAction SilentlyContinue
$null = Out-File -FilePath "$unicodeTempDir\ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ.txt" -Encoding unicode -InputObject "ਅ ਆ ਇ ਈ ਉ ਊ ਏ ਐ ਓ ਔ ਕ ਖ ਗ ਘ ਙ ਚ ਛ ਜ ਝ ਞ ਟ ਠ ਡ ਢ ਣ ਤ ਥ ਦ ਧ ਨ ਪ ਫ ਬ ਭ ਮ ਯ ਰ ਲ ਲ਼ ਵ " -Append
$null = Out-File -FilePath "$unicodeTempDir\ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ.txt" -Encoding unicode -InputObject "அ ஆ இ ஈ உ ஊ எ ஏ ஐ ஒ ஓ ஔ க ங ச ஜ ஞ ட ண த ந ன ப ம ய ர ற ல ள ழ வ ஷ ஸ ஹ " -Append
$catalogPath = "$env:TEMP\క ఖ గ ఘ ఙ చ ఛ జ ఝ ఞ.cat"
$catalogDataPath = @("$testDataPath\UserConfigProv\", "$unicodeTempDir\ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ.txt" ,"$unicodeTempDir\ɥ ɦ ɧ ɨ ɩ ɪ ɫ ɬ.txt")
try
{
$null = New-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -CatalogVersion 2.0
$result = Test-FileCatalog -Path $catalogDataPath -CatalogFilePath $catalogPath -Detailed
}
finally
{
Remove-Item $unicodeTempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$catalogPath" -Force -ErrorAction SilentlyContinue
}
$result.Status | Should Be "Valid"
$result.Signature.Status | Should Be "NotSigned"
$result.HashAlgorithm | Should Be "SHA256"
$result.CatalogItems.Count | Should Be 11
$result.PathItems.Count | Should Be 11
CompareHashTables $result.CatalogItems $result.PathItems
CompareHashTables $result.CatalogItems $expectedPathsAndHashes
}
}
Context "NewAndTestCatalogTests NegativeTestCases when creation or validation Fails"{
AfterEach {
Remove-Item "$script:catalogPath" -Force -ErrorAction SilentlyContinue
Remove-Item "$env:temp\UserConfigProv" -Force -Recurse -ErrorAction SilentlyContinue
}
It "TestCatalogWhenNewFileAddedtoFolderBeforeValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogWhenNewFileAddedtoFolderBeforeValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 2.0
$null = copy-item $testDataPath\UserConfigProv $env:temp -Recurse -ErrorAction SilentlyContinue
$null = New-Item $env:temp\UserConfigProv\DSCResources\NewFile.txt -ItemType File
Add-Content $env:temp\UserConfigProv\DSCResources\NewFile.txt -Value "More Data" -force
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed
$result.Status | Should Be "ValidationFailed"
$result.CatalogItems.Count | Should Be 9
$result.PathItems.Count | Should Be 10
$result.CatalogItems.ContainsKey("DSCResources\NewFile.txt") | Should Be $false
$result.PathItems.ContainsKey("DSCResources\NewFile.txt") | Should Be $true
# By Skipping the new added file validation will pass
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed -FilesToSkip "NewFile.txt"
$result.Status | Should Be "Valid"
}
It "TestCatalogWhenNewFileDeletedFromFolderBeforeValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogWhenNewFileDeletedFromFolderBeforeValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 1.0
$null = copy-item $testDataPath\UserConfigProv $env:temp -Recurse -ErrorAction SilentlyContinue
del $env:temp\UserConfigProv\DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1 -force -ErrorAction SilentlyContinue
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed
$result.Status | Should Be "ValidationFailed"
$result.CatalogItems.Count | Should Be 9
$result.PathItems.Count | Should Be 8
$result.CatalogItems.ContainsKey("DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1") | Should Be $true
$result.PathItems.ContainsKey("DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1") | Should Be $false
# By Skipping the deleted file validation will pass
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed -FilesToSkip "UserConfigProviderModVersion1.psm1"
$result.Status | Should Be "Valid"
}
It "TestCatalogWhenFileContentModifiedBeforeValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogWhenFileContentModifiedBeforeValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 1.0
$null = copy-item $testDataPath\UserConfigProv $env:temp -Recurse -ErrorAction SilentlyContinue
Add-Content $env:temp\UserConfigProv\DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1 -Value "More Data" -Force
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed
$result.Status | Should Be "ValidationFailed"
$result.CatalogItems.Count | Should Be 9
$result.PathItems.Count | Should Be 9
$catalogHashValue = $result.CatalogItems["DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1"]
$pathHashValue = $result.PathItems["DSCResources\UserConfigProviderModVersion1\UserConfigProviderModVersion1.psm1"]
($catalogHashValue -eq $pathHashValue) | Should Be $false
# By Skipping the file with modifed contents validation will pass
$result = Test-FileCatalog -Path $env:temp\UserConfigProv -CatalogFilePath $script:catalogPath -Detailed -FilesToSkip "UserConfigProviderModVersion1.psm1"
$result.Status | Should Be "Valid"
}
}
Context "TestCatalog Skip Validation Tests"{
AfterEach {
Remove-Item "$script:catalogPath" -Force -ErrorAction SilentlyContinue
}
It "TestCatalogSkipSingleFileDuringValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogSkipSingleFileDuringValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 2.0
$result = Test-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -FilesToSkip "scriptdsc.schema"
$result | Should Be "Valid"
}
It "TestCatalogSkipCertainFileTypeDuringValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogSkipCertainFileTypeDuringValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 2.0
$result = Test-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -FilesToSkip "*.mof"
$result | Should Be "Valid"
}
It "TestCatalogSkipWildCardPatternDuringValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogSkipWildCardPatternDuringValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -FilesToSkip "UserConfigProvider*.psm1"
$result | Should Be "Valid"
}
It "TestCatalogSkipMuitplePattensDuringValidation" {
$script:catalogPath = "$env:TEMP\TestCatalogSkipMuitplePattensDuringValidation.cat"
$null = New-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -CatalogVersion 1.0
$result = Test-FileCatalog -Path $testDataPath\UserConfigProv\ -CatalogFilePath $script:catalogPath -FilesToSkip "*.psd1","UserConfigProviderModVersion2.psm1","*ModVersion1.schema.mof"
$result | Should Be "Valid"
}
}
}
@@ -0,0 +1,49 @@
<MachineInventory aliasing="True">
<Machine machineRole="Server">
<Accounts>
<LocalAdmin user="root" password="Bull_dog1" />
</Accounts>
<BMCMachine>No</BMCMachine>
<BranchName>Linux</BranchName>
<BuildNumber>CentOS</BuildNumber>
<BuildType>Fre</BuildType>
<Factory>00000000-0000-0000-0000-000000000000</Factory>
<HyperVEnabled>No</HyperVEnabled>
<IPV4>Yes</IPV4>
<IPV4Address>
<ip>$ipAddress</ip>
</IPV4Address>
<IPV6>Yes</IPV6>
<IPV6Address>
<ip>2001:4898:28:3:215:5dff:feb8:b9b3</ip>
</IPV6Address>
<MachineName>Linux1</MachineName>
<Membership>Workgroup</Membership>
<NetworkLocation>None</NetworkLocation>
<OSArchitecture>X64</OSArchitecture>
<OSBaseLanguage>en-US</OSBaseLanguage>
<Platform>Windows 8 Server</Platform>
<ProcessorArchitecture>X64</ProcessorArchitecture>
<SKU>Server DataCenter</SKU>
<ServicePack>None</ServicePack>
<Subnet>Unknown</Subnet>
<SystemDrive>C:\</SystemDrive>
<VirtualMachine>No</VirtualMachine>
<WSManListeners>
<WSManListener Port="5985" URLPrefix="wsman" UseSSL="False" DefaultListener="True" ServiceType="OMI">
<AuthSchemes>
<AuthScheme>Basic</AuthScheme>
</AuthSchemes>
<Capabilities>
</Capabilities>
</WSManListener>
<WSManListener Port="5986" URLPrefix="wsman" UseSSL="True" ServiceType="OMI">
<AuthSchemes>
<AuthScheme>Basic</AuthScheme>
</AuthSchemes>
<Capabilities>
</Capabilities>
</WSManListener>
</WSManListeners>
</Machine>
</MachineInventory>
@@ -0,0 +1 @@
Text File to test catalog
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

@@ -0,0 +1,61 @@
# The Get-TargetResource cmdlet is used to fetch the desired state of the DSC managed node through a powershell script.
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the inormation
# gathered from the GetScript execution.
function Get-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$result = @{
Text = "Hello from Get!";
}
$result;
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrasturcure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$path = "$env:SystemDrive\dscTestPath\hello1.txt"
New-Item -Path $path -Type File -force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
}
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0")]
class UserConfigProviderModVersion1 : OMI_BaseResource
{
[key] string Text;
};
@@ -0,0 +1,62 @@
# The Get-TargetResource cmdlet is used to fetch the desired state of the DSC managed node through a powershell script.
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the inormation
# gathered from the GetScript execution.
function Get-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$result = @{
Text = "Hello from Get!";
}
$result;
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrasturcure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$path = "$env:SystemDrive\dscTestPath\hello2.txt"
New-Item -Path $path -Type File -force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
}
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0")]
class UserConfigProviderModVersion2 : OMI_BaseResource
{
[key] string Text;
};
@@ -0,0 +1,62 @@
# The Get-TargetResource cmdlet is used to fetch the desired state of the DSC managed node through a powershell script.
# This cmdlet executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution is in the form of a hashtable containing all the inormation
# gathered from the GetScript execution.
function Get-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$result = @{
Text = "Hello from Get!";
}
$result;
}
# The Set-TargetResource cmdlet is used to Set the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). If the DSC managed node requires a restart either during or after the execution of the SetScript,
# the SetScript notifies the PS Infrasturcure by setting the variable $DSCMachineStatus.IsRestartRequired to $true.
function Set-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$path = "$env:SystemDrive\dscTestPath\hello3.txt"
New-Item -Path $path -Type File -force
Add-Content -Path $path -Value $text
}
# The Test-TargetResource cmdlet is used to validate the desired state of the DSC managed node through a powershell script.
# The method executes the user supplied script (i.e., the script is responsible for validating the desired state of the
# DSC managed node). The result of the script execution should be true if the DSC managed machine is in the desired state
# or else false should be returned.
function Test-TargetResource
{
[CmdletBinding()]
param
(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
$text
)
$false
}
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0")]
class UserConfigProviderModVersion3 : OMI_BaseResource
{
[key] string Text;
};
@@ -0,0 +1,15 @@
configuration scriptdsc
{
param ($one, $two, $three)
Import-DscResource -ModuleName UserConfigProv
Log scriptDscLogResource
{
Message = "This is the message from the embedded log resource: one=$one two=$two three=$three"
}
}
Export-ModuleMember -Function scriptdsc
@@ -0,0 +1,12 @@
@{
ModuleVersion = '3.0.0.1'
Author = 'fayzas'
CompanyName = 'Microsoft Corporation'
Copyright = '(c) 2013 Microsoft Corporation. All rights reserved.'
Description = 'Hello World!'
PowerShellVersion = '3.0'
CLRVersion = '4.0'
RequiredModules = @()
# NestedModules = @("UserConfigProviderModVersion.psm1")
# FunctionsToExport = @("Get-TargetResource", "Set-TargetResource", "Test-TargetResource")
}
@@ -1,6 +1,6 @@
Describe "Compare-Object" {
BeforeAll {
$nl = [Environment]::NewLine
$nl = [Environment]::NewLine
$content1 = "line 1" + $nl + "line 2"
$content2 = "line 1" + $nl + "line 2.1"
@@ -12,10 +12,10 @@ Describe "Compare-Object" {
$file3 = Join-Path -Path $TestDrive -ChildPath "test3.txt"
$file4 = Join-Path -Path $TestDrive -ChildPath "test4.txt"
New-Item $file1 -ItemType file -Value $content1 -Force
New-Item $file2 -ItemType file -Value $content2 -Force
New-Item $file3 -ItemType file -Value $content3 -Force
New-Item $file4 -ItemType file -Value $content4 -Force
$null = New-Item $file1 -ItemType file -Value $content1 -Force
$null = New-Item $file2 -ItemType file -Value $content2 -Force
$null = New-Item $file3 -ItemType file -Value $content3 -Force
$null = New-Item $file4 -ItemType file -Value $content4 -Force
}
It "Should be able to compare the same object using the referenceObject and differenceObject switches" {
@@ -454,4 +454,4 @@ Describe "Compare-Object DRT basic functionality" -Tags DRT{
$result.InputObject | Should Be "refObject"
$result.SideIndicator | Should Be "<="
}
}
}