Skip to content

Commit d18447f

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
add multiline test
1 parent e9ec9d5 commit d18447f

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

dsc/tests/dsc_extension_secret.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,19 @@ Describe 'Tests for the secret() function and extensions' {
116116
$out.results.Count | Should -Be 1
117117
$out.results[0].result.actualState.Output | Should -BeExactly 'SameSecret'
118118
}
119+
120+
It 'Secret with multiple lines' {
121+
$configYaml = @'
122+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
123+
resources:
124+
- name: Echo
125+
type: Microsoft.DSC.Debug/Echo
126+
properties:
127+
output: "[secret('MultiLine')]"
128+
'@
129+
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json
130+
$LASTEXITCODE | Should -Be 2
131+
$errorMessage = Get-Content -Raw -Path $TestDrive/error.log
132+
$errorMessage | Should -Match "Extension 'Test/Secret2' returned multiple lines which is not supported for secrets"
133+
}
119134
}

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ secretNoResults = "Extension '%{extension}' returned no output"
188188
importingFile = "Importing file '%{file}' with extension '%{extension}'"
189189
importNotSupported = "Import is not supported by extension '%{extension}' for file '%{file}'"
190190
importNoResults = "Extension '%{extension}' returned no results for import"
191+
secretMultipleLinesReturned = "Extension '%{extension}' returned multiple lines which is not supported for secrets"
191192

192193
[extensions.extension_manifest]
193194
extensionManifestSchemaTitle = "Extension manifest schema URI"

dsc_lib/src/extensions/dscextension.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,15 @@ impl DscExtension {
245245
info!("{}", t!("extensions.dscextension.secretNoResults", extension = self.type_name));
246246
Ok(None)
247247
} else {
248-
debug!("{}", t!("extensions.dscextension.extensionReturnedSecret", extension = self.type_name));
249-
Ok(Some(stdout))
248+
// see if multiple lines were returned
249+
let secret = if stdout.lines().count() > 1 {
250+
return Err(DscError::NotSupported(t!("extensions.dscextension.secretMultipleLinesReturned", extension = self.type_name).to_string()));
251+
} else {
252+
debug!("{}", t!("extensions.dscextension.extensionReturnedSecret", extension = self.type_name));
253+
// remove any trailing newline characters
254+
stdout.trim_end_matches('\n').to_string()
255+
};
256+
Ok(Some(secret))
250257
}
251258
} else {
252259
Err(DscError::UnsupportedCapability(

extensions/test/secret/secret.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ $secretTwo = @{
2727
DifferentSecret = 'Hello2'
2828
DuplicateSecret = 'World2'
2929
DuplicateSame = 'SameSecret'
30+
MultiLine = "This`nis`nmultiline"
3031
}
3132
}
3233

0 commit comments

Comments
 (0)