Skip to content

Commit ce67457

Browse files
committed
Add validation tests
Signed-off-by: Tushar Goel <[email protected]>
1 parent 96d6f8c commit ce67457

33 files changed

+2643
-4
lines changed

schemas/purl-test.schema.json

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@
104104
"enum": [
105105
"build",
106106
"parse",
107-
"roundtrip"
107+
"roundtrip",
108+
"validation"
108109
],
109110
"meta:enum": {
110111
"build": "A PURL building test from decoded components to a canonical PURL string.",
111112
"parse": "A PURL building test from decoded components to a canonical PURL string.",
112-
"roundtrip": "A PURL routrip test, parsing then building back a PURL from a canonical string input."
113+
"roundtrip": "A PURL routrip test, parsing then building back a PURL from a canonical string input.",
114+
"validation": "A PURL validation test, checking if a PURL follows all the rules for a particular ecosystem."
113115
}
114116
},
115117
"expected_failure": {
@@ -126,7 +128,16 @@
126128
"string",
127129
"null"
128130
]
131+
},
132+
"expected_messages": {
133+
"title": "Expected messages",
134+
"description": "Validation messages expected for this test. Can be null or a list of strings.",
135+
"default": null,
136+
"type": ["null", "array"],
137+
"items": {
138+
"type": "string"
129139
}
140+
}
130141
},
131142
"allOf": [
132143
{
@@ -284,6 +295,31 @@
284295
"expected_failure_reason"
285296
]
286297
}
298+
},
299+
{
300+
"if": {
301+
"properties": {
302+
"test_type": { "const": "validation" }
303+
},
304+
"required": ["test_type"]
305+
},
306+
"then": {
307+
"properties": {
308+
"input": {
309+
"title": "Expected decoded PURL components",
310+
"description": "Test input as an object with decoded PURL components for validation.",
311+
"$ref": "#/definitions/purl_components"
312+
},
313+
"expected_messages": {
314+
"title": "Expected messages",
315+
"description": "Validation messages expected for this test. Can be null or a list of strings.",
316+
"default": null,
317+
"type": ["null", "array"],
318+
"items": { "type": "string" }
319+
}
320+
},
321+
"required": ["input"]
322+
}
287323
}
288324
]
289325
}

tests/types/alpm-test.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,104 @@
135135
"expected_output": "pkg:alpm/arch/containers-common@1:0.47.4-4?arch=x86_64",
136136
"expected_failure": false,
137137
"expected_failure_reason": null
138+
},
139+
{
140+
"description": "Valid alpm package with arch qualifier",
141+
"test_group": "base",
142+
"test_type": "validation",
143+
"input": {
144+
"type": "alpm",
145+
"namespace": "arch",
146+
"name": "pacman",
147+
"version": "6.0.1-1",
148+
"qualifiers": {
149+
"arch": "x86_64"
150+
},
151+
"subpath": null
152+
},
153+
"expected_messages": null
154+
},
155+
{
156+
"description": "alpm package with uppercase nmamespace",
157+
"test_group": "base",
158+
"test_type": "validation",
159+
"input": {
160+
"type": "alpm",
161+
"namespace": "Arch",
162+
"name": "pacman",
163+
"version": "6.0.1-1",
164+
"qualifiers": {
165+
"arch": "x86_64"
166+
},
167+
"subpath": null
168+
},
169+
"expected_messages": ["Namespace is not lowercased for purl type: 'alpm'"]
170+
},
171+
{
172+
"description": "alpm package with uppercase nmamespace (advanced)",
173+
"test_group": "advanced",
174+
"test_type": "validation",
175+
"input": {
176+
"type": "alpm",
177+
"namespace": "Arch",
178+
"name": "pacman",
179+
"version": "6.0.1-1",
180+
"qualifiers": {
181+
"arch": "x86_64"
182+
},
183+
"subpath": null
184+
},
185+
"expected_messages": null
186+
},
187+
{
188+
"description": "Valid alpm package with 'any' arch",
189+
"test_group": "base",
190+
"test_type": "validation",
191+
"input": {
192+
"type": "alpm",
193+
"namespace": "arch",
194+
"name": "python-pip",
195+
"version": "21.0-1",
196+
"qualifiers": {
197+
"arch": "any"
198+
},
199+
"subpath": null
200+
},
201+
"expected_messages": null
202+
},
203+
{
204+
"description": "Valid alpm package with epoch in version",
205+
"test_group": "advanced",
206+
"test_type": "validation",
207+
"input": {
208+
"type": "alpm",
209+
"namespace": "arch",
210+
"name": "containers-common",
211+
"version": "1:0.47.4-4",
212+
"qualifiers": {
213+
"arch": "x86_64"
214+
},
215+
"subpath": null
216+
},
217+
"expected_messages": null
218+
},
219+
{
220+
"description": "alpm package missing namespace",
221+
"test_group": "base",
222+
"test_type": "validation",
223+
"input": {
224+
"type": "alpm",
225+
"namespace": null,
226+
"name": "pacman",
227+
"version": "6.0.1-1",
228+
"qualifiers": {
229+
"arch": "x86_64"
230+
},
231+
"subpath": null
232+
},
233+
"expected_messages": [
234+
"Namespace is required for purl type: 'alpm'"
235+
]
138236
}
139237
]
140238
}

