Skip to content

Commit 698f13f

Browse files
authored
Add warning about embedded resources (#35)
1 parent 9e5f541 commit 698f13f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ data LocalizedData
6666
ImportDscResourceWarningForInbuiltResource=The configuration '{0}' is loading one or more built-in resources without explicitly importing associated modules. Add Import-DscResource -ModuleName 'PSDesiredStateConfiguration' to your configuration to avoid this message.
6767
PasswordTooLong=An error occurred during encryption of a password in node '{0}'. Most likely the password entered is too long to be encrypted using the selected certificate. Please either use a shorter password or select a certificate with a larger key.
6868
PsDscRunAsCredentialNotSupport=The 'PsDscRunAsCredential' property is not currently support when using Invoke-DscResource.
69+
EmbeddedResourcesNotSupported=Embedded resources are not support on Linux or macOS. Please see https://aka.ms/PSCoreDSC for more details.
6970
'@
7071
}
7172
Set-StrictMode -Off
@@ -1904,6 +1905,10 @@ function Configuration
19041905
return $moduleInfos
19051906
}
19061907

1908+
if ( $IsMacOS -or $IsLinux ) {
1909+
Write-Warning -Message $LocalizedData.EmbeddedResourcesNotSupported
1910+
}
1911+
19071912
try
19081913
{
19091914
Write-Debug -Message "BEGIN CONFIGURATION '$Name' PROCESSING: OutputPath: '$OutputPath'"
@@ -4687,6 +4692,10 @@ function Invoke-DscResource
46874692
ThrowError -ExceptionName 'System.ArgumentException' -ExceptionMessage $errorMessage -ExceptionObject $exception -ErrorId 'InvalidResourceSpecification,Invoke-DscResource' -ErrorCategory InvalidArgument
46884693
}
46894694

4695+
if ( @($resource.Properties | Where-Object { $_.PropertyType -eq '' }).Count -gt 0 -and ($IsMacOS -or $IsLinux)) {
4696+
Write-Warning -Message $LocalizedData.EmbeddedResourcesNotSupported
4697+
}
4698+
46904699
[Microsoft.PowerShell.DesiredStateConfiguration.DscResourceInfo] $resource = $resource[0]
46914700
if($resource.ImplementedAs -ne 'PowerShell')
46924701
{

test/PSDesiredStateConfiguration.Tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
368368
)
369369

370370
Install-ModuleIfMissing -Name PowerShellGet -Force -SkipPublisherCheck -MinimumVersion '2.2.1'
371+
Install-ModuleIfMissing -Name xWebAdministration
371372
$module = Get-Module PowerShellGet -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1
372373

373374
$psGetModuleSpecification = @{ModuleName = $module.Name; ModuleVersion = $module.Version.ToString() }
@@ -428,6 +429,34 @@ Describe "Test PSDesiredStateConfiguration" -tags CI {
428429
Should -Throw -ErrorId 'InvalidResourceSpecification,Invoke-DscResource' -ExpectedMessage 'Invalid Resource Name ''Script'' or module specification.'
429430
}
430431

432+
it "Resource with embedded resource not supported and a warning should be produced" {
433+
434+
if (!(Test-IsInvokeDscResourceEnable)) {
435+
Set-ItResult -Skipped -Because "Feature not enabled"
436+
}
437+
438+
if (!$IsMacOS) {
439+
Set-ItResult -Skipped -Because "Not applicable on Windows and xWebAdministration resources don't load on linux"
440+
}
441+
442+
try {
443+
Invoke-DscResource -Name xWebSite -ModuleName 'xWebAdministration' -Method Test -Property @{TestScript = 'foobar' } -ErrorAction Stop -WarningVariable warnings
444+
}
445+
catch{
446+
#this will fail too, but that is nat what we are testing...
447+
}
448+
449+
$warnings.Count | Should -Be 1 -because "There should be 1 warning on macOS and Linux"
450+
$warnings[0] | Should -Match 'embedded resources.*not support'
451+
}
452+
453+
it "Using PsDscRunAsCredential should say not supported" -Skip:(!(Test-IsInvokeDscResourceEnable)) {
454+
{
455+
Invoke-DscResource -Name Script -ModuleName PSDscResources -Method Set -Property @{TestScript = { Write-Output 'test'; return $false }; GetScript = { return @{ } }; SetScript = {return}; PsDscRunAsCredential='natoheu'} -ErrorAction Stop
456+
} |
457+
Should -Throw -ErrorId 'PsDscRunAsCredentialNotSupport,Invoke-DscResource'
458+
}
459+
431460
# waiting on Get-DscResource to be fixed
432461
it "Invalid module name" -Skip:(!(Test-IsInvokeDscResourceEnable)) {
433462
Set-ItResult -Pending -Because "https://github.com/PowerShell/PSDesiredStateConfiguration/issues/17"

0 commit comments

Comments
 (0)