-
Notifications
You must be signed in to change notification settings - Fork 1k
stores: test for duplicate keys, reserve keyword (yaml only now) #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,19 +62,19 @@ key4: *bar | |
| var ALIASES_BRANCHES = sops.TreeBranches{ | ||
| sops.TreeBranch{ | ||
| sops.TreeItem{ | ||
| Key: "key1", | ||
| Key: "key1", | ||
| Value: []interface{}{ | ||
| "foo", | ||
| }, | ||
| }, | ||
| sops.TreeItem{ | ||
| Key: "key2", | ||
| Key: "key2", | ||
| Value: []interface{}{ | ||
| "foo", | ||
| }, | ||
| }, | ||
| sops.TreeItem{ | ||
| Key: "key3", | ||
| Key: "key3", | ||
| Value: sops.TreeBranch{ | ||
| sops.TreeItem{ | ||
| Key: "foo", | ||
|
|
@@ -87,7 +87,7 @@ var ALIASES_BRANCHES = sops.TreeBranches{ | |
| }, | ||
| }, | ||
| sops.TreeItem{ | ||
| Key: "key4", | ||
| Key: "key4", | ||
| Value: sops.TreeBranch{ | ||
| sops.TreeItem{ | ||
| Key: "foo", | ||
|
|
@@ -237,7 +237,6 @@ prometheus-node-exporter: | |
| - --collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$ | ||
| `) | ||
|
|
||
|
|
||
| func TestUnmarshalMetadataFromNonSOPSFile(t *testing.T) { | ||
| data := []byte(`hello: 2`) | ||
| _, err := (&Store{}).LoadEncryptedFile(data) | ||
|
|
@@ -398,3 +397,35 @@ func TestHasSopsTopLevelKey(t *testing.T) { | |
| }) | ||
| assert.Equal(t, ok, false) | ||
| } | ||
|
|
||
| func TestDuplicateAttributes(t *testing.T) { | ||
| // Duplicate keys are _not_ valid yaml. | ||
| // | ||
| // See https://yaml.org/spec/1.2.2/#mapping | ||
| // > The content of a mapping node is an unordered set of key/value node pairs, | ||
| // > with the restriction that each of the keys is unique. | ||
| // | ||
| data := ` | ||
| hello: Sops config file | ||
| hello: Duplicates are not ok | ||
| rootunique: | ||
| key2: "value" | ||
| key2: "foo" | ||
| ` | ||
| s := new(Store) | ||
| _, err := s.LoadPlainFile([]byte(data)) | ||
| assert.NotNil(t, err) | ||
| assert.Equal(t, `yaml: unmarshal errors: | ||
| line 3: mapping key "hello" already defined at line 2`, err.Error()) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also add a test which looks at multi-document YAML streams (with collisions in later documents). |
||
|
|
||
| func TestReservedAttributes(t *testing.T) { | ||
| data := ` | ||
| hello: Sops config file | ||
| sops: The attribute 'sops' must be rejected, otherwise the file cannot be opened later on | ||
| ` | ||
| s := new(Store) | ||
| _, err := s.LoadPlainFile([]byte(data)) | ||
| assert.NotNil(t, err) | ||
| assert.Equal(t, `YAML doc used reserved word 'sops'`, err.Error()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, we should extend this test to verify that re-serializing yields the same result.