Skip to content

Commit 1e99ed3

Browse files
committed
Disallow additional properties in credential_spec
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 896ff57 commit 1e99ed3

8 files changed

Lines changed: 254 additions & 193 deletions

File tree

cli/compose/loader/loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ services:
283283
foo:
284284
image: busybox
285285
credential_spec:
286-
File: "/foo"
286+
file: "/foo"
287287
configs: [super]
288288
configs:
289289
super:

cli/compose/schema/bindata.go

Lines changed: 172 additions & 172 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/compose/schema/data/config_schema_v3.3.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@
118118
}
119119
},
120120
"container_name": {"type": "string"},
121-
"credential_spec": {"type": "object", "properties": {
122-
"file": {"type": "string"},
123-
"registry": {"type": "string"}
124-
}},
121+
"credential_spec": {
122+
"type": "object",
123+
"properties": {
124+
"file": {"type": "string"},
125+
"registry": {"type": "string"}
126+
},
127+
"additionalProperties": false
128+
},
125129
"depends_on": {"$ref": "#/definitions/list_of_strings"},
126130
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
127131
"dns": {"$ref": "#/definitions/string_or_list"},

cli/compose/schema/data/config_schema_v3.4.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@
121121
}
122122
},
123123
"container_name": {"type": "string"},
124-
"credential_spec": {"type": "object", "properties": {
125-
"file": {"type": "string"},
126-
"registry": {"type": "string"}
127-
}},
124+
"credential_spec": {
125+
"type": "object",
126+
"properties": {
127+
"file": {"type": "string"},
128+
"registry": {"type": "string"}
129+
},
130+
"additionalProperties": false
131+
},
128132
"depends_on": {"$ref": "#/definitions/list_of_strings"},
129133
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
130134
"dns": {"$ref": "#/definitions/string_or_list"},

cli/compose/schema/data/config_schema_v3.5.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@
122122
}
123123
},
124124
"container_name": {"type": "string"},
125-
"credential_spec": {"type": "object", "properties": {
126-
"file": {"type": "string"},
127-
"registry": {"type": "string"}
128-
}},
125+
"credential_spec": {
126+
"type": "object",
127+
"properties": {
128+
"file": {"type": "string"},
129+
"registry": {"type": "string"}
130+
},
131+
"additionalProperties": false
132+
},
129133
"depends_on": {"$ref": "#/definitions/list_of_strings"},
130134
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
131135
"dns": {"$ref": "#/definitions/string_or_list"},

cli/compose/schema/data/config_schema_v3.6.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@
122122
}
123123
},
124124
"container_name": {"type": "string"},
125-
"credential_spec": {"type": "object", "properties": {
126-
"file": {"type": "string"},
127-
"registry": {"type": "string"}
128-
}},
125+
"credential_spec": {
126+
"type": "object",
127+
"properties": {
128+
"file": {"type": "string"},
129+
"registry": {"type": "string"}
130+
},
131+
"additionalProperties": false
132+
},
129133
"depends_on": {"$ref": "#/definitions/list_of_strings"},
130134
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
131135
"dns": {"$ref": "#/definitions/string_or_list"},

cli/compose/schema/data/config_schema_v3.7.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@
122122
}
123123
},
124124
"container_name": {"type": "string"},
125-
"credential_spec": {"type": "object", "properties": {
126-
"file": {"type": "string"},
127-
"registry": {"type": "string"}
128-
}},
125+
"credential_spec": {
126+
"type": "object",
127+
"properties": {
128+
"file": {"type": "string"},
129+
"registry": {"type": "string"}
130+
},
131+
"additionalProperties": false
132+
},
129133
"depends_on": {"$ref": "#/definitions/list_of_strings"},
130134
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
131135
"dns": {"$ref": "#/definitions/string_or_list"},

cli/compose/schema/schema_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package schema
22

33
import (
4+
"fmt"
45
"testing"
56

67
"gotest.tools/assert"
@@ -78,6 +79,46 @@ func TestValidateAllowsXFields(t *testing.T) {
7879
assert.NilError(t, err)
7980
}
8081

82+
func TestValidateCredentialSpecs(t *testing.T) {
83+
config := dict{
84+
"version": "99.99",
85+
"services": dict{
86+
"foo": dict{
87+
"image": "busybox",
88+
"credential_spec": dict{
89+
"config": "foobar",
90+
},
91+
},
92+
},
93+
}
94+
tests := []struct {
95+
version string
96+
expectedErr string
97+
}{
98+
{version: "3.0", expectedErr: "credential_spec"},
99+
{version: "3.1", expectedErr: "credential_spec"},
100+
{version: "3.2", expectedErr: "credential_spec"},
101+
{version: "3.3", expectedErr: "config"},
102+
{version: "3.4", expectedErr: "config"},
103+
{version: "3.5", expectedErr: "config"},
104+
{version: "3.6", expectedErr: "config"},
105+
{version: "3.7", expectedErr: "config"},
106+
}
107+
108+
for _, tc := range tests {
109+
tc := tc
110+
t.Run(tc.version, func(t *testing.T) {
111+
err := Validate(config, tc.version)
112+
if tc.expectedErr != "" {
113+
assert.ErrorContains(t, err, fmt.Sprintf("Additional property %s is not allowed", tc.expectedErr))
114+
} else {
115+
assert.NilError(t, err)
116+
}
117+
})
118+
}
119+
120+
}
121+
81122
func TestValidateSecretConfigNames(t *testing.T) {
82123
config := dict{
83124
"version": "3.5",

0 commit comments

Comments
 (0)