@@ -10,10 +10,11 @@ import (
1010 "testing"
1111
1212 "github.com/go-kit/log"
13+
1314 "github.com/observatorium/api/test/testtls"
1415)
1516
16- // Helper function to generate test certificates using the existing testtls package
17+ // Helper function to generate test certificates using the existing testtls package.
1718func setupTestCertificatesWithFile (t testing.TB ) (clientCert tls.Certificate , caPath string , cleanup func ()) {
1819 t .Helper ()
1920
@@ -26,10 +27,10 @@ func setupTestCertificatesWithFile(t testing.TB) (clientCert tls.Certificate, ca
2627 // Generate certificates using the testtls package
2728 err = testtls .GenerateCerts (
2829 tmpDir ,
29- "test-api" , // API common name
30+ "test-api" , // API common name
3031 []string {"localhost" , "127.0.0.1" }, // API SANs
31- "test-dex" , // Dex common name
32- []string {"localhost" }, // Dex SANs
32+ "test-dex" , // Dex common name
33+ []string {"localhost" }, // Dex SANs
3334 )
3435 if err != nil {
3536 os .RemoveAll (tmpDir )
@@ -70,12 +71,12 @@ func TestMTLSAuthenticator_PathBasedAuthentication(t *testing.T) {
7071 defer cleanup ()
7172
7273 tests := []struct {
73- name string
74- pathPatterns []string
75- requestPath string
76- expectMTLS bool
77- expectError bool
78- description string
74+ name string
75+ pathPatterns []string
76+ requestPath string
77+ expectMTLS bool
78+ expectError bool
79+ description string
7980 }{
8081 {
8182 name : "no_patterns_enforces_all_paths" ,
@@ -139,7 +140,7 @@ func TestMTLSAuthenticator_PathBasedAuthentication(t *testing.T) {
139140 t .Run (tt .name , func (t * testing.T ) {
140141 // Create mTLS config with path patterns using file-based CA
141142 config := map [string ]interface {}{
142- "caPath" : caPath , // Use file-based CA as original code expects
143+ "caPath" : caPath , // Use file-based CA as original code expects
143144 "pathPatterns" : tt .pathPatterns ,
144145 }
145146
@@ -319,7 +320,7 @@ func TestMTLSAuthenticator_InvalidPathPattern(t *testing.T) {
319320 }
320321}
321322
322- // Test path matching logic without requiring certificate validation
323+ // Test path matching logic without requiring certificate validation.
323324func TestMTLSAuthenticator_PathMatchingLogic (t * testing.T ) {
324325 tests := []struct {
325326 name string
@@ -338,7 +339,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
338339 {
339340 name : "pattern_matches_requires_mtls" ,
340341 pathPatterns : []string {"/api/.*/receive" },
341- requestPath : "/api/metrics/v1/receive" ,
342+ requestPath : "/api/metrics/v1/receive" ,
342343 expectSkip : false ,
343344 description : "Matching pattern requires mTLS" ,
344345 },
@@ -379,7 +380,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
379380 }
380381
381382 middleware := authenticator .Middleware ()
382-
383+
383384 handlerCalled := false
384385 testHandler := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
385386 handlerCalled = true
@@ -413,7 +414,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
413414 }
414415}
415416
416- // Test both CA configuration methods work correctly
417+ // Test both CA configuration methods work correctly.
417418func TestMTLSAuthenticator_CAConfiguration (t * testing.T ) {
418419 // Test file-based CA configuration
419420 t .Run ("file_based_ca" , func (t * testing.T ) {
@@ -449,7 +450,7 @@ func TestMTLSAuthenticator_CAConfiguration(t *testing.T) {
449450 }
450451
451452 config := map [string ]interface {}{
452- "ca" : caPEM , // Direct CA data
453+ "ca" : caPEM , // Direct CA data
453454 }
454455
455456 logger := log .NewNopLogger ()
@@ -465,4 +466,3 @@ func TestMTLSAuthenticator_CAConfiguration(t *testing.T) {
465466 }
466467 })
467468}
468-
0 commit comments