Skip to content
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

improve yaml validator #680

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/modules/salt/saltstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,10 @@ func TestUpdateSetting_UpdateAdvancedFailToParse(tester *testing.T) {

// Update setting
setting := model.NewSetting("myapp.advanced")
setting.Value = "new advanced"
setting.Value = "[s new advanced"
setting.Syntax = "yaml"
err := salt.UpdateSetting(ctx(), setting, false)
assert.EqualError(tester, err, "ERROR_MALFORMED_YAML -> yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `new adv...`")
assert.EqualError(tester, err, "ERROR_MALFORMED_YAML -> yaml: line 1: did not find expected ',' or ']'")
}

///// INT TYPE
Expand Down
2 changes: 1 addition & 1 deletion syntax/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ValidateYaml(value string) error {
"length": len(value),
}).Debug("Parsing YAML to verify good syntax")

mapped := make(map[string]interface{})
var mapped interface{}
err = yaml.Unmarshal([]byte(value), &mapped)
if err != nil {
log.WithFields(log.Fields{
Expand Down
4 changes: 3 additions & 1 deletion syntax/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
func TestValidate_Yaml(tester *testing.T) {
for _, syntax := range []string{"yaml", "yml"} {
assert.NoError(tester, Validate("valid: yaml", syntax))
assert.EqualError(tester, Validate("invalid yaml", syntax), "ERROR_MALFORMED_YAML -> yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `invalid...`")
assert.NoError(tester, Validate("- one\n- two", syntax))
assert.NoError(tester, Validate("map_of_list:\n - one\n - two", syntax))
assert.EqualError(tester, Validate("[ lksdgf invalid yaml", syntax), "ERROR_MALFORMED_YAML -> yaml: line 1: did not find expected ',' or ']'")
}
}
Loading