Skip to content

Commit

Permalink
Add purl
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 18, 2024
1 parent 15e2b7e commit 639cee5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
15 changes: 15 additions & 0 deletions schema/v2/purl.schema.json
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]"
]
}
54 changes: 49 additions & 5 deletions tests/v2_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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),
Expand All @@ -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(())
}

0 comments on commit 639cee5

Please sign in to comment.