Skip to content

Commit

Permalink
Fix for secret key transformation in multi-value scenarios (#1274)
Browse files Browse the repository at this point in the history
* Add repro test.

Signed-off-by: Phillip Hoff <[email protected]>

* Fix for secret key transformation in multi-value scenarios.

Signed-off-by: Phillip Hoff <[email protected]>

---------

Signed-off-by: Phillip Hoff <[email protected]>
  • Loading branch information
philliphoff authored Apr 24, 2024
1 parent 5922fd7 commit a1e262f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,15 @@ private async Task LoadAsync()
$"A duplicate key '{key}' was found in the secret store '{store}'. Please remove any duplicates from your secret store.");
}

data.Add(normalizeKey ? NormalizeKey(secretDescriptor.SecretName) : secretDescriptor.SecretName,
result[key]);
// The name of the key "as desired" by the user based on the descriptor.
//
// NOTE: This should vary only if a single secret of the same name is returned.
string desiredKey = StringComparer.Ordinal.Equals(key, secretDescriptor.SecretKey) ? secretDescriptor.SecretName : key;

// The name of the key normalized based on the configured delimiters.
string normalizedKey = normalizeKey ? NormalizeKey(desiredKey) : desiredKey;

data.Add(normalizedKey, result[key]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,35 @@ public void LoadSecrets_FromSecretStoreThatCanReturnsMultipleValues()
config[secondSecretKey].Should().Be(secondSecretValue);
}

[Fact]
public void LoadSecrets_FromSecretStoreThatCanReturnsMultivaluedValues()
{
var storeName = "store";
var parentSecretKey = "connectionStrings";
var firstSecretKey = "first_secret";
var secondSecretKey = "second_secret";
var firstSecretValue = "secret1";
var secondSecretValue = "secret2";

var secretDescriptors = new[]
{
new DaprSecretDescriptor(parentSecretKey)
};

var daprClient = new Mock<DaprClient>();

daprClient.Setup(c => c.GetSecretAsync(storeName, parentSecretKey,
It.IsAny<Dictionary<string, string>>(), default))
.ReturnsAsync(new Dictionary<string, string> { { firstSecretKey, firstSecretValue }, { secondSecretKey, secondSecretValue } });

var config = CreateBuilder()
.AddDaprSecretStore(storeName, secretDescriptors, daprClient.Object)
.Build();

config[firstSecretKey].Should().Be(firstSecretValue);
config[secondSecretKey].Should().Be(secondSecretValue);
}

[Fact]
public void LoadSecrets_FromSecretStoreWithADifferentSecretKeyAndName()
{
Expand Down

0 comments on commit a1e262f

Please sign in to comment.