1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Test SecureRandom.uuid format

SecureRandom uses v4 UUIDs, which are completely random except for
6 bits, 4 in the version field and 2 in the clk_seq_hi_res field.
Add a test that those bit patterns are set correctly for v4 UUIDs,
per RFC 4122 section 4.4.

Fixes [Bug #13603]
This commit is contained in:
Jeremy Evans 2019-07-26 09:56:53 -07:00
parent 4f978a1c99
commit 5fef46ae0d

View file

@ -140,6 +140,11 @@ end
def test_uuid
uuid = @it.uuid
assert_equal(36, uuid.size)
# Check time_hi_and_version and clock_seq_hi_res bits (RFC 4122 4.4)
assert_equal('4', uuid[14])
assert_include(%w'8 9 a b', uuid[19])
assert_match(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/, uuid)
end