Skip to content

tests for the "uuid" format #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/draft2019-09/format.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,5 +610,41 @@
"valid": true
}
]
},
{
"description": "validation of UUIDs",
"schema": { "format": "uuid" },
"tests": [
{
"description": "ignores integers",
"data": 12,
"valid": true
},
{
"description": "ignores floats",
"data": 13.7,
"valid": true
},
{
"description": "ignores objects",
"data": {},
"valid": true
},
{
"description": "ignores arrays",
"data": [],
"valid": true
},
{
"description": "ignores booleans",
"data": false,
"valid": true
},
{
"description": "ignores null",
"data": null,
"valid": true
}
]
}
]
70 changes: 70 additions & 0 deletions tests/draft2019-09/optional/format/uuid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[
{
"description": "uuid format",
"schema": {
"format": "uuid"
},
"tests": [
{
"description": "all upper-case",
"data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380",
"valid": true
},
{
"description": "all lower-case",
"data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380",
"valid": true
},
{
"description": "mixed case",
"data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380",
"valid": true
},
{
"description": "all zeroes is valid",
"data": "00000000-0000-0000-0000-000000000000",
"valid": true
},
{
"description": "wrong length",
"data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638",
"valid": false
},
{
"description": "missing section",
"data": "2eb8aa08-aa98-11ea-73b441d16380",
"valid": false
},
{
"description": "bad characters (not hex)",
"data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380",
"valid": false
},
{
"description": "no dashes",
"data": "2eb8aa08aa9811eab4aa73b441d16380",
"valid": false
},
{
"description": "valid version 4",
"data": "98d80576-482e-427f-8434-7f86890ab222",
"valid": true
},
{
"description": "valid version 5",
"data": "99c17cbb-656f-564a-940f-1a4568f03487",
"valid": true
},
{
"description": "hypothetical version 6",
"data": "99c17cbb-656f-664a-940f-1a4568f03487",
"valid": true
},
{
"description": "hypothetical version 15",
"data": "99c17cbb-656f-f64a-940f-1a4568f03487",
"valid": true
}
]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also also probably good to have a UUID 6 (i.e. by inserting 6 where the version goes) and assert it's invalid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. I've seen some regexes that are tighter and only accept the current versions, but indeed the RFC says

Apart from determining whether the timestamp portion of the UUID is in the future and therefore not yet assignable, there is no mechanism for determining whether a UUID is 'valid'.

..so these implementations are being needlessly (and invalidly) too strict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid, or valid? IMO we should accept future versions as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw I just tried a "future version" uuid in PostgreSQL against its uuid data type and it accepted version 6 and version 15 (f).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, yep good catch (I didn't go read the RFC first, so yeah seems valid is the right behavior)!

]