Skip to content

Commit a1af646

Browse files
committed
allow multiple results that have same value
1 parent 071efc7 commit a1af646

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

dsc/tests/dsc_functions_secret.tests.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Describe 'Tests for the secret() function and extensions' {
1212
$env:PATH = $oldPath
1313
}
1414

15-
It 'Call secret() function with just a name' {
15+
It 'Just a secret name' {
1616
$configYaml = @'
1717
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
1818
resources:
@@ -27,7 +27,7 @@ Describe 'Tests for the secret() function and extensions' {
2727
$out.results[0].result.actualState.Output | Should -BeExactly 'Hello'
2828
}
2929

30-
It 'Call secret() function with a name and vault' {
30+
It 'Name and vault' {
3131
$configYaml = @'
3232
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
3333
resources:
@@ -42,7 +42,7 @@ Describe 'Tests for the secret() function and extensions' {
4242
$out.results[0].result.actualState.Output | Should -BeExactly 'Hello2'
4343
}
4444

45-
It 'Call secret() function with a name that does not exist' {
45+
It 'Name that does not exist' {
4646
$configYaml = @'
4747
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
4848
resources:
@@ -57,7 +57,7 @@ Describe 'Tests for the secret() function and extensions' {
5757
$errorMessage | Should -Match "Secret 'NonExistentSecret' not found"
5858
}
5959

60-
It 'Call secret() function with a vault that does not exist' {
60+
It 'Vault that does not exist' {
6161
$configYaml = @'
6262
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
6363
resources:
@@ -72,7 +72,7 @@ Describe 'Tests for the secret() function and extensions' {
7272
$errorMessage | Should -Match "Secret 'MySecret' not found"
7373
}
7474

75-
It 'Call secret() function with a duplicate secret' {
75+
It 'Duplicate secret' {
7676
$configYaml = @'
7777
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
7878
resources:
@@ -84,10 +84,10 @@ Describe 'Tests for the secret() function and extensions' {
8484
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json
8585
$LASTEXITCODE | Should -Be 2
8686
$errorMessage = Get-Content -Raw -Path $TestDrive/error.log
87-
$errorMessage | Should -Match "Multiple secrets with the same name 'DuplicateSecret' was returned, try specifying a vault"
87+
$errorMessage | Should -Match "Multiple secrets with the same name 'DuplicateSecret' and different values was returned, try specifying a vault"
8888
}
8989

90-
It 'Call secret() function with secret and vault to disambiguate' {
90+
It 'Secret and vault to disambiguate' {
9191
$configYaml = @'
9292
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
9393
resources:
@@ -101,4 +101,19 @@ Describe 'Tests for the secret() function and extensions' {
101101
$out.results.Count | Should -Be 1
102102
$out.results[0].result.actualState.Output | Should -BeExactly 'World'
103103
}
104+
105+
It 'Same secret name and value in different extensions' {
106+
$configYaml = @'
107+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
108+
resources:
109+
- name: Echo
110+
type: Microsoft.DSC.Debug/Echo
111+
properties:
112+
output: "[secret('DuplicateSame')]"
113+
'@
114+
$out = dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json
115+
$LASTEXITCODE | Should -Be 0
116+
$out.results.Count | Should -Be 1
117+
$out.results[0].result.actualState.Output | Should -BeExactly 'SameSecret'
118+
}
104119
}

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ invalidSecondArgType = "Invalid argument type for second parameter"
300300

301301
[functions.secret]
302302
notString = "Parameter secret name is not a string"
303-
multipleSecrets = "Multiple secrets with the same name '%{name}' was returned, try specifying a vault"
303+
multipleSecrets = "Multiple secrets with the same name '%{name}' and different values was returned, try specifying a vault"
304304
extensionReturnedError = "Extension '%{extension}': %{error}"
305305
noExtensions = "No extensions supporting secrets was found"
306306
secretNotFound = "Secret '%{name}' not found"

dsc_lib/src/functions/secret.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Function for Secret {
5050
match extension.secret(&secret_name, vault_name.as_deref()) {
5151
Ok(secret_result) => {
5252
if let Some(secret_value) = secret_result {
53-
if secret_returned {
53+
if secret_returned && result != secret_value {
5454
return Err(DscError::Function("secret".to_string(), t!("functions.secret.multipleSecrets", name = secret_name.clone()).to_string()));
5555
}
5656

extensions/test/secret/secret.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $secretsOne = @{
1515
Vault1 = @{
1616
MySecret = 'Hello'
1717
DuplicateSecret = 'World'
18+
DuplicateSame = 'SameSecret'
1819
}
1920
Vault2 = @{
2021
AnotherSecret = 'Foo'
@@ -25,6 +26,7 @@ $secretTwo = @{
2526
VaultA = @{
2627
DifferentSecret = 'Hello2'
2728
DuplicateSecret = 'World2'
29+
DuplicateSame = 'SameSecret'
2830
}
2931
}
3032

0 commit comments

Comments
 (0)