From 5fef46ae0dedaab359f55bc3680f4278eb7da98d Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 26 Jul 2019 09:56:53 -0700 Subject: 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] --- test/test_securerandom.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test') 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 -- cgit v1.2.1