@@ -198,3 +198,72 @@ func TestSecrets(t *testing.T) {
198198 value = store .GetWithDefault (ctx , testKey , defaultValue )
199199 assert .Equal (t , testValue , value )
200200}
201+
202+ func TestValidateConfigPath (t * testing.T ) {
203+ tests := []struct {
204+ name string
205+ path string
206+ expectError bool
207+ setup func () string // returns path to cleanup
208+ }{
209+ {
210+ name : "valid json file" ,
211+ path : "config_test.json" ,
212+ expectError : false ,
213+ setup : func () string {
214+ tmpFile , _ := os .CreateTemp ("" , "config_test_*.json" )
215+ tmpFile .WriteString ("{}" )
216+ tmpFile .Close ()
217+ return tmpFile .Name ()
218+ },
219+ },
220+ {
221+ name : "empty path" ,
222+ path : "" ,
223+ expectError : true ,
224+ setup : func () string { return "" },
225+ },
226+ {
227+ name : "path traversal" ,
228+ path : "../../../etc/passwd" ,
229+ expectError : true ,
230+ setup : func () string { return "" },
231+ },
232+ {
233+ name : "non-json file" ,
234+ path : "config.txt" ,
235+ expectError : true ,
236+ setup : func () string {
237+ tmpFile , _ := os .CreateTemp ("" , "config_test_*.txt" )
238+ tmpFile .WriteString ("{}" )
239+ tmpFile .Close ()
240+ return tmpFile .Name ()
241+ },
242+ },
243+ {
244+ name : "nonexistent file" ,
245+ path : "nonexistent.json" ,
246+ expectError : true ,
247+ setup : func () string { return "" },
248+ },
249+ }
250+
251+ for _ , tt := range tests {
252+ t .Run (tt .name , func (t * testing.T ) {
253+ cleanupPath := tt .setup ()
254+ if cleanupPath != "" {
255+ defer os .Remove (cleanupPath )
256+ if tt .path == "config_test.json" || tt .path == "config.txt" {
257+ tt .path = cleanupPath
258+ }
259+ }
260+
261+ err := validateConfigPath (tt .path )
262+ if tt .expectError {
263+ assert .Error (t , err )
264+ } else {
265+ assert .NoError (t , err )
266+ }
267+ })
268+ }
269+ }
0 commit comments