Skip to content

Commit

Permalink
Fix test for recursive source_profile. Fixes #527
Browse files Browse the repository at this point in the history
  • Loading branch information
mtibben committed Feb 18, 2020
1 parent 12866e7 commit 0760274
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vault/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (cl *ConfigLoader) populateFromConfigFile(config *Config, profileName strin
}

// Ignore source_profile if it recursively refers to the profile
if config.SourceProfileName == profileName {
if config.SourceProfileName == config.ProfileName {
config.SourceProfileName = ""
}

Expand Down
37 changes: 37 additions & 0 deletions vault/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,40 @@ source_profile=foo
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfileName, config.SourceProfileName)
}
}

func TestSourceProfileCanReferToParent(t *testing.T) {
f := newConfigFile(t, []byte(`
[profile root]
[profile foo]
parent_profile=root
source_profile=root
`))
defer os.Remove(f)

configFile, err := vault.LoadConfig(f)
if err != nil {
t.Fatal(err)
}

def, ok := configFile.ProfileSection("foo")
if !ok {
t.Fatalf("Couldn't load profile foo")
}

expectedSourceProfile := "root"
if def.SourceProfile != expectedSourceProfile {
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfile, def.SourceProfile)
}

configLoader := &vault.ConfigLoader{File: configFile}
config, err := configLoader.LoadFromProfile("foo")
if err != nil {
t.Fatalf("Should have found a profile: %v", err)
}

expectedSourceProfileName := "root"
if config.SourceProfileName != expectedSourceProfileName {
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfileName, config.SourceProfileName)
}
}

1 comment on commit 0760274

@whi-tw
Copy link

@whi-tw whi-tw commented on 0760274 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.