Skip to content

Commit

Permalink
Don't allow profiles to refer to themselves
Browse files Browse the repository at this point in the history
Fixes #504
  • Loading branch information
mtibben committed Feb 14, 2020
1 parent 3105570 commit f26b718
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vault/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ func (cl *ConfigLoader) populateFromConfigFile(config *Config, profileName strin
}
}

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

return nil
}

Expand Down
34 changes: 34 additions & 0 deletions vault/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,37 @@ func TestIniWithoutHeaderSavesWithHeader(t *testing.T) {
t.Fatalf("Expected:\n%q\nGot:\n%q", expected, b)
}
}

func TestLoadedProfileDoesntReferToItself(t *testing.T) {
f := newConfigFile(t, []byte(`
[profile foo]
source_profile=foo
`))
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 := "foo"
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 := ""
if config.SourceProfileName != expectedSourceProfileName {
t.Fatalf("Expected '%s', got '%s'", expectedSourceProfileName, config.SourceProfileName)
}
}

0 comments on commit f26b718

Please sign in to comment.