@@ -9,10 +9,8 @@ namespace VaultSharp.Extensions.Configuration.Test
9
9
using DotNet . Testcontainers . Containers . WaitStrategies ;
10
10
using FluentAssertions ;
11
11
using Microsoft . Extensions . Configuration ;
12
- using Microsoft . VisualStudio . TestPlatform . TestHost ;
13
12
using Newtonsoft . Json ;
14
13
using Serilog ;
15
- using Serilog . Core ;
16
14
using Serilog . Extensions . Logging ;
17
15
using VaultSharp . V1 . AuthMethods . Token ;
18
16
using Xunit ;
@@ -49,7 +47,7 @@ private async Task LoadDataAsync(Dictionary<string, IEnumerable<KeyValuePair<str
49
47
{
50
48
var authMethod = new TokenAuthMethodInfo ( "root" ) ;
51
49
52
- var vaultClientSettings = new VaultClientSettings ( "http://localhost:8200" , authMethod ) ;
50
+ var vaultClientSettings = new VaultClientSettings ( "http://localhost:8200" , authMethod ) { SecretsEngineMountPoints = { KeyValueV2 = "secret" } } ;
53
51
IVaultClient vaultClient = new VaultClient ( vaultClientSettings ) ;
54
52
55
53
foreach ( var sectionPair in values )
@@ -69,7 +67,7 @@ private async Task LoadDataAsync(string secretPath, string jsonData)
69
67
{
70
68
var authMethod = new TokenAuthMethodInfo ( "root" ) ;
71
69
72
- var vaultClientSettings = new VaultClientSettings ( "http://localhost:8200" , authMethod ) ;
70
+ var vaultClientSettings = new VaultClientSettings ( "http://localhost:8200" , authMethod ) { SecretsEngineMountPoints = { KeyValueV2 = "secret" } } ;
73
71
IVaultClient vaultClient = new VaultClient ( vaultClientSettings ) ;
74
72
75
73
var dictionary = JsonConvert . DeserializeObject < Dictionary < string , object > > ( jsonData ) ;
@@ -89,8 +87,9 @@ public async Task Success_SimpleTest_TokenAuth()
89
87
new KeyValuePair < string , object > ( "option1" , "value1" ) ,
90
88
new KeyValuePair < string , object > ( "option3" , 5 ) ,
91
89
new KeyValuePair < string , object > ( "option4" , true ) ,
92
- new KeyValuePair < string , object > ( "option5" , new [ ] { "v1" , "v2" , "v3" } ) ,
93
- new KeyValuePair < string , object > ( "option6" ,
90
+ new KeyValuePair < string , object > ( "option5" , new [ ] { "v1" , "v2" , "v3" } ) ,
91
+ new KeyValuePair < string , object > (
92
+ "option6" ,
94
93
new [ ]
95
94
{
96
95
new TestConfigObject ( ) { OptionA = "a1" , OptionB = "b1" } ,
@@ -194,8 +193,8 @@ public async Task Success_WatcherTest_TokenAuth()
194
193
var values =
195
194
new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
196
195
{
197
- { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1" ) , } } ,
198
- { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2" ) , } } ,
196
+ { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1" ) } } ,
197
+ { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2" ) } } ,
199
198
} ;
200
199
201
200
var container = this . PrepareVaultContainer ( ) ;
@@ -208,8 +207,7 @@ public async Task Success_WatcherTest_TokenAuth()
208
207
// act
209
208
ConfigurationBuilder builder = new ConfigurationBuilder ( ) ;
210
209
builder . AddVaultConfiguration (
211
- ( ) => new VaultOptions ( "http://localhost:8200" , "root" , reloadOnChange : true ,
212
- reloadCheckIntervalSeconds : 10 ) ,
210
+ ( ) => new VaultOptions ( "http://localhost:8200" , "root" , reloadOnChange : true , reloadCheckIntervalSeconds : 10 ) ,
213
211
"test" ,
214
212
"secret" ,
215
213
this . _logger ) ;
@@ -226,12 +224,12 @@ public async Task Success_WatcherTest_TokenAuth()
226
224
// load new data and wait for reload
227
225
values = new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
228
226
{
229
- { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1_new" ) , } } ,
230
- { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2_new" ) , } } ,
231
- { "test/subsection3" , new [ ] { new KeyValuePair < string , object > ( "option3" , "value3_new" ) , } } ,
227
+ { "test" , new [ ] { new KeyValuePair < string , object > ( "option1" , "value1_new" ) } } ,
228
+ { "test/subsection" , new [ ] { new KeyValuePair < string , object > ( "option2" , "value2_new" ) } } ,
229
+ { "test/subsection3" , new [ ] { new KeyValuePair < string , object > ( "option3" , "value3_new" ) } } ,
232
230
} ;
233
231
await this . LoadDataAsync ( values ) . ConfigureAwait ( false ) ;
234
- await Task . Delay ( TimeSpan . FromSeconds ( 15 ) ) . ConfigureAwait ( true ) ;
232
+ await Task . Delay ( TimeSpan . FromSeconds ( 15 ) , cts . Token ) . ConfigureAwait ( true ) ;
235
233
236
234
reloadToken . HasChanged . Should ( ) . BeTrue ( ) ;
237
235
configurationRoot . GetValue < string > ( "option1" ) . Should ( ) . Be ( "value1_new" ) ;
@@ -257,7 +255,7 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
257
255
var container = this . PrepareVaultContainer ( ) ;
258
256
try
259
257
{
260
- await container . StartAsync ( ) . ConfigureAwait ( false ) ;
258
+ await container . StartAsync ( cts . Token ) . ConfigureAwait ( false ) ;
261
259
await this . LoadDataAsync ( "myservice-config" , jsonData ) . ConfigureAwait ( false ) ;
262
260
263
261
@@ -283,7 +281,7 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
283
281
@"{""option1"": ""value1_new"",""subsection"": {""option2"": ""value2_new""},""subsection3"": {""option3"": ""value3_new""}}" ;
284
282
285
283
await this . LoadDataAsync ( "myservice-config" , jsonData ) . ConfigureAwait ( false ) ;
286
- await Task . Delay ( TimeSpan . FromSeconds ( 15 ) ) . ConfigureAwait ( true ) ;
284
+ await Task . Delay ( TimeSpan . FromSeconds ( 15 ) , cts . Token ) . ConfigureAwait ( true ) ;
287
285
288
286
reloadToken . HasChanged . Should ( ) . BeTrue ( ) ;
289
287
configurationRoot . GetValue < string > ( "option1" ) . Should ( ) . Be ( "value1_new" ) ;
@@ -298,7 +296,6 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
298
296
await container . DisposeAsync ( ) . ConfigureAwait ( false ) ;
299
297
}
300
298
}
301
-
302
299
}
303
300
304
301
public class TestConfigObject
0 commit comments