Skip to content

Commit

Permalink
schema/config_test.go: add a test for an env var without =value
Browse files Browse the repository at this point in the history
Related: moby/moby#33557

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Jun 13, 2017
1 parent df6f3c5 commit bf681bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
21 changes: 21 additions & 0 deletions schema/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ func TestConfig(t *testing.T) {
`,
fail: false,
},
// expected failure: Env is invalid
{
config: `
{
"architecture": "amd64",
"os": "linux",
"config": {
"Env": [
"foo"
]
},
"rootfs": {
"diff_ids": [
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
],
"type": "layers"
}
}
`,
fail: true,
},
} {
r := strings.NewReader(tt.config)
err := schema.ValidatorMediaTypeImageConfig.Validate(r)
Expand Down
7 changes: 7 additions & 0 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ func validateConfig(r io.Reader) error {

checkPlatform(header.OS, header.Architecture)

envRegexp := regexp.MustCompile(`^[^=]+=.*$`)
for _, e := range header.Config.Env {
if !envRegexp.MatchString(e) {
return errors.Errorf("unexpected env: %q", e)
}
}

return nil
}

Expand Down

0 comments on commit bf681bb

Please sign in to comment.