Skip to content

Commit

Permalink
Merge pull request #693 from AkihiroSuda/env-test
Browse files Browse the repository at this point in the history
schema/config_test.go: add a test for an env var without `=value`
  • Loading branch information
vbatts authored Jun 23, 2017
2 parents fc936c7 + 5503959 commit af173bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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
10 changes: 9 additions & 1 deletion schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"io/ioutil"
"regexp"

digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -138,7 +139,7 @@ func validateDescriptor(r io.Reader) error {
}

err = header.Digest.Validate()
if err == digest.ErrDigestUnsupported {
if err == digest.ErrDigestUnsupported {
// we ignore unsupported algorithms
fmt.Printf("warning: unsupported digest: %q: %v\n", header.Digest, err)
return nil
Expand Down Expand Up @@ -184,6 +185,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 af173bc

Please sign in to comment.