Skip to content

Commit 8fd3a89

Browse files
committed
Fix: nil map panic in ConfigLoader tests
Replace direct struct instantiation with NewConfigLoader constructor to properly initialize the sourceChain map. This prevents panics when GetProfileConfig tries to assign to the nil map.
1 parent 2432e9e commit 8fd3a89

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

vault/config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestIncludeProfile(t *testing.T) {
253253
t.Fatal(err)
254254
}
255255

256-
configLoader := &vault.ConfigLoader{File: configFile}
256+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "")
257257
config, err := configLoader.GetProfileConfig("testincludeprofile2")
258258
if err != nil {
259259
t.Fatalf("Should have found a profile: %v", err)
@@ -273,7 +273,7 @@ func TestIncludeSsoSession(t *testing.T) {
273273
t.Fatal(err)
274274
}
275275

276-
configLoader := &vault.ConfigLoader{File: configFile}
276+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "")
277277
config, err := configLoader.GetProfileConfig("with-sso-session")
278278
if err != nil {
279279
t.Fatalf("Should have found a profile: %v", err)
@@ -368,7 +368,7 @@ source_profile=foo
368368
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfile, def.SourceProfile)
369369
}
370370

371-
configLoader := &vault.ConfigLoader{File: configFile}
371+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "")
372372
config, err := configLoader.GetProfileConfig("foo")
373373
if err != nil {
374374
t.Fatalf("Should have found a profile: %v", err)
@@ -405,7 +405,7 @@ source_profile=root
405405
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfile, def.SourceProfile)
406406
}
407407

408-
configLoader := &vault.ConfigLoader{File: configFile}
408+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "")
409409
config, err := configLoader.GetProfileConfig("foo")
410410
if err != nil {
411411
t.Fatalf("Should have found a profile: %v", err)
@@ -495,7 +495,7 @@ transitive_session_tags = tagOne ,tagTwo,tagThree
495495
if err != nil {
496496
t.Fatal(err)
497497
}
498-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "tagged"}
498+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "tagged")
499499
config, err := configLoader.GetProfileConfig("tagged")
500500
if err != nil {
501501
t.Fatalf("Should have found a profile: %v", err)
@@ -532,7 +532,7 @@ transitive_session_tags = tagOne ,tagTwo,tagThree
532532
if err != nil {
533533
t.Fatal(err)
534534
}
535-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "tagged"}
535+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "tagged")
536536
config, err := configLoader.GetProfileConfig("tagged")
537537
if err != nil {
538538
t.Fatalf("Should have found a profile: %v", err)
@@ -577,7 +577,7 @@ source_profile = interim
577577
if err != nil {
578578
t.Fatal(err)
579579
}
580-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "target"}
580+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "target")
581581
config, err := configLoader.GetProfileConfig("target")
582582
if err != nil {
583583
t.Fatalf("Should have found a profile: %v", err)

vault/vault_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ web_identity_token_process = oidccli raw
1919
if err != nil {
2020
t.Fatal(err)
2121
}
22-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "role2"}
22+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "role2")
2323
config, err := configLoader.GetProfileConfig("role2")
2424
if err != nil {
2525
t.Fatalf("Should have found a profile: %v", err)
@@ -55,7 +55,7 @@ role_arn=arn:aws:iam::12345678901:role/allow-view-only-access-from-other-account
5555
if err != nil {
5656
t.Fatal(err)
5757
}
58-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "my-shared-base-profile"}
58+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "my-shared-base-profile")
5959
config, err := configLoader.GetProfileConfig("my-shared-base-profile")
6060
if err != nil {
6161
t.Fatalf("Should have found a profile: %v", err)
@@ -103,7 +103,7 @@ sso_registration_scopes=sso:account:access
103103
if err != nil {
104104
t.Fatal(err)
105105
}
106-
configLoader := &vault.ConfigLoader{File: configFile, ActiveProfile: "test"}
106+
configLoader := vault.NewConfigLoader(vault.ProfileConfig{}, configFile, "test")
107107
config, err := configLoader.GetProfileConfig("test")
108108
if err != nil {
109109
t.Fatalf("Should have found a profile: %v", err)

0 commit comments

Comments
 (0)