Skip to content

Commit 5503959

Browse files
committed
schema/config_test.go: add a test for an env var without =value
Related: moby/moby#33557 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 6772079 commit 5503959

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

schema/config_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ func TestConfig(t *testing.T) {
210210
`,
211211
fail: false,
212212
},
213+
// expected failure: Env is invalid
214+
{
215+
config: `
216+
{
217+
"architecture": "amd64",
218+
"os": "linux",
219+
"config": {
220+
"Env": [
221+
"foo"
222+
]
223+
},
224+
"rootfs": {
225+
"diff_ids": [
226+
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
227+
],
228+
"type": "layers"
229+
}
230+
}
231+
`,
232+
fail: true,
233+
},
213234
} {
214235
r := strings.NewReader(tt.config)
215236
err := schema.ValidatorMediaTypeImageConfig.Validate(r)

schema/validator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"io"
2222
"io/ioutil"
23+
"regexp"
2324

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

140141
err = header.Digest.Validate()
141-
if err == digest.ErrDigestUnsupported {
142+
if err == digest.ErrDigestUnsupported {
142143
// we ignore unsupported algorithms
143144
fmt.Printf("warning: unsupported digest: %q: %v\n", header.Digest, err)
144145
return nil
@@ -184,6 +185,13 @@ func validateConfig(r io.Reader) error {
184185

185186
checkPlatform(header.OS, header.Architecture)
186187

188+
envRegexp := regexp.MustCompile(`^[^=]+=.*$`)
189+
for _, e := range header.Config.Env {
190+
if !envRegexp.MatchString(e) {
191+
return errors.Errorf("unexpected env: %q", e)
192+
}
193+
}
194+
187195
return nil
188196
}
189197

0 commit comments

Comments
 (0)