Skip to content

Commit f2e702d

Browse files
Maartymsolarik
andauthored
🐛 fix - keys with substring of base path not working (#24)
* 🐛 fix - keys with substring of base path not working * ✅ add test scenario Co-authored-by: Martin Solárik <[email protected]>
1 parent 2b3a072 commit f2e702d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Source/VaultSharp.Extensions.Configuration/VaultConfigurationProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ private async Task LoadVaultDataAsync(IVaultClient vaultClient)
9595
this._logger?.LogDebug($"VaultConfigurationProvider: got Vault data with key `{secretData.Key}`");
9696

9797
var key = secretData.Key;
98-
key = key.Replace(this._source.BasePath, string.Empty, StringComparison.InvariantCultureIgnoreCase).TrimStart('/')
99-
.Replace('/', ':');
98+
key = key.TrimStart('/')[this._source.BasePath.TrimStart('/').Length..].TrimStart('/').Replace('/', ':');
10099
key = this.ReplaceTheAdditionalCharactersForConfigurationPath(key);
101100
var data = secretData.SecretData.Data;
102101

Tests/VaultSharp.Extensions.Configuration.Test/IntegrationTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public async Task Success_SimpleTest_TokenAuth()
109109
new KeyValuePair<string, object>("option7", "value7"),
110110
}
111111
},
112+
{
113+
"test/subsection/testsection", new[]
114+
{
115+
new KeyValuePair<string, object>("option8", "value8"),
116+
}
117+
},
112118
};
113119

114120
var container = this.PrepareVaultContainer();
@@ -148,6 +154,7 @@ public async Task Success_SimpleTest_TokenAuth()
148154
.GetSection("otherSubsection4")
149155
.GetSection("otherSubsection5")
150156
.GetValue<string>("option7").Should().Be("value7");
157+
configurationRoot.GetSection("subsection").GetSection("testsection").GetValue<string>("option8").Should().Be("value8");
151158
}
152159
finally
153160
{
@@ -227,6 +234,7 @@ public async Task Success_WatcherTest_TokenAuth()
227234
{ "test", new[] { new KeyValuePair<string, object>("option1", "value1_new") } },
228235
{ "test/subsection", new[] { new KeyValuePair<string, object>("option2", "value2_new") } },
229236
{ "test/subsection3", new[] { new KeyValuePair<string, object>("option3", "value3_new") } },
237+
{ "test/testsection", new[] { new KeyValuePair<string, object>("option4", "value4_new") } },
230238
};
231239
await this.LoadDataAsync(values).ConfigureAwait(false);
232240
await Task.Delay(TimeSpan.FromSeconds(15), cts.Token).ConfigureAwait(true);
@@ -235,6 +243,7 @@ public async Task Success_WatcherTest_TokenAuth()
235243
configurationRoot.GetValue<string>("option1").Should().Be("value1_new");
236244
configurationRoot.GetSection("subsection").GetValue<string>("option2").Should().Be("value2_new");
237245
configurationRoot.GetSection("subsection3").GetValue<string>("option3").Should().Be("value3_new");
246+
configurationRoot.GetSection("testsection").GetValue<string>("option4").Should().Be("value4_new");
238247

239248
changeWatcher.Dispose();
240249
}

0 commit comments

Comments
 (0)