tests/types/apk-test.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,107 @@
9090
"expected_output": "pkg:apk/alpine/[email protected]?arch=x86",
9191
"expected_failure": false,
9292
"expected_failure_reason": null
93+
},
94+
{
95+
"description": "Valid apk package with arch qualifier",
96+
"test_group": "base",
97+
"test_type": "validation",
98+
"input": {
99+
"type": "apk",
100+
"namespace": "alpine",
101+
"name": "curl",
102+
"version": "7.83.0-r0",
103+
"qualifiers": {
104+
"arch": "x86"
105+
},
106+
"subpath": null
107+
},
108+
"expected_messages": null
109+
},
110+
{
111+
"description": "Valid apk package with higher version and arch qualifier",
112+
"test_group": "base",
113+
"test_type": "validation",
114+
"input": {
115+
"type": "apk",
116+
"namespace": "alpine",
117+
"name": "apk",
118+
"version": "2.12.9-r3",
119+
"qualifiers": {
120+
"arch": "x86"
121+
},
122+
"subpath": null
123+
},
124+
"expected_messages": null
125+
},
126+
{
127+
"description": "Valid apk package with openwrt vendor",
128+
"test_group": "advanced",
129+
"test_type": "validation",
130+
"input": {
131+
"type": "apk",
132+
"namespace": "openwrt",
133+
"name": "busybox",
134+
"version": "1.35.0-r5",
135+
"qualifiers": {
136+
"arch": "mips"
137+
},
138+
"subpath": null
139+
},
140+
"expected_messages": null
141+
},
142+
{
143+
"description": "apk package missing namespace",
144+
"test_group": "base",
145+
"test_type": "validation",
146+
"input": {
147+
"type": "apk",
148+
"namespace": null,
149+
"name": "curl",
150+
"version": "7.83.0-r0",
151+
"qualifiers": {
152+
"arch": "x86"
153+
},
154+
"subpath": null
155+
},
156+
"expected_messages": [
157+
"Namespace is required for purl type: 'apk'"
158+
]
159+
},
160+
{
161+
"description": "apk package with uppercase namespace and name",
162+
"test_group": "base",
163+
"test_type": "validation",
164+
"input": {
165+
"type": "apk",
166+
"namespace": "FOO",
167+
"name": "BAR",
168+
"version": "7.83.0-r0",
169+
"qualifiers": {
170+
"arch": "x86"
171+
},
172+
"subpath": null
173+
},
174+
"expected_messages": [
175+
"Namespace is not lowercased for purl type: 'apk'",
176+
"Name is not lowercased for purl type: 'apk'"
177+
]
178+
},
179+
{
180+
"description": "apk package with uppercase namespace and name (advanced)",
181+
"test_group": "advanced",
182+
"test_type": "validation",
183+
"input": {
184+
"type": "apk",
185+
"namespace": "FOO",
186+
"name": "BAR",
187+
"version": "7.83.0-r0",
188+
"qualifiers": {
189+
"arch": "x86"
190+
},
191+
"subpath": null
192+
},
193+
"expected_messages": null
93194
}
94195
]
95196
}

tests/types/bitbucket-test.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,68 @@
9191
"expected_output": "pkg:bitbucket/birkenfeld/pygments-main@244fd47e07d1014f0aed9c",
9292
"expected_failure": false,
9393
"expected_failure_reason": null
94+
},
95+
{
96+
"description": "Valid Bitbucket package with commit hash as version",
97+
"test_group": "base",
98+
"test_type": "validation",
99+
"input": {
100+
"type": "bitbucket",
101+
"namespace": "birkenfeld",
102+
"name": "pygments-main",
103+
"version": "244fd47e07d1014f0aed9c",
104+
"qualifiers": null,
105+
"subpath": null
106+
},
107+
"expected_messages": null
108+
},
109+
{
110+
"description": "Valid Bitbucket package with subpath",
111+
"test_group": "base",
112+
"test_type": "validation",
113+
"input": {
114+
"type": "bitbucket",
115+
"namespace": "teamname",
116+
"name": "repo-name",
117+
"version": "1.0.0",
118+
"qualifiers": null,
119+
"subpath": "src/main"
120+
},
121+
"expected_messages": null
122+
},
123+
{
124+
"description": "Valid Bitbucket package with qualifiers",
125+
"test_group": "base",
126+
"test_type": "validation",
127+
"input": {
128+
"type": "bitbucket",
129+
"namespace": "company",
130+
"name": "service",
131+
"version": "release-2024",
132+
"qualifiers": {
133+
"arch": "x86_64",
134+
"os": "linux"
135+
},
136+
"subpath": null
137+
},
138+
"expected_messages": ["Invalid qualifiers found: arch, os. Allowed qualifiers are: repository_url"]
139+
},
140+
{
141+
"description": "Valid Bitbucket package with qualifiers",
142+
"test_group": "advanced",
143+
"test_type": "validation",
144+
"input": {
145+
"type": "bitbucket",
146+
"namespace": "company",
147+
"name": "service",
148+
"version": "release-2024",
149+
"qualifiers": {
150+
"arch": "x86_64",
151+
"os": "linux"
152+
},
153+
"subpath": null
154+
},
155+
"expected_messages": null
94156
}
95157
]
96158
}

0 commit comments

Comments
 (0)