Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveDirectoryDsc: Migrate HQRM And Unit Tests to PowerShell 7 #597

Merged
merged 16 commits into from
Apr 21, 2020
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

- ActiveDirectoryDsc
- Migrated to DscResource.Common Module.
- Testing HQRM and Unit Tests on PowerShell 7

## [6.0.1] - 2020-04-16

Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ stages:
inputs:
filePath: './build.ps1'
arguments: '-Tasks hqrmtest'
pwsh: false
pwsh: true
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: succeededOrFailed()
Expand Down Expand Up @@ -100,7 +100,7 @@ stages:
inputs:
filePath: './build.ps1'
arguments: "-Tasks test -PesterScript 'tests/Unit'"
pwsh: false
pwsh: true
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: succeededOrFailed()
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/MSFT_ADDomain/MSFT_ADDomain.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function Get-TargetResource
)

Assert-Module -ModuleName 'ADDSDeployment' -ImportModule

$domainFQDN = Resolve-DomainFQDN -DomainName $DomainName -ParentDomainName $ParentDomainName

# If the domain has been installed then the Netlogon SysVol registry item will exist.
Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ function Get-ThumbnailByteArray
if (Test-Path -Path $ThumbnailPhoto)
{
Write-Verbose -Message ($script:localizedData.LoadingThumbnailFromFile -f $ThumbnailPhoto)
$thumbnailPhotoAsByteArray = Get-Content -Path $ThumbnailPhoto -Encoding Byte
$thumbnailPhotoAsByteArray = Get-ByteContent -Path $ThumbnailPhoto
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'Get-CurrentUser'
'Test-Password'
'Test-PrincipalContextCredentials'
'Get-ByteContent'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2063,3 +2063,33 @@ function Test-PrincipalContextCredentials

return $result
}

<#
.SYNOPSIS
Returns the contents of a file as a byte array

.PARAMETER Path
Specifies the path to an item.
#>
function Get-ByteContent
{
[CmdletBinding()]
[OutputType([System.Byte[]])]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Path
)

if ($PSVersionTable.PSEdition -eq 'Core')
{
$content = Get-Content -Path $Path -AsByteStream
}
else
{
$content = Get-Content -Path $Path -Encoding 'Byte'
}

return $content
}
48 changes: 24 additions & 24 deletions tests/Unit/ActiveDirectoryDsc.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1427,14 +1427,14 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

$compareTargetResourceStateResult = Compare-ResourcePropertyState @compareTargetResourceStateParameters
$compareTargetResourceStateResult | Should -HaveCount 2
$compareTargetResourceStateResult[0].ParameterName | Should -Be 'ComputerName'
$compareTargetResourceStateResult[0].Expected | Should -Be 'DC01'
$compareTargetResourceStateResult[0].Actual | Should -Be 'DC01'
$compareTargetResourceStateResult[0].InDesiredState | Should -BeTrue
$compareTargetResourceStateResult[1].ParameterName | Should -Be 'Location'
$compareTargetResourceStateResult[1].Expected | Should -Be 'Sweden'
$compareTargetResourceStateResult[1].Actual | Should -Be 'Sweden'
$compareTargetResourceStateResult[1].InDesiredState | Should -BeTrue
$computerNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'ComputerName'
$computerNameResult.Expected | Should -Be 'DC01'
$computerNameResult.Actual | Should -Be 'DC01'
$computerNameResult.InDesiredState | Should -BeTrue
$locationNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'Location'
$locationNameResult.Expected | Should -Be 'Sweden'
$locationNameResult.Actual | Should -Be 'Sweden'
$locationNameResult.InDesiredState | Should -BeTrue
}
}

Expand Down Expand Up @@ -1485,14 +1485,14 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

$compareTargetResourceStateResult = Compare-ResourcePropertyState @compareTargetResourceStateParameters
$compareTargetResourceStateResult | Should -HaveCount 2
$compareTargetResourceStateResult[0].ParameterName | Should -Be 'ComputerName'
$compareTargetResourceStateResult[0].Expected | Should -Be 'DC01'
$compareTargetResourceStateResult[0].Actual | Should -Be 'DC01'
$compareTargetResourceStateResult[0].InDesiredState | Should -BeTrue
$compareTargetResourceStateResult[1].ParameterName | Should -Be 'Location'
$compareTargetResourceStateResult[1].Expected | Should -Be 'Europe'
$compareTargetResourceStateResult[1].Actual | Should -Be 'Sweden'
$compareTargetResourceStateResult[1].InDesiredState | Should -BeFalse
$computerNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'ComputerName'
$computerNameResult.Expected | Should -Be 'DC01'
$computerNameResult.Actual | Should -Be 'DC01'
$computerNameResult.InDesiredState | Should -BeTrue
$locationNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'Location'
$locationNameResult.Expected | Should -Be 'Europe'
$locationNameResult.Actual | Should -Be 'Sweden'
$locationNameResult.InDesiredState | Should -BeFalse
}
}

Expand Down Expand Up @@ -1579,14 +1579,14 @@ InModuleScope 'ActiveDirectoryDsc.Common' {

$compareTargetResourceStateResult = Compare-ResourcePropertyState @compareTargetResourceStateParameters
$compareTargetResourceStateResult | Should -HaveCount 2
$compareTargetResourceStateResult[0].ParameterName | Should -Be 'ComputerName'
$compareTargetResourceStateResult[0].Expected | Should -Be 'DC01'
$compareTargetResourceStateResult[0].Actual | Should -Be 'DC01'
$compareTargetResourceStateResult[0].InDesiredState | Should -BeTrue
$compareTargetResourceStateResult[1].ParameterName | Should -Be 'Location'
$compareTargetResourceStateResult[1].Expected | Should -Be 'Europe'
$compareTargetResourceStateResult[1].Actual | Should -Be 'Sweden'
$compareTargetResourceStateResult[1].InDesiredState | Should -BeFalse
$computerNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'ComputerName'
$computerNameResult.Expected | Should -Be 'DC01'
$computerNameResult.Actual | Should -Be 'DC01'
$computerNameResult.InDesiredState | Should -BeTrue
$locationNameResult = $compareTargetResourceStateResult | Where-Object -Property ParameterName -eq 'Location'
$locationNameResult.Expected | Should -Be 'Europe'
$locationNameResult.Actual | Should -Be 'Sweden'
$locationNameResult.InDesiredState | Should -BeFalse
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Unit/MSFT_ADKDSKey.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ try
InModuleScope $script:dscResourceName {
Set-StrictMode -Version 1.0

# Load stub cmdlets and classes.
# Load AD stub cmdlets and classes.
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\ActiveDirectory_2019.psm1') -Force

# Load KDS stub cmdlets and classes.
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'Stubs\Kds.psm1') -Force

# Need to do a deep copy of the Array of objects that compare returns
function Copy-ArrayObjects
{
Expand Down
34 changes: 17 additions & 17 deletions tests/Unit/Stubs/ActiveDirectory_2019.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Version: 1.0.1.0
# CreatedOn: 2019-08-12 11:47:22Z

Add-Type -IgnoreWarnings -TypeDefinition @'
Add-Type -IgnoreWarnings -WarningAction SilentlyContinue -TypeDefinition @'
namespace Microsoft.ActiveDirectory.Management
{
public class ADAccount
Expand All @@ -11,14 +11,14 @@ namespace Microsoft.ActiveDirectory.Management
public ADAccount() { }
public ADAccount(System.String identity) { }
public ADAccount(System.Guid guid) { }
public ADAccount(System.Security.Principal.SecurityIdentifier sid) { }
public ADAccount(System.Object sid) { }
public ADAccount(Microsoft.ActiveDirectory.Management.ADObject identity) { }

// Property
public System.String UserPrincipalName { get; set; }
public System.Boolean Enabled { get; set; }
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down Expand Up @@ -196,14 +196,14 @@ namespace Microsoft.ActiveDirectory.Management
public ADComputer(Microsoft.ActiveDirectory.Management.ADObject identity) { }
public ADComputer(System.String identity) { }
public ADComputer(System.Guid guid) { }
public ADComputer(System.Security.Principal.SecurityIdentifier sid) { }
public ADComputer(System.Object sid) { }

// Property
public System.String DNSHostName { get; set; }
public System.String UserPrincipalName { get; set; }
public System.Boolean Enabled { get; set; }
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down Expand Up @@ -272,11 +272,11 @@ namespace Microsoft.ActiveDirectory.Management
public ADDomain() { }
public ADDomain(System.String identity) { }
public ADDomain(System.Guid guid) { }
public ADDomain(System.Security.Principal.SecurityIdentifier sid) { }
public ADDomain(System.Object sid) { }
public ADDomain(Microsoft.ActiveDirectory.Management.ADObject adobject) { }

// Property
public System.Security.Principal.SecurityIdentifier DomainSID { get; set; }
public System.Object DomainSID { get; set; }
public Microsoft.ActiveDirectory.Management.ADPropertyValueCollection AllowedDNSSuffixes { get; set; }
public System.Nullable<System.TimeSpan> LastLogonReplicationInterval { get; set; }
public System.Nullable<Microsoft.ActiveDirectory.Management.ADDomainMode> DomainMode { get; set; }
Expand Down Expand Up @@ -320,7 +320,7 @@ namespace Microsoft.ActiveDirectory.Management
public ADDomainController() { }
public ADDomainController(System.String identity) { }
public ADDomainController(System.Guid guid) { }
public ADDomainController(System.Security.Principal.SecurityIdentifier sid) { }
public ADDomainController(System.Object sid) { }
public ADDomainController(Microsoft.ActiveDirectory.Management.ADObject identity) { }

// Property
Expand Down Expand Up @@ -414,7 +414,7 @@ namespace Microsoft.ActiveDirectory.Management
public ADForest() { }
public ADForest(System.String identity) { }
public ADForest(System.Guid guid) { }
public ADForest(System.Security.Principal.SecurityIdentifier sid) { }
public ADForest(System.Object sid) { }
public ADForest(Microsoft.ActiveDirectory.Management.ADObject adobject) { }

// Property
Expand Down Expand Up @@ -458,14 +458,14 @@ namespace Microsoft.ActiveDirectory.Management
public ADGroup() { }
public ADGroup(System.String identity) { }
public ADGroup(System.Guid guid) { }
public ADGroup(System.Security.Principal.SecurityIdentifier sid) { }
public ADGroup(System.Object sid) { }
public ADGroup(Microsoft.ActiveDirectory.Management.ADObject identity) { }

// Property
public System.Nullable<Microsoft.ActiveDirectory.Management.ADGroupScope> GroupScope { get; set; }
public System.Nullable<Microsoft.ActiveDirectory.Management.ADGroupCategory> GroupCategory { get; set; }
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down Expand Up @@ -606,12 +606,12 @@ namespace Microsoft.ActiveDirectory.Management
public ADPrincipal() { }
public ADPrincipal(System.String identity) { SamAccountName = identity; }
public ADPrincipal(System.Guid guid) { }
public ADPrincipal(System.Security.Principal.SecurityIdentifier sid) { }
public ADPrincipal(System.Object sid) { }
public ADPrincipal(Microsoft.ActiveDirectory.Management.ADObject adobject) { }

// Property
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down Expand Up @@ -828,14 +828,14 @@ namespace Microsoft.ActiveDirectory.Management
public ADServiceAccount(Microsoft.ActiveDirectory.Management.ADObject identity) { }
public ADServiceAccount(System.String identity) { }
public ADServiceAccount(System.Guid guid) { }
public ADServiceAccount(System.Security.Principal.SecurityIdentifier sid) { }
public ADServiceAccount(System.Object sid) { }

// Property
public System.String[] ServicePrincipalNames { get; set; }
public System.String UserPrincipalName { get; set; }
public System.Boolean Enabled { get; set; }
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down Expand Up @@ -905,7 +905,7 @@ namespace Microsoft.ActiveDirectory.Management
public ADUser() { }
public ADUser(System.String identity) { }
public ADUser(System.Guid guid) { }
public ADUser(System.Security.Principal.SecurityIdentifier sid) { }
public ADUser(System.Object sid) { }
public ADUser(Microsoft.ActiveDirectory.Management.ADObject identity) { }

// Property
Expand All @@ -914,7 +914,7 @@ namespace Microsoft.ActiveDirectory.Management
public System.String UserPrincipalName { get; set; }
public System.Boolean Enabled { get; set; }
public System.String SamAccountName { get; set; }
public System.Security.Principal.SecurityIdentifier SID { get; set; }
public System.Object SID { get; set; }
public System.String DistinguishedName { get; set; }
public System.String Name { get; set; }
public System.String ObjectClass { get; set; }
Expand Down
Loading