Added test generation code for #34

This commit is contained in:
MichaelGrafnetter 2016-11-08 22:47:28 +01:00
parent 6e332307e9
commit 99cba912f2
2 changed files with 21 additions and 0 deletions

View File

@ -167,6 +167,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
<None Include="Tests\ConvertTo-OrgIdHashNative.ps1" />
<None Include="Tests\Set-SamAccountPasswordHash.Tests.ps1" />
<None Include="Tests\Path.Tests.ps1" />
<None Include="Tests\ConvertFrom-UnicodePassword.Tests.ps1" />

View File

@ -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())