@@ -27,7 +27,7 @@ public void HttpClientShouldBeCreatedIfNotProvider()
2727 [ Fact ]
2828 public void BasicAuthHeaderShouldBeCorrect ( )
2929 {
30- var credentials = new LokiCredentials { Login = "Billy" , Password = "Herrington" } ;
30+ var credentials = new LokiCredentials { Login = "Billy" , Password = "Herrington" } ;
3131 using var client = new TestLokiHttpClient ( ) ;
3232
3333 client . SetCredentials ( credentials ) ;
@@ -48,37 +48,32 @@ public void AuthorizationHeaderShouldNotBeSetWithoutCredentials()
4848 client . Client . DefaultRequestHeaders . Authorization . ShouldBeNull ( ) ;
4949 }
5050
51- [ Fact ]
52- public void TenantHeaderShouldBeCorrect ( )
53- {
54- // List of test cases with tenant IDs and their expected validity
55- var validTenantIds = new List < ( string TenantId , bool IsValid ) >
51+ [ Theory ]
52+ [ InlineData ( "tenant123" , true ) ]
53+ [ InlineData ( "tenant-123" , true ) ]
54+ [ InlineData ( "tenant..123" , false ) ]
55+ [ InlineData ( "." , false ) ]
56+ [ InlineData ( "tenant!_*.123'()" , true ) ]
57+ [ InlineData ( "tenant-123..." , false ) ]
58+ [ InlineData ( "tenant123456...test" , false ) ]
59+ [ InlineData ( "tenant1234567890!@" , false ) ]
60+ public void TenantHeaderShouldBeCorrect ( string tenantId , bool isValid )
5661 {
57- ( "tenant123" , true ) , // Only alphanumeric characters
58- ( "tenant-123" , true ) , // Valid special characters
59- ( "tenant..123" , false ) , // Double period ".." is not allowed
60- ( "." , false ) , // Single period is not allowed
61- ( "tenant!_*.123'()" , true ) , // All allowed special characters
62- ( "tenant-123..." , false ) , // Multiple periods at the end are not allowed
63- ( "tenant123456...test" , false ) , // Ends with a period "."
64- ( "tenant1234567890!@" , false ) , // "@" is not allowed
65- } ;
66-
67- foreach ( var ( tenantId , isValid ) in validTenantIds )
62+ using var client = new TestLokiHttpClient ( ) ;
63+
64+ if ( isValid )
65+ {
66+ client . SetTenant ( tenantId ) ;
67+
68+ var tenantHeaders = client . Client . DefaultRequestHeaders
69+ . GetValues ( "X-Scope-OrgID" )
70+ . ToList ( ) ;
71+
72+ tenantHeaders . ShouldBeEquivalentTo ( new List < string > { tenantId } ) ;
73+ }
74+ else
6875 {
69- using var client = new TestLokiHttpClient ( ) ;
70-
71- if ( isValid )
72- {
73- client . SetTenant ( tenantId ) ;
74-
75- var tenantHeaders = client . Client . DefaultRequestHeaders . GetValues ( "X-Scope-OrgID" ) . ToList ( ) ;
76- tenantHeaders . ShouldBeEquivalentTo ( new List < string > { tenantId } ) ;
77- }
78- else
79- {
80- Should . Throw < ArgumentException > ( ( ) => client . SetTenant ( tenantId ) ) ;
81- }
76+ Should . Throw < ArgumentException > ( ( ) => client . SetTenant ( tenantId ) ) ;
8277 }
8378 }
8479
@@ -120,4 +115,4 @@ public void SetDefaultHeadersShouldSetHeaderCorrectly()
120115 httpClient . DefaultRequestHeaders . Contains ( "Custom-Header" ) . ShouldBeTrue ( ) ;
121116 httpClient . DefaultRequestHeaders . GetValues ( "Custom-Header" ) . ShouldBe ( new [ ] { "HeaderValue" } ) ;
122117 }
123- }
118+ }
0 commit comments