Skip to content

Commit

Permalink
Update outpack schema file. (#50)
Browse files Browse the repository at this point in the history
The new schema file adds requirements on the characters used by paths
found in the metadata. This aims at ensuring cross-platform
compatibility.
  • Loading branch information
plietar committed May 10, 2024
1 parent 7de87d8 commit 15f5a6a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/outpack/schema/outpack/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Imported from outpack

* Schema version 0.1.1
* Imported on 2023-12-04 11:53:24.971506
* From outpack @ 61bd5d84b0c737d3fb7dd24d45e4a117cd4e8bb5 (main)
* Imported on 2024-05-10 14:22:08.807105
* From outpack @ 5350c1766d95d1ef707552ed3275ed625a419e0c (main)

Do not make changes to files here, they will be overwritten
Run ./scripts/update_schemas to update
6 changes: 3 additions & 3 deletions src/outpack/schema/outpack/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"properties": {
"path": {
"description": "The path of the file",
"type": "string"
"$ref": "relative-path.json"
},
"hash": {
"$ref": "hash.json"
Expand Down Expand Up @@ -93,11 +93,11 @@
"properties": {
"here": {
"description": "The path of the file in this packet",
"type": "string"
"$ref": "relative-path.json"
},
"there": {
"description": "The path of the file within the upstream packet",
"type": "string"
"$ref": "relative-path.json"
}
},
"required": ["here", "there"]
Expand Down
9 changes: 9 additions & 0 deletions src/outpack/schema/outpack/relative-path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "File path",
"description": "A relative cross-platform file path",
"version": "0.1.1",

"type": "string",
"pattern": "^([^<>:\"/\\\\|?*\\x00-\\x1f]+/)*[^<>:\"/\\\\|?*\\x00-\\x1f]+$"
}
26 changes: 26 additions & 0 deletions tests/test_packet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

import pytest
from jsonschema.exceptions import ValidationError

from outpack.init import outpack_init
from outpack.metadata import PacketDependsPath
Expand Down Expand Up @@ -273,3 +276,26 @@ def test_can_search_with_this_parameter(tmp_path):
with create_packet(root, "downstream", parameters={"x": 2}) as p:
result = p.use_dependency(query)
assert result.id == id2


@pytest.mark.skipif(
os.name == "nt",
reason="This test uses filenames that aren't valid on Windows",
)
def test_cannot_create_packet_with_invalid_filename(tmp_path):
root = create_temporary_root(tmp_path)

# These are legal filenames on POSIX, but not on Windows. If we allowed
# these in packets we would not be able to pull the packets on a Windows
# machine.
with pytest.raises(ValidationError):
with create_packet(root, "data") as p:
(p.path / R"bad\file\name").touch()

with pytest.raises(ValidationError):
with create_packet(root, "data") as p:
(p.path / "bad<file>name").touch()

with pytest.raises(ValidationError):
with create_packet(root, "data") as p:
(p.path / "bad\x01file\x01name").touch()

0 comments on commit 15f5a6a

Please sign in to comment.