-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://pgxn.org/meta/v2/purl.schema.json", | ||
"title": "Path", | ||
"description": "A *purl* is specifies a valid package in the format defined by the [purl spec](https://github.com/package-url/purl-spec/blob/master/PURL-SPECIFICATION.rst). All known [purl Types](https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst) **MAY** be used, as well as `pgxn` for PGXN packages and `postgres` for PostgreSQL core [contrib](https://www.postgresql.org/docs/current/contrib.html) or development packages. Versions appearing after a `@` are valid but ignored.", | ||
"type": "string", | ||
"format": "uri", | ||
"pattern": "^pkg:[a-zA-Z.+-][a-zA-Z0-9.+-]+/[^@?#]+(?:@[^?#]+)?(?:\\?[^#]+)?(?:#\\S+)?$", | ||
"examples": [ | ||
"pkg:pgxn/pgtap", | ||
"pkg:postgres/pg_regress", | ||
"pkg:generic/python3", | ||
"pkg:pypi/[email protected]" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,8 +196,8 @@ fn test_v2_license() -> Result<(), Box<dyn Error>> { | |
let id = id_for(SCHEMA_VERSION, "license"); | ||
let idx = compiler.compile(&id, &mut schemas)?; | ||
|
||
// Test valid relative paths. | ||
for valid_path in [ | ||
// Test valid relative licenses. | ||
for valid_license in [ | ||
json!("MIT"), | ||
json!("PostgreSQL"), | ||
json!("Apache-2.0 OR MIT"), | ||
|
@@ -214,12 +214,12 @@ fn test_v2_license() -> Result<(), Box<dyn Error>> { | |
json!("LicenseRef-MIT-Style-1"), | ||
json!("DocumentRef-spdx-tool-1.2:LicenseRef-MIT-Style-2"), | ||
] { | ||
if let Err(e) = schemas.validate(&valid_path, idx) { | ||
panic!("path pattern {} failed: {e}", valid_path); | ||
if let Err(e) = schemas.validate(&valid_license, idx) { | ||
panic!("path pattern {} failed: {e}", valid_license); | ||
} | ||
} | ||
|
||
// Test invalid paths. | ||
// Test invalid licenses. | ||
for invalid_license in [ | ||
json!(""), | ||
json!(null), | ||
|
@@ -236,3 +236,47 @@ fn test_v2_license() -> Result<(), Box<dyn Error>> { | |
} | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_v2_purl() -> Result<(), Box<dyn Error>> { | ||
// Load the schemas and compile the semver schema. | ||
let mut compiler = new_compiler("schema/v2")?; | ||
let mut schemas = Schemas::new(); | ||
let id = id_for(SCHEMA_VERSION, "purl"); | ||
let idx = compiler.compile(&id, &mut schemas)?; | ||
|
||
// Test valid relative purls. | ||
for valid_purl in [ | ||
json!("pkg:pgxn/pgtap"), | ||
json!("pkg:postgres/pg_regress"), | ||
json!("pkg:generic/python3"), | ||
json!("pkg:pypi/[email protected]"), | ||
json!("pkg:type/namespace/name"), | ||
json!("pkg:type/namespace/name@version"), | ||
json!("pkg:type/namespace/name@version?qualifiers"), | ||
json!("pkg:type/namespace/name@version?qualifiers#subpath"), | ||
] { | ||
if let Err(e) = schemas.validate(&valid_purl, idx) { | ||
panic!("path pattern {} failed: {e}", valid_purl); | ||
} | ||
} | ||
|
||
// Test invalid purls. | ||
for invalid_purl in [ | ||
json!("http://example.com"), | ||
json!("https://example.com"), | ||
json!("mailto:[email protected]"), | ||
json!(null), | ||
json!("0"), | ||
json!(0), | ||
json!("\n\t"), | ||
json!("()"), | ||
json!("AND"), | ||
json!("OR"), | ||
] { | ||
if schemas.validate(&invalid_purl, idx).is_ok() { | ||
panic!("{} unexpectedly passed!", invalid_purl) | ||
} | ||
} | ||
Ok(()) | ||
} |