diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-26 09:56:53 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-07-26 09:56:53 -0700 |
commit | 5fef46ae0dedaab359f55bc3680f4278eb7da98d (patch) | |
tree | ac85ea50c8998a72de1679421b0629f8b0cf4ff3 /test | |
parent | 4f978a1c995ec565f72095415f4d2fb298188fae (diff) | |
download | ruby-5fef46ae0dedaab359f55bc3680f4278eb7da98d.tar.gz |
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]
Diffstat (limited to 'test')
-rw-r--r-- | test/test_securerandom.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/test/test_securerandom.rb b/test/test_securerandom.rb index 1bc35f91f8..7c8640fce4 100644 --- a/test/test_securerandom.rb +++ b/test/test_securerandom.rb @@ -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 |