aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_string.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-05-23 20:07:36 -0700
committerJeremy Evans <code@jeremyevans.net>2019-06-01 10:50:06 -0700
commit4b9869e7e04cbfb581f6f1b21ae17b310135c5e2 (patch)
tree9baaa7e6e9efa28290e982dc641da13f05b8a6d0 /test/ruby/test_string.rb
parent09c09eb0db6c14c532935081c9b79d38fdc81f6b (diff)
downloadruby-4b9869e7e04cbfb581f6f1b21ae17b310135c5e2.tar.gz
Update String#crypt tests to work on OpenBSD
Skip the webrick httpauth tests that use crypt when testing on OpenBSD. Fixes [Bug #11363]
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r--test/ruby/test_string.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index f591f7ea9d..f0649b092f 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -646,9 +646,22 @@ CODE
assert_raise(ArgumentError) { "foo".count }
end
+ def crypt_supports_des_crypt?
+ /openbsd/ !~ RUBY_PLATFORM
+ end
+
def test_crypt
- assert_equal(S('aaGUC/JkO9/Sc'), S("mypassword").crypt(S("aa")))
- assert_not_equal(S('aaGUC/JkO9/Sc'), S("mypassword").crypt(S("ab")))
+ if crypt_supports_des_crypt?
+ pass = "aaGUC/JkO9/Sc"
+ good_salt = "aa"
+ bad_salt = "ab"
+ else
+ pass = "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2."
+ good_salt = "$2a$04$0WVaz0pV3jzfZ5G5tpmHWu"
+ bad_salt = "$2a$04$0WVaz0pV3jzfZ5G5tpmHXu"
+ end
+ assert_equal(S(pass), S("mypassword").crypt(S(good_salt)))
+ assert_not_equal(S(pass), S("mypassword").crypt(S(bad_salt)))
assert_raise(ArgumentError) {S("mypassword").crypt(S(""))}
assert_raise(ArgumentError) {S("mypassword").crypt(S("\0a"))}
assert_raise(ArgumentError) {S("mypassword").crypt(S("a\0"))}
@@ -660,9 +673,9 @@ CODE
end
@cls == String and
- assert_no_memory_leak([], 's = ""', "#{<<~"begin;"}\n#{<<~'end;'}")
+ assert_no_memory_leak([], "s = ''; salt_proc = proc{#{(crypt_supports_des_crypt? ? '..' : good_salt).inspect}}", "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
- 1000.times { s.crypt(-"..").clear }
+ 1000.times { s.crypt(-salt_proc.call).clear }
end;
end