@@ -20,7 +20,6 @@ import (
2020 "crypto/x509"
2121 "encoding/base64"
2222 "os"
23- "path/filepath"
2423 "testing"
2524
2625 "github.com/stretchr/testify/assert"
@@ -54,68 +53,6 @@ func TestRequireTransportSecurity(t *testing.T) {
5453 }
5554}
5655
57- func TestIsFilePath (t * testing.T ) {
58- // Create a temporary file for testing
59- tmpDir := t .TempDir ()
60- tmpFile := filepath .Join (tmpDir , "test.pem" )
61- err := os .WriteFile (tmpFile , []byte ("test content" ), 0600 )
62- require .NoError (t , err )
63-
64- testCases := []struct {
65- name string
66- value string
67- want bool
68- }{
69- {
70- name : "absolute path" ,
71- value : "/path/to/ca.pem" ,
72- want : true ,
73- },
74- {
75- name : "relative path with ./" ,
76- value : "./ca.pem" ,
77- want : true ,
78- },
79- {
80- name : "relative path with ../" ,
81- value : "../ca.pem" ,
82- want : true ,
83- },
84- {
85- name : "home directory path" ,
86- value : "~/ca.pem" ,
87- want : true ,
88- },
89- {
90- name : "existing file" ,
91- value : tmpFile ,
92- want : true ,
93- },
94- {
95- name : "PEM content with newlines" ,
96- value : "-----BEGIN CERTIFICATE-----\n MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A\n -----END CERTIFICATE-----" ,
97- want : false ,
98- },
99- {
100- name : "base64 encoded content" ,
101- value : "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=" ,
102- want : false ,
103- },
104- {
105- name : "non-existent file without path prefix" ,
106- value : "nonexistent.pem" ,
107- want : false ,
108- },
109- }
110-
111- for _ , tc := range testCases {
112- t .Run (tc .name , func (t * testing.T ) {
113- got := IsFilePath (tc .value )
114- assert .Equal (t , tc .want , got , "IsFilePath(%q) = %v, want %v" , tc .value , got , tc .want )
115- })
116- }
117- }
118-
11956func TestAppendCAFromFile (t * testing.T ) {
12057 // Check if the file exists, skip test if not
12158 if _ , err := os .Stat (caPath ); os .IsNotExist (err ) {
@@ -210,7 +147,8 @@ func TestBackwardCompatibility_StoredFilePath(t *testing.T) {
210147 storedValue := caPath
211148
212149 // Verify IsFilePath detects it as a file path
213- assert .True (t , IsFilePath (storedValue ), "stored file path should be detected as a file path" )
150+ _ , err := os .Stat (storedValue )
151+ assert .Nil (t , err , "stored file path should be detected as a file path" )
214152
215153 // Verify it can be loaded using the file path method
216154 certsPool , err := x509 .SystemCertPool ()
@@ -233,7 +171,7 @@ func TestBackwardCompatibility_NewClientOldConfig(t *testing.T) {
233171
234172 // New client logic: detect and load appropriately
235173 var opts []Option
236- if IsFilePath (oldConfigValue ) {
174+ if _ , err := os . Stat (oldConfigValue ); err == nil {
237175 opts = append (opts , WithCAFile (oldConfigValue ))
238176 } else {
239177 opts = append (opts , WithCAContent (oldConfigValue ))
@@ -273,7 +211,7 @@ func TestBackwardCompatibility_OldClientNewConfig(t *testing.T) {
273211 assert .NoError (t , err , "old client should load file path" )
274212
275213 // New client behavior: detect then use file path
276- if IsFilePath (configValue ) {
214+ if _ , statErr := os . Stat (configValue ); statErr == nil {
277215 err = appendCAFromFile (configValue , certsPool2 )
278216 } else {
279217 err = appendCAFromContent (configValue , certsPool2 )
0 commit comments