File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -116,4 +116,19 @@ Describe 'Tests for the secret() function and extensions' {
116
116
$out.results.Count | Should - Be 1
117
117
$out.results [0 ].result.actualState.Output | Should - BeExactly ' SameSecret'
118
118
}
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
+ }
119
134
}
Original file line number Diff line number Diff line change @@ -188,6 +188,7 @@ secretNoResults = "Extension '%{extension}' returned no output"
188
188
importingFile = " Importing file '%{file}' with extension '%{extension}'"
189
189
importNotSupported = " Import is not supported by extension '%{extension}' for file '%{file}'"
190
190
importNoResults = " Extension '%{extension}' returned no results for import"
191
+ secretMultipleLinesReturned = " Extension '%{extension}' returned multiple lines which is not supported for secrets"
191
192
192
193
[extensions .extension_manifest ]
193
194
extensionManifestSchemaTitle = " Extension manifest schema URI"
Original file line number Diff line number Diff line change @@ -245,8 +245,15 @@ impl DscExtension {
245
245
info ! ( "{}" , t!( "extensions.dscextension.secretNoResults" , extension = self . type_name) ) ;
246
246
Ok ( None )
247
247
} 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) )
250
257
}
251
258
} else {
252
259
Err ( DscError :: UnsupportedCapability (
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ $secretTwo = @{
27
27
DifferentSecret = ' Hello2'
28
28
DuplicateSecret = ' World2'
29
29
DuplicateSame = ' SameSecret'
30
+ MultiLine = " This`n is`n multiline"
30
31
}
31
32
}
32
33
You can’t perform that action at this time.
0 commit comments