@@ -217,6 +217,90 @@ func Test_DynamicStore_authConfigured(t *testing.T) {
217
217
if err := ds .Put (ctx , serverAddr , cred ); err != nil {
218
218
t .Fatal ("DynamicStore.Get() error =" , err )
219
219
}
220
+ // Put() should not set detected store back to config
221
+ if got := ds .detectedCredsStore ; got != "" {
222
+ t .Errorf ("ds.detectedCredsStore = %v, want empty" , got )
223
+ }
224
+ if got := ds .config .CredentialsStore (); got != "" {
225
+ t .Errorf ("ds.config.CredentialsStore() = %v, want empty" , got )
226
+ }
227
+
228
+ // test get
229
+ got , err := ds .Get (ctx , serverAddr )
230
+ if err != nil {
231
+ t .Fatal ("DynamicStore.Get() error =" , err )
232
+ }
233
+ if want := cred ; got != want {
234
+ t .Errorf ("DynamicStore.Get() = %v, want %v" , got , want )
235
+ }
236
+
237
+ // test delete
238
+ err = ds .Delete (ctx , serverAddr )
239
+ if err != nil {
240
+ t .Fatal ("DynamicStore.Delete() error =" , err )
241
+ }
242
+
243
+ // verify delete
244
+ got , err = ds .Get (ctx , serverAddr )
245
+ if err != nil {
246
+ t .Fatal ("DynamicStore.Get() error =" , err )
247
+ }
248
+ if want := auth .EmptyCredential ; got != want {
249
+ t .Errorf ("DynamicStore.Get() = %v, want %v" , got , want )
250
+ }
251
+ }
252
+
253
+ func Test_DynamicStore_authConfigured_DetectDefaultNativeStore (t * testing.T ) {
254
+ // prepare test content
255
+ tempDir := t .TempDir ()
256
+ configPath := filepath .Join (tempDir , "auth_configured.json" )
257
+ config := configtest.Config {
258
+ AuthConfigs : map [string ]configtest.AuthConfig {
259
+ "xxx" : {},
260
+ },
261
+ SomeConfigField : 123 ,
262
+ }
263
+ jsonStr , err := json .Marshal (config )
264
+ if err != nil {
265
+ t .Fatalf ("failed to marshal config: %v" , err )
266
+ }
267
+ if err := os .WriteFile (configPath , jsonStr , 0666 ); err != nil {
268
+ t .Fatalf ("failed to write config file: %v" , err )
269
+ }
270
+
271
+ opts := StoreOptions {
272
+ AllowPlaintextPut : true ,
273
+ DetectDefaultNativeStore : true ,
274
+ }
275
+ ds , err := NewStore (configPath , opts )
276
+ if err != nil {
277
+ t .Fatal ("NewStore() error =" , err )
278
+ }
279
+
280
+ // test IsAuthConfigured
281
+ authConfigured := ds .IsAuthConfigured ()
282
+ if want := true ; authConfigured != want {
283
+ t .Errorf ("DynamicStore.IsAuthConfigured() = %v, want %v" , authConfigured , want )
284
+ }
285
+
286
+ serverAddr := "test.example.com"
287
+ cred := auth.Credential {
288
+ Username : "username" ,
289
+ Password : "password" ,
290
+ }
291
+ ctx := context .Background ()
292
+
293
+ // test put
294
+ if err := ds .Put (ctx , serverAddr , cred ); err != nil {
295
+ t .Fatal ("DynamicStore.Get() error =" , err )
296
+ }
297
+ // Put() should not set detected store back to config
298
+ if got := ds .detectedCredsStore ; got != "" {
299
+ t .Errorf ("ds.detectedCredsStore = %v, want empty" , got )
300
+ }
301
+ if got := ds .config .CredentialsStore (); got != "" {
302
+ t .Errorf ("ds.config.CredentialsStore() = %v, want empty" , got )
303
+ }
220
304
221
305
// test get
222
306
got , err := ds .Get (ctx , serverAddr )
@@ -280,16 +364,15 @@ func Test_DynamicStore_noAuthConfigured(t *testing.T) {
280
364
if _ , err := ds .Get (ctx , serverAddr ); err != nil {
281
365
t .Fatal ("DynamicStore.Get() error =" , err )
282
366
}
283
- if got := ds .config .CredentialsStore (); got != "" {
284
- t .Errorf ("ds.config.CredentialsStore() = %v, want empty" , got )
285
- }
286
367
287
368
// test put
288
369
if err := ds .Put (ctx , serverAddr , cred ); err != nil {
289
370
t .Fatal ("DynamicStore.Put() error =" , err )
290
371
}
291
-
292
372
// Put() should not set detected store back to config
373
+ if got := ds .detectedCredsStore ; got != "" {
374
+ t .Errorf ("ds.detectedCredsStore = %v, want empty" , got )
375
+ }
293
376
if got := ds .config .CredentialsStore (); got != "" {
294
377
t .Errorf ("ds.config.CredentialsStore() = %v, want empty" , got )
295
378
}
@@ -319,7 +402,7 @@ func Test_DynamicStore_noAuthConfigured(t *testing.T) {
319
402
}
320
403
}
321
404
322
- func Test_DynamicStore_noAuthConfigured_DetectDefaultStore (t * testing.T ) {
405
+ func Test_DynamicStore_noAuthConfigured_DetectDefaultNativeStore (t * testing.T ) {
323
406
// prepare test content
324
407
tempDir := t .TempDir ()
325
408
configPath := filepath .Join (tempDir , "no_auth_configured.json" )
@@ -335,8 +418,8 @@ func Test_DynamicStore_noAuthConfigured_DetectDefaultStore(t *testing.T) {
335
418
}
336
419
337
420
opts := StoreOptions {
338
- AllowPlaintextPut : true ,
339
- DetectDefaultCredsStore : true ,
421
+ AllowPlaintextPut : true ,
422
+ DetectDefaultNativeStore : true ,
340
423
}
341
424
ds , err := NewStore (configPath , opts )
342
425
if err != nil {
@@ -356,10 +439,15 @@ func Test_DynamicStore_noAuthConfigured_DetectDefaultStore(t *testing.T) {
356
439
}
357
440
ctx := context .Background ()
358
441
359
- // Get() should not set detected store back to config
442
+ // Get() should set detectedCredsStore only, but should not save it back to config
360
443
if _ , err := ds .Get (ctx , serverAddr ); err != nil {
361
444
t .Fatal ("DynamicStore.Get() error =" , err )
362
445
}
446
+ if defaultStore := getDefaultHelperSuffix (); defaultStore != "" {
447
+ if got := ds .detectedCredsStore ; got != defaultStore {
448
+ t .Errorf ("ds.detectedCredsStore = %v, want %v" , got , defaultStore )
449
+ }
450
+ }
363
451
if got := ds .config .CredentialsStore (); got != "" {
364
452
t .Errorf ("ds.config.CredentialsStore() = %v, want empty" , got )
365
453
}
@@ -369,11 +457,9 @@ func Test_DynamicStore_noAuthConfigured_DetectDefaultStore(t *testing.T) {
369
457
t .Fatal ("DynamicStore.Put() error =" , err )
370
458
}
371
459
372
- // Put() should set detected store back to config
373
- if defaultStore := getDefaultHelperSuffix (); defaultStore != "" {
374
- if got := ds .config .CredentialsStore (); got != defaultStore {
375
- t .Errorf ("ds.config.CredentialsStore() = %v, want %v" , got , defaultStore )
376
- }
460
+ // Put() should set the detected store back to config
461
+ if got := ds .config .CredentialsStore (); got != ds .detectedCredsStore {
462
+ t .Errorf ("ds.config.CredentialsStore() = %v, want %v" , got , ds .detectedCredsStore )
377
463
}
378
464
379
465
// test get
0 commit comments