Skip to content

Commit

Permalink
Moves localization to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
iainbrighton committed May 19, 2016
1 parent 6eee8ea commit 7d7ad8b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DSCResource.Tests/
1 change: 0 additions & 1 deletion DSCResource.Tests
Submodule DSCResource.Tests deleted from b367d4
57 changes: 29 additions & 28 deletions DSCResources/MSFT_xADUser/MSFT_xADUser.psm1
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
# Localized messages
data LocalizedData
$moduleRoot = Split-Path -Path $MyInvocation.MyCommand.Path -Parent
#region LocalizedData
$culture = 'en-us'
if (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath $PSUICulture))
{
# culture="en-US"
ConvertFrom-StringData @'
RoleNotFoundError = Please ensure that the PowerShell module for role '{0}' is installed.
RetrievingADUserError = Error looking up Active Directory user '{0}' ({0}@{1}).
PasswordParameterConflictError = Parameter '{0}' cannot be set to '{1}' when the '{2}' parameter is specified.
RetrievingADUser = Retrieving Active Directory user '{0}' ({0}@{1}) ...
CreatingADDomainConnection = Creating connection to Active Directory domain '{0}' ...
CheckingADUserPassword = Checking Active Directory user '{0}' password ...
ADUserIsPresent = Active Directory user '{0}' ({0}@{1}) is present.
ADUserNotPresent = Active Directory user '{0}' ({0}@{1}) was NOT present.
ADUserNotDesiredPropertyState = User '{0}' property is NOT in the desired state. Expected '{1}', actual '{2}'.
AddingADUser = Adding Active Directory user '{0}'.
RemovingADUser = Removing Active Directory user '{0}'.
UpdatingADUser = Updating Active Directory user '{0}'.
SettingADUserPassword = Setting Active Directory user password.
UpdatingADUserProperty = Updating user property '{0}' with/to '{1}'.
RemovingADUserProperty = Removing user property '{0}' with '{1}'.
MovingADUser = Moving user from '{0}' to '{1}'.
RenamingADUser = Renaming user from '{0}' to '{1}'.
'@
$culture = $PSUICulture
}
$importLocalizedDataParams = @{
BindingVariable = 'LocalizedData'
Filename = 'MSFT_xADUser.psd1'
BaseDirectory = $moduleRoot
UICulture = $culture
}
Import-LocalizedData @importLocalizedDataParams
#endregion

## Create a property map that maps the DSC resource parameters to the
## Active Directory user attributes.
Expand Down Expand Up @@ -831,15 +820,27 @@ function Test-Password
if ($DomainAdministratorCredential)
{
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
'Domain', $DomainName, $DomainAdministratorCredential.UserName, `
$DomainAdministratorCredential.GetNetworkCredential().Password);
[System.DirectoryServices.AccountManagement.ContextType]::Domain,
$DomainName,
$DomainAdministratorCredential.UserName,
$DomainAdministratorCredential.GetNetworkCredential().Password
);
}
else
{
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('Domain', $DomainName, $null, $null);
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
[System.DirectoryServices.AccountManagement.ContextType]::Domain,
$DomainName,
$null,
$null
);
}
Write-Verbose -Message ($LocalizedData.CheckingADUserPassword -f $UserName);
return $principalContext.ValidateCredentials($UserName, $Password.GetNetworkCredential().Password);
return $principalContext.ValidateCredentials(
$UserName,
$Password.GetNetworkCredential().Password,
[System.DirectoryServices.AccountManagement.ContextOptions]::Negotiate
);

} #end function Test-Password

Expand Down
22 changes: 22 additions & 0 deletions DSCResources/MSFT_xADUser/en-US/MSFT_xADUser.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# culture="en-US"
ConvertFrom-StringData @'
RoleNotFoundError = Please ensure that the PowerShell module for role '{0}' is installed.
RetrievingADUserError = Error looking up Active Directory user '{0}' ({0}@{1}).
PasswordParameterConflictError = Parameter '{0}' cannot be set to '{1}' when the '{2}' parameter is specified.
RetrievingADUser = Retrieving Active Directory user '{0}' ({0}@{1}) ...
CreatingADDomainConnection = Creating connection to Active Directory domain '{0}' ...
CheckingADUserPassword = Checking Active Directory user '{0}' password ...
ADUserIsPresent = Active Directory user '{0}' ({0}@{1}) is present.
ADUserNotPresent = Active Directory user '{0}' ({0}@{1}) was NOT present.
ADUserNotDesiredPropertyState = User '{0}' property is NOT in the desired state. Expected '{1}', actual '{2}'.
AddingADUser = Adding Active Directory user '{0}'.
RemovingADUser = Removing Active Directory user '{0}'.
UpdatingADUser = Updating Active Directory user '{0}'.
SettingADUserPassword = Setting Active Directory user password.
UpdatingADUserProperty = Updating user property '{0}' with/to '{1}'.
RemovingADUserProperty = Removing user property '{0}' with '{1}'.
MovingADUser = Moving user from '{0}' to '{1}'.
RenamingADUser = Renaming user from '{0}' to '{1}'.
'@
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ The xADDomainDefaultPasswordPolicy DSC resource will manage an Active Directory

### Unreleased

* xADUser: Fixes bug in user credential validation when a domain certificate authority is deployed.

### 2.11.0.0
* xWaitForADDomain: Made explicit credentials optional and other various updates

Expand Down
12 changes: 4 additions & 8 deletions Tests/Unit/MSFT_xADUser.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
$Global:DSCModuleName = 'xActiveDirectory' # Example xNetworking
$Global:DSCResourceName = 'MSFT_xADUser' # Example MSFT_xFirewall
$Global:DSCModuleName = 'xActiveDirectory'
$Global:DSCResourceName = 'MSFT_xADUser'

#region HEADER
[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path))
Write-Host $moduleRoot -ForegroundColor Green;
if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'))
}
else
{
& git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull')
}

Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $Global:DSCModuleName `
-DSCResourceName $Global:DSCResourceName `
-TestType Unit
#endregion
#endregion HEADER


# Begin Testing
Expand Down

0 comments on commit 7d7ad8b

Please sign in to comment.