mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_m17n_comb.rb: test_str_crypt split into strict
and non-strict versions to allow masking out non-strict when glibc version cannot be determined (#11045). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4bd7276247
commit
2d1f3ed151
1 changed files with 32 additions and 17 deletions
|
@ -743,28 +743,43 @@ class TestM17NComb < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_str_crypt
|
# glibc 2.16 or later denies salt contained other than [0-9A-Za-z./] #7312
|
||||||
strict_crypt = nil
|
# we use this check to test strict and non-strict behavior separately #11045
|
||||||
# glibc 2.16 or later denies salt contained other than [0-9A-Za-z./] #7312
|
strict_crypt = if defined? Etc::CS_GNU_LIBC_VERSION
|
||||||
if defined? Etc::CS_GNU_LIBC_VERSION
|
glibcver = Etc.confstr(Etc::CS_GNU_LIBC_VERSION).scan(/\d+/).map(&:to_i)
|
||||||
glibcver = Etc.confstr(Etc::CS_GNU_LIBC_VERSION).scan(/\d+/).map(&:to_i)
|
(glibcver <=> [2, 16]) >= 0
|
||||||
strict_crypt = (glibcver <=> [2, 16]) >= 0
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
def test_str_crypt
|
||||||
combination(STRINGS, STRINGS) {|str, salt|
|
combination(STRINGS, STRINGS) {|str, salt|
|
||||||
if strict_crypt
|
# skip input other than [0-9A-Za-z./] to confirm strict behavior
|
||||||
next unless salt.ascii_only? && /\A[0-9a-zA-Z.\/]+\z/ =~ salt
|
next unless salt.ascii_only? && /\A[0-9a-zA-Z.\/]+\z/ =~ salt
|
||||||
end
|
|
||||||
if b(salt).length < 2
|
confirm_crypt_result(str, salt)
|
||||||
assert_raise(ArgumentError) { str.crypt(salt) }
|
|
||||||
next
|
|
||||||
end
|
|
||||||
t = str.crypt(salt)
|
|
||||||
assert_equal(b(str).crypt(b(salt)), t, "#{encdump(str)}.crypt(#{encdump(salt)})")
|
|
||||||
assert_encoding('ASCII-8BIT', t.encoding)
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !strict_crypt
|
||||||
|
def test_str_crypt_nonstrict
|
||||||
|
combination(STRINGS, STRINGS) {|str, salt|
|
||||||
|
# only test input other than [0-9A-Za-z./] to confirm non-strict behavior
|
||||||
|
next if salt.ascii_only? && /\A[0-9a-zA-Z.\/]+\z/ =~ salt
|
||||||
|
|
||||||
|
confirm_crypt_result(str, salt)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private def confirm_crypt_result(str, salt)
|
||||||
|
if b(salt).length < 2
|
||||||
|
assert_raise(ArgumentError) { str.crypt(salt) }
|
||||||
|
return
|
||||||
|
end
|
||||||
|
t = str.crypt(salt)
|
||||||
|
assert_equal(b(str).crypt(b(salt)), t, "#{encdump(str)}.crypt(#{encdump(salt)})")
|
||||||
|
assert_encoding('ASCII-8BIT', t.encoding)
|
||||||
|
end
|
||||||
|
|
||||||
def test_str_delete
|
def test_str_delete
|
||||||
combination(STRINGS, STRINGS) {|s1, s2|
|
combination(STRINGS, STRINGS) {|s1, s2|
|
||||||
if s1.empty?
|
if s1.empty?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue