Skip to content

Commit 5a5c78c

Browse files
authored
Merge pull request #118 from TG1999/add_validation_tests
Add validation tests
2 parents 9b27957 + 5aee9f6 commit 5a5c78c

33 files changed

+1470
-2
lines changed

schemas/purl-test.schema.json

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,34 @@
6868
}
6969
}
7070
},
71+
"purl_validation_message": {
72+
"title": "PURL validation message",
73+
"description": "Validation severity and message to use as a test expected output when validating a PURL.",
74+
"type": "object",
75+
"additionalProperties": false,
76+
"properties": {
77+
"severity": {
78+
"title": "Validation severity",
79+
"description": "Validation severity.",
80+
"type": "string",
81+
"enum": [
82+
"info",
83+
"warning",
84+
"error"
85+
],
86+
"meta:enum": {
87+
"info": "Informational validation message",
88+
"warning": "Warning validation message",
89+
"error": "Error validation message"
90+
}
91+
},
92+
"message": {
93+
"title": "Validation message",
94+
"description": "Validation message.",
95+
"type": "string"
96+
}
97+
}
98+
},
7199
"purl_test": {
72100
"title": "PURL test",
73101
"description": "A PURL test with input and expected output.",
@@ -104,12 +132,14 @@
104132
"enum": [
105133
"build",
106134
"parse",
107-
"roundtrip"
135+
"roundtrip",
136+
"validation"
108137
],
109138
"meta:enum": {
110139
"build": "A PURL building test from decoded components to a canonical PURL string.",
111140
"parse": "A PURL building test from decoded components to a canonical PURL string.",
112-
"roundtrip": "A PURL roundtrip test, parsing then building back a PURL from a canonical string input."
141+
"roundtrip": "A PURL roundtrip test, parsing then building back a PURL from a canonical string input.",
142+
"validation": "A PURL validation test, checking if a PURL follows all the rules for a particular ecosystem."
113143
}
114144
},
115145
"expected_failure": {
@@ -284,6 +314,39 @@
284314
"expected_failure_reason"
285315
]
286316
}
317+
},
318+
{
319+
"if": {
320+
"properties": {
321+
"test_type": {
322+
"const": "validation"
323+
}
324+
},
325+
"required": [
326+
"test_type"
327+
]
328+
},
329+
"then": {
330+
"properties": {
331+
"input": {
332+
"title": "Input test PURL",
333+
"description": "A PURL string to use as a test input (canonical or not).",
334+
"type": "string"
335+
},
336+
"expected_output": {
337+
"title": "Expected validation messages and severities",
338+
"description": "List of validation objects with message and severity expected for this test. Can be an empty list.",
339+
"type": "array",
340+
"items": {
341+
"$ref": "#/definitions/purl_validation_message"
342+
}
343+
}
344+
},
345+
"required": [
346+
"input",
347+
"expected_output"
348+
]
349+
}
287350
}
288351
]
289352
}

tests/types/alpm-test.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,58 @@
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": "pkg:alpm/arch/pacman@6.0.1-1?arch=x86_64",
144+
"expected_output": []
145+
},
146+
{
147+
"description": "alpm package with uppercase nmamespace",
148+
"test_group": "base",
149+
"test_type": "validation",
150+
"input": "pkg:alpm/Arch/pacman@6.0.1-1?arch=x86_64",
151+
"expected_output": [
152+
{
153+
"severity": "warning",
154+
"message": "Namespace is not lowercased for purl type: 'alpm'"
155+
}
156+
]
157+
},
158+
{
159+
"description": "alpm package with uppercase nmamespace (advanced)",
160+
"test_group": "advanced",
161+
"test_type": "validation",
162+
"input": "pkg:alpm/Arch/pacman@6.0.1-1?arch=x86_64",
163+
"expected_output": []
164+
},
165+
{
166+
"description": "Valid alpm package with 'any' arch",
167+
"test_group": "base",
168+
"test_type": "validation",
169+
"input": "pkg:alpm/arch/python-pip@21.0-1?arch=any",
170+
"expected_output": []
171+
},
172+
{
173+
"description": "Valid alpm package with epoch in version",
174+
"test_group": "advanced",
175+
"test_type": "validation",
176+
"input": "pkg:alpm/arch/containers-common@1:0.47.4-4?arch=x86_64",
177+
"expected_output": []
178+
},
179+
{
180+
"description": "alpm package missing namespace",
181+
"test_group": "base",
182+
"test_type": "validation",
183+
"input": "pkg:alpm/pacman@6.0.1-1?arch=x86_64",
184+
"expected_output": [
185+
{
186+
"severity": "error",
187+
"message": "Namespace is required for purl type: 'alpm'"
188+
}
189+
]
138190
}
139191
]
140192
}

tests/types/apk-test.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,62 @@
9090
"expected_output": "pkg:apk/alpine/apk@2.12.9-r3?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": "pkg:apk/alpine/curl@7.83.0-r0?arch=x86",
99+
"expected_output": []
100+
},
101+
{
102+
"description": "Valid apk package with higher version and arch qualifier",
103+
"test_group": "base",
104+
"test_type": "validation",
105+
"input": "pkg:apk/alpine/apk@2.12.9-r3?arch=x86",
106+
"expected_output": []
107+
},
108+
{
109+
"description": "Valid apk package with openwrt vendor",
110+
"test_group": "advanced",
111+
"test_type": "validation",
112+
"input": "pkg:apk/openwrt/busybox@1.35.0-r5?arch=mips",
113+
"expected_output": []
114+
},
115+
{
116+
"description": "apk package missing namespace",
117+
"test_group": "base",
118+
"test_type": "validation",
119+
"input": "pkg:apk/curl@7.83.0-r0?arch=x86",
120+
"expected_output": [
121+
{
122+
"severity": "error",
123+
"message": "Namespace is required for purl type: 'apk'"
124+
}
125+
]
126+
},
127+
{
128+
"description": "apk package with uppercase namespace and name",
129+
"test_group": "base",
130+
"test_type": "validation",
131+
"input": "pkg:apk/FOO/BAR@7.83.0-r0?arch=x86",
132+
"expected_output": [
133+
{
134+
"severity": "warning",
135+
"message": "Namespace is not lowercased for purl type: 'apk'"
136+
},
137+
{
138+
"severity": "warning",
139+
"message": "Name is not lowercased for purl type: 'apk'"
140+
}
141+
]
142+
},
143+
{
144+
"description": "apk package with uppercase namespace and name (advanced)",
145+
"test_group": "advanced",
146+
"test_type": "validation",
147+
"input": "pkg:apk/FOO/BAR@7.83.0-r0?arch=x86",
148+
"expected_output": []
93149
}
94150
]
95151
}

tests/types/bitbucket-test.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,39 @@
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": "pkg:bitbucket/birkenfeld/pygments-main@244fd47e07d1014f0aed9c",
100+
"expected_output": []
101+
},
102+
{
103+
"description": "Valid Bitbucket package with subpath",
104+
"test_group": "base",
105+
"test_type": "validation",
106+
"input": "pkg:bitbucket/teamname/repo-name@1.0.0#src/main",
107+
"expected_output": []
108+
},
109+
{
110+
"description": "Valid Bitbucket package with qualifiers",
111+
"test_group": "base",
112+
"test_type": "validation",
113+
"input": "pkg:bitbucket/company/service@release-2024?arch=x86_64&os=linux",
114+
"expected_output": [
115+
{
116+
"severity": "info",
117+
"message": "Invalid qualifiers found: arch, os. Allowed qualifiers are: repository_url"
118+
}
119+
]
120+
},
121+
{
122+
"description": "Valid Bitbucket package with qualifiers",
123+
"test_group": "advanced",
124+
"test_type": "validation",
125+
"input": "pkg:bitbucket/company/service@release-2024?arch=x86_64&os=linux",
126+
"expected_output": []
94127
}
95128
]
96129
}

tests/types/bitnami-test.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,34 @@
184184
"expected_output": "pkg:bitnami/wordpress@6.2.0?arch=arm64&distro=photon-4",
185185
"expected_failure": false,
186186
"expected_failure_reason": null
187+
},
188+
{
189+
"description": "Valid Bitnami package without version",
190+
"test_group": "base",
191+
"test_type": "validation",
192+
"input": "pkg:bitnami/wordpress?distro=debian-12",
193+
"expected_output": []
194+
},
195+
{
196+
"description": "Valid Bitnami package with version and distro",
197+
"test_group": "base",
198+
"test_type": "validation",
199+
"input": "pkg:bitnami/wordpress@6.2.0?distro=debian-12",
200+
"expected_output": []
201+
},
202+
{
203+
"description": "Valid Bitnami package with arch and distro",
204+
"test_group": "advanced",
205+
"test_type": "validation",
206+
"input": "pkg:bitnami/wordpress@6.2.0?arch=arm64&distro=debian-12",
207+
"expected_output": []
208+
},
209+
{
210+
"description": "Valid Bitnami package with another distro",
211+
"test_group": "advanced",
212+
"test_type": "validation",
213+
"input": "pkg:bitnami/wordpress@6.2.0?arch=arm64&distro=photon-4",
214+
"expected_output": []
187215
}
188216
]
189217
}

tests/types/cargo-test.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,39 @@
123123
"expected_output": "pkg:cargo/structopt@0.3.11",
124124
"expected_failure": false,
125125
"expected_failure_reason": null
126+
},
127+
{
128+
"description": "Valid Cargo package with name and version",
129+
"test_group": "base",
130+
"test_type": "validation",
131+
"input": "pkg:cargo/rand@0.7.2",
132+
"expected_output": []
133+
},
134+
{
135+
"description": "Valid Cargo package with another example",
136+
"test_group": "base",
137+
"test_type": "validation",
138+
"input": "pkg:cargo/clap@2.33.0",
139+
"expected_output": []
140+
},
141+
{
142+
"description": "Cargo package without version",
143+
"test_group": "advanced",
144+
"test_type": "validation",
145+
"input": "pkg:cargo/structopt",
146+
"expected_output": []
147+
},
148+
{
149+
"description": "Cargo package with namespace (not allowed)",
150+
"test_group": "advanced",
151+
"test_type": "validation",
152+
"input": "pkg:cargo/rustlang/serde@1.0.0",
153+
"expected_output": [
154+
{
155+
"severity": "error",
156+
"message": "Namespace is prohibited for purl type: 'cargo'"
157+
}
158+
]
126159
}
127160
]
128161
}

tests/types/cocoapods-test.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@
164164
"expected_output": "pkg:cocoapods/GoogleUtilities@7.5.2#NSData%2Bzlib",
165165
"expected_failure": false,
166166
"expected_failure_reason": null
167+
},
168+
{
169+
"description": "Valid CocoaPods package with name and version",
170+
"test_group": "base",
171+
"test_type": "validation",
172+
"input": "pkg:cocoapods/AFNetworking@4.0.1",
173+
"expected_output": []
174+
},
175+
{
176+
"description": "Valid CocoaPods package with subspec in subpath",
177+
"test_group": "base",
178+
"test_type": "validation",
179+
"input": "pkg:cocoapods/GoogleUtilities@7.5.2#NSData+zlib",
180+
"expected_output": []
181+
},
182+
{
183+
"description": "CocoaPods package without version",
184+
"test_group": "advanced",
185+
"test_type": "validation",
186+
"input": "pkg:cocoapods/MapsIndoors",
187+
"expected_output": []
188+
},
189+
{
190+
"description": "CocoaPods package with namespace (not allowed)",
191+
"test_group": "advanced",
192+
"test_type": "validation",
193+
"input": "pkg:cocoapods/apple/ShareKit@2.0#Twitter",
194+
"expected_output": [
195+
{
196+
"severity": "error",
197+
"message": "Namespace is prohibited for purl type: 'cocoapods'"
198+
}
199+
]
167200
}
168201
]
169202
}

0 commit comments

Comments
 (0)