@@ -16,6 +16,7 @@ namespace VaultSharp.Extensions.Configuration.Test
16
16
using Serilog ;
17
17
using Serilog . Extensions . Logging ;
18
18
using VaultSharp . Core ;
19
+ using VaultSharp . V1 . AuthMethods ;
19
20
using VaultSharp . V1 . AuthMethods . AppRole ;
20
21
using VaultSharp . V1 . AuthMethods . Token ;
21
22
using Xunit ;
@@ -35,15 +36,15 @@ public IntegrationTests()
35
36
this . logger = new SerilogLoggerProvider ( Log . Logger ) . CreateLogger ( nameof ( IntegrationTests ) ) ;
36
37
}
37
38
38
- private IContainer PrepareVaultContainer ( bool enableSSL = false , string ? script = null )
39
+ private IContainer PrepareVaultContainer ( bool enableSSL = false , string ? script = null , string tokenId = "root" )
39
40
{
40
41
var builder = new ContainerBuilder ( )
41
42
. WithImage ( "vault:1.13.3" )
42
43
. WithName ( "vaultsharptest_" + Guid . NewGuid ( ) . ToString ( ) . Substring ( 0 , 8 ) )
43
44
. WithPortBinding ( 8200 , 8200 )
44
45
. WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilPortIsAvailable ( 8200 ) )
45
46
. WithEnvironment ( "VAULT_UI" , "true" )
46
- . WithEnvironment ( "VAULT_DEV_ROOT_TOKEN_ID" , "root" )
47
+ . WithEnvironment ( "VAULT_DEV_ROOT_TOKEN_ID" , tokenId )
47
48
. WithEnvironment ( "VAULT_DEV_LISTEN_ADDRESS" , "0.0.0.0:8200" ) ;
48
49
49
50
if ( enableSSL )
@@ -822,6 +823,56 @@ public async Task Success_Proxy_Verify_Custom_Hook_Invoked()
822
823
await container . DisposeAsync ( ) ;
823
824
}
824
825
}
826
+
827
+ [ Fact ( Skip = "vault-proxy required" ) ]
828
+ public async Task Success_TokenNoAuthMethod ( )
829
+ {
830
+ // arrange
831
+ using CancellationTokenSource cts = new CancellationTokenSource ( ) ;
832
+ var values =
833
+ new Dictionary < string , IEnumerable < KeyValuePair < string , object > > >
834
+ {
835
+ {
836
+ "myservice-config" , new [ ]
837
+ {
838
+ new KeyValuePair < string , object > ( "option1" , "value1" )
839
+ }
840
+ } ,
841
+ } ;
842
+
843
+ var container = this . PrepareVaultContainer ( tokenId : "" ) ;
844
+ try
845
+ {
846
+ await container . StartAsync ( cts . Token ) . ConfigureAwait ( false ) ;
847
+ await this . LoadDataAsync ( "http://localhost:8200" , values ) . ConfigureAwait ( false ) ;
848
+
849
+ // Moq mock of PostProcessHttpClientHandlerAction implementation:
850
+ var mockConfigureProxyAction = new Mock < Action < HttpMessageHandler > > ( ) ;
851
+
852
+ // act
853
+ ConfigurationBuilder builder = new ConfigurationBuilder ( ) ;
854
+ builder . AddVaultConfiguration (
855
+ ( ) => new VaultOptions ( "http://localhost:8200" , ( IAuthMethodInfo ) null ! )
856
+ {
857
+ PostProcessHttpClientHandlerAction = mockConfigureProxyAction . Object
858
+ } ,
859
+ "myservice-config" ,
860
+ "secret" ,
861
+ this . logger ) ;
862
+ var configurationRoot = builder . Build ( ) ;
863
+
864
+ // assert secrets were loaded successfully:
865
+ configurationRoot . GetValue < string > ( "option1" ) . Should ( ) . Be ( "value1" ) ;
866
+
867
+ // assert that PostProcessHttpClientHandlerAction was actually invoked, and a HttpMessageHandler was passed:
868
+ mockConfigureProxyAction . Verify ( x => x ( It . IsAny < HttpMessageHandler > ( ) ) , Times . Once ) ;
869
+ }
870
+ finally
871
+ {
872
+ cts . Cancel ( ) ;
873
+ await container . DisposeAsync ( ) . ConfigureAwait ( false ) ;
874
+ }
875
+ }
825
876
}
826
877
827
878
public class TestConfigObject
0 commit comments