2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2016-08-06 12:03:25 -04:00
|
|
|
require "active_support/security_utils"
|
2014-10-23 09:56:48 -04:00
|
|
|
|
|
|
|
class SecurityUtilsTest < ActiveSupport::TestCase
|
|
|
|
def test_secure_compare_should_perform_string_comparison
|
2016-08-06 12:03:25 -04:00
|
|
|
assert ActiveSupport::SecurityUtils.secure_compare("a", "a")
|
2017-01-31 06:41:14 -05:00
|
|
|
assert_not ActiveSupport::SecurityUtils.secure_compare("a", "b")
|
|
|
|
end
|
|
|
|
|
2016-04-11 17:11:06 -04:00
|
|
|
def test_fixed_length_secure_compare_should_perform_string_comparison
|
|
|
|
assert ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "a")
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "b")
|
2016-04-11 17:11:06 -04: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 09:56:48 -04:00
|
|
|
end
|