Skip to content

Commit

Permalink
Relax YAML document marker requirments (gopasspw#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz authored Oct 16, 2017
1 parent 0ba6175 commit 6daa299
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion store/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Parse(buf []byte) (*Secret, error) {

// decodeYAML attempts to decode an optional YAML part of a secret
func (s *Secret) decodeYAML() (bool, error) {
if !strings.HasPrefix(s.body, "---\n") {
if !strings.HasPrefix(s.body, "---\n") && s.password != "---" {
return false, nil
}
d := make(map[string]interface{})
Expand Down
42 changes: 42 additions & 0 deletions store/secret/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,48 @@ url: http://www.test.com/`
}
},
},
{
name: "Document Marker as Password (#398)",
tf: func(t *testing.T) {
mlValue := `---`
s, err := Parse([]byte(mlValue))
if err != nil {
t.Logf("%s", err)
}
if s == nil {
t.Fatalf("Secret is nil")
}
// read back key
if s.Password() != "---" {
t.Errorf("Secret does not match input")
}
},
},
{
name: "YAML Body without Password (#398)",
tf: func(t *testing.T) {
mlValue := `---
username: myuser@test.com
password: somepasswd
url: http://www.test.com/`
s, err := Parse([]byte(mlValue))
if err != nil {
t.Logf("%s", err)
}
if s == nil {
t.Fatalf("Secret is nil")
}
t.Logf("Data: %+v", s.Data())
// read back key
val, err := s.Value("username")
if err != nil {
t.Fatalf("Failed to read username: %s", err)
}
if val != "myuser@test.com" {
t.Errorf("Decoded Secret does not match input")
}
},
},
} {
// run test case
t.Run(tc.name, tc.tf)
Expand Down

0 comments on commit 6daa299

Please sign in to comment.