2017-07-09 12:06:36 +00:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 13:39:13 +00:00
|
|
|
|
2018-09-30 00:50:43 +00:00
|
|
|
require_relative "abstract_unit"
|
2016-08-06 16:03:25 +00:00
|
|
|
require "active_support/security_utils"
|
2014-10-23 13:56:48 +00:00
|
|
|
|
|
|
|
class SecurityUtilsTest < ActiveSupport::TestCase
|
|
|
|
def test_secure_compare_should_perform_string_comparison
|
2016-08-06 16:03:25 +00:00
|
|
|
assert ActiveSupport::SecurityUtils.secure_compare("a", "a")
|
2017-01-31 11:41:14 +00:00
|
|
|
assert_not ActiveSupport::SecurityUtils.secure_compare("a", "b")
|
|
|
|
end
|
|
|
|
|
2021-04-02 16:45:29 +00:00
|
|
|
def test_secure_compare_return_false_on_bytesize_mismatch
|
|
|
|
assert_not ActiveSupport::SecurityUtils.secure_compare("a", "\u{ff41}")
|
|
|
|
end
|
|
|
|
|
2016-04-11 21:11:06 +00:00
|
|
|
def test_fixed_length_secure_compare_should_perform_string_comparison
|
|
|
|
assert ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "a")
|
2018-04-17 22:21:34 +00:00
|
|
|
assert_not ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "b")
|
2016-04-11 21:11:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_fixed_length_secure_compare_raise_on_length_mismatch
|
|
|
|
assert_raises(ArgumentError, "string length mismatch.") do
|
|
|
|
ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "ab")
|
|
|
|
end
|
|
|
|
end
|
2014-10-23 13:56:48 +00:00
|
|
|
end
|