From 99cba912f27544e1ade89dc086b3fab97fc1d5af Mon Sep 17 00:00:00 2001 From: MichaelGrafnetter Date: Tue, 8 Nov 2016 22:47:28 +0100 Subject: [PATCH] Added test generation code for #34 --- .../DSInternals.PowerShell.csproj | 1 + .../Tests/ConvertTo-OrgIdHashNative.ps1 | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 Src/DSInternals.PowerShell/Tests/ConvertTo-OrgIdHashNative.ps1 diff --git a/Src/DSInternals.PowerShell/DSInternals.PowerShell.csproj b/Src/DSInternals.PowerShell/DSInternals.PowerShell.csproj index 63a2d5d..30261f1 100644 --- a/Src/DSInternals.PowerShell/DSInternals.PowerShell.csproj +++ b/Src/DSInternals.PowerShell/DSInternals.PowerShell.csproj @@ -167,6 +167,7 @@ PreserveNewest Designer + diff --git a/Src/DSInternals.PowerShell/Tests/ConvertTo-OrgIdHashNative.ps1 b/Src/DSInternals.PowerShell/Tests/ConvertTo-OrgIdHashNative.ps1 new file mode 100644 index 0000000..022b608 --- /dev/null +++ b/Src/DSInternals.PowerShell/Tests/ConvertTo-OrgIdHashNative.ps1 @@ -0,0 +1,20 @@ +<# +.SYNOPSIS +Calculates the OrgId hash of a given password using Azure AD Connect's library. +.DESCRIPTION +This is only used to manually generate test data for C# Unit Tests. +#> +#Requires -Module DSInternals +param( + [Parameter(Mandatory = $true)] + [SecureString] $Password +) + +## Load the Microsoft.Online.PasswordSynchronization.Cryptography.dll assembly from Azure AD Connect +# Location is typically 'C:\Program Files\Microsoft Azure AD Sync\', but it can be changed during installation. +$adSyncPath = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\AD Sync').Location +$cryptoAssemblyPath = Join-Path $adSyncPath 'Bin\Microsoft.Online.PasswordSynchronization.Cryptography.dll' +Add-Type -Path $cryptoAssemblyPath -ErrorAction Stop + +$ntHash = ConvertTo-NTHash -Password $Password +return [Microsoft.Online.PasswordSynchronization.OrgIdHashGenerator]::Generate($ntHash.ToUpper()) \ No newline at end of file