@@ -2,15 +2,19 @@ namespace VaultSharp.Extensions.Configuration.Test
2
2
{
3
3
using System ;
4
4
using System . Collections . Generic ;
5
+ using System . Net ;
5
6
using System . Threading ;
6
7
using System . Threading . Tasks ;
7
8
using DotNet . Testcontainers . Builders ;
8
9
using DotNet . Testcontainers . Containers ;
9
10
using FluentAssertions ;
10
11
using Microsoft . Extensions . Configuration ;
12
+ using Microsoft . Extensions . Logging ;
13
+ using Moq ;
11
14
using Newtonsoft . Json ;
12
15
using Serilog ;
13
16
using Serilog . Extensions . Logging ;
17
+ using VaultSharp . Core ;
14
18
using VaultSharp . V1 . AuthMethods . Token ;
15
19
using Xunit ;
16
20
using ILogger = Microsoft . Extensions . Logging . ILogger ;
@@ -391,6 +395,45 @@ public async Task Success_AuthMethod()
391
395
await container . DisposeAsync ( ) . ConfigureAwait ( false ) ;
392
396
}
393
397
}
398
+
399
+
400
+ [ Fact ]
401
+ public async Task Failure_PermissionDenied ( )
402
+ {
403
+ // arrange
404
+ using var cts = new CancellationTokenSource ( ) ;
405
+ var jsonData = @"{""option1"": ""value1"",""subsection"":{""option2"": ""value2""}}" ;
406
+ var loggerMock = new Mock < ILogger < IntegrationTests > > ( ) ;
407
+ var container = this . PrepareVaultContainer ( ) ;
408
+ try
409
+ {
410
+ await container . StartAsync ( cts . Token ) . ConfigureAwait ( false ) ;
411
+ await this . LoadDataAsync ( "myservice-config" , jsonData ) . ConfigureAwait ( false ) ;
412
+
413
+ // act
414
+ var builder = new ConfigurationBuilder ( ) ;
415
+ builder . AddVaultConfiguration (
416
+ ( ) => new VaultOptions ( "http://localhost:8200" , new TokenAuthMethodInfo ( "NON VALID TOKEN" ) , reloadOnChange : true , reloadCheckIntervalSeconds : 10 , omitVaultKeyName : true ) ,
417
+ "myservice-config" ,
418
+ "secret" ,
419
+ loggerMock . Object ) ;
420
+ var configurationRoot = builder . Build ( ) ;
421
+
422
+ // assert
423
+ loggerMock . Verify (
424
+ x => x . Log (
425
+ It . Is < LogLevel > ( l => l == LogLevel . Error ) ,
426
+ It . IsAny < EventId > ( ) ,
427
+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) == "Cannot load configuration from Vault" ) ,
428
+ It . Is < VaultApiException > ( exception => exception . HttpStatusCode == HttpStatusCode . Forbidden ) ,
429
+ It . Is < Func < It . IsAnyType , Exception ? , string > > ( ( v , t ) => true ) ) , Times . Once ) ;
430
+ }
431
+ finally
432
+ {
433
+ cts . Cancel ( ) ;
434
+ await container . DisposeAsync ( ) . ConfigureAwait ( false ) ;
435
+ }
436
+ }
394
437
}
395
438
396
439
public class TestConfigObject
0 commit comments