This repository was archived by the owner on Feb 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ public BindleClient(ConnectionInfo connectionInfo)
3131 }
3232
3333 _httpClient = new HttpClient ( handler ) { BaseAddress = new Uri ( SlashSafe ( connectionInfo . BaseUri ) ) } ;
34+
35+ if ( ! string . IsNullOrEmpty ( connectionInfo . UserName ) && ! string . IsNullOrEmpty ( connectionInfo . Password ) )
36+ {
37+ _httpClient . DefaultRequestHeaders . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , $ "{ connectionInfo . UserName } :{ connectionInfo . Password } ") ;
38+ }
3439 }
3540
3641 private const string INVOICE_PATH = "_i" ;
Original file line number Diff line number Diff line change @@ -21,16 +21,33 @@ public class ConnectionInfo
2121 "ssl mode"
2222 } ;
2323
24+ static readonly string [ ] usernameAliases = {
25+ "user" ,
26+ "username"
27+ } ;
28+
29+ static readonly string [ ] passwordAliases = {
30+ "pass" ,
31+ "passwd" ,
32+ "password"
33+ } ;
34+
2435 private readonly Dictionary < string , string > keyValuePairs ;
2536
2637 public string BaseUri ;
2738
39+ public string UserName ;
40+
41+ public string Password ;
42+
2843 public SslMode ? SslMode ;
2944
3045 public ConnectionInfo ( )
3146 {
3247 keyValuePairs = new Dictionary < string , string > ( ) ;
3348 BaseUri = "http://localhost:8080/v1/" ;
49+ UserName = String . Empty ;
50+ Password = String . Empty ;
3451 }
3552
3653 public ConnectionInfo ( string connectionString )
@@ -39,6 +56,10 @@ public ConnectionInfo(string connectionString)
3956
4057 BaseUri = GetValue ( serverAliases ) ;
4158
59+ UserName = GetValue ( usernameAliases ) ;
60+
61+ Password = GetValue ( passwordAliases ) ;
62+
4263 try
4364 {
4465 SslMode = Enum . Parse < SslMode > ( GetValue ( sslModeAliases ) , true ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,25 @@ public void ShouldAcceptSslModeAliases()
3535 Assert . Equal ( SslMode . VerifyFull , ( new ConnectionInfo ( "sslmode=verifyfull" ) . SslMode ) ) ;
3636 }
3737
38+ [ Fact ]
39+ public void ShouldAcceptUserNameAliases ( )
40+ {
41+ Assert . Equal ( "" , ( new ConnectionInfo ( "" ) . UserName ) ) ;
42+ Assert . Equal ( "" , ( new ConnectionInfo ( "username=" ) . UserName ) ) ;
43+ Assert . Equal ( "spongebob" , ( new ConnectionInfo ( "username=spongebob" ) . UserName ) ) ;
44+ Assert . Equal ( "patrick" , ( new ConnectionInfo ( "user=patrick" ) . UserName ) ) ;
45+ }
46+
47+ [ Fact ]
48+ public void ShouldAcceptPasswordAliases ( )
49+ {
50+ Assert . Equal ( "" , ( new ConnectionInfo ( "" ) . Password ) ) ;
51+ Assert . Equal ( "" , ( new ConnectionInfo ( "password=" ) . Password ) ) ;
52+ Assert . Equal ( "imagoofygooberyeah" , ( new ConnectionInfo ( "password=imagoofygooberyeah" ) . Password ) ) ;
53+ Assert . Equal ( "uragoofygooberyeah" , ( new ConnectionInfo ( "pass=uragoofygooberyeah" ) . Password ) ) ;
54+ Assert . Equal ( "wereallgoofygoobersyeah" , ( new ConnectionInfo ( "passwd=wereallgoofygoobersyeah" ) . Password ) ) ;
55+ }
56+
3857 [ Fact ]
3958 public void ShouldAcceptMultipleOptions ( )
4059 {
You can’t perform that action at this time.
0 commit comments