Skip to content

Commit

Permalink
More liberal verification of uuid wannabe structs
Browse files Browse the repository at this point in the history
Change-Id: Ic5e999cb8432341b8d6f9510df951de87d00a583
  • Loading branch information
9seconds committed May 12, 2017
1 parent 4d47810 commit a924c3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 1 addition & 9 deletions backend/api/decapod_api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,7 @@
# This is real world UUID, not RFC like.
"dmidecode_uuid": {
"type": "string",
"pattern": (
"^"
"[0-9a-fA-F]{8}-"
"[0-9a-fA-F]{4}-"
"[0-9a-fA-F]{4}-"
"[0-9a-fA-F]{4}-"
"[0-9a-fA-F]{12}"
"$"
)
"pattern": r"^[0-9a-fA-F\-]{32,38}$"
},
"dmidecode_uuid_array": {
"type": "array",
Expand Down
18 changes: 18 additions & 0 deletions tests/api/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ def test_require_schema_uuid_ok():
function(mck)


@pytest.mark.parametrize("version", (
# these were taken from complains on failed discovery
"04D192B0-7F16-4071-80B5-FD55F7A57DB1",
"E840B5D9-B4A3-414E-A75F-E27779911998"
))
def test_known_funky_uuids(version):
schema = {
"data": {"$ref": "#/definitions/uuid4"}
}
schema = validators.create_data_schema(schema)
function = validators.require_schema(schema)(dummy_function)

mck = mock.MagicMock()
mck.request_json = {"data": pytest.faux.gen_uuid()}

function(mck)


@pytest.mark.parametrize("wrap_into_array", (True, False))
@pytest.mark.parametrize("value", (
"", 0, 1, -1, {}, None, 1.0, "1",
Expand Down

0 comments on commit a924c3c

Please sign in to comment.