about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rwxr-xr-xt/bin/sha1sum.rb23
-rwxr-xr-xt/t0100-rack-input-hammer.sh7
-rw-r--r--t/test-lib.sh10
3 files changed, 39 insertions, 1 deletions
diff --git a/t/bin/sha1sum.rb b/t/bin/sha1sum.rb
new file mode 100755
index 0000000..b602e79
--- /dev/null
+++ b/t/bin/sha1sum.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+# -*- encoding: binary -*-
+
+# Reads from stdin and outputs the SHA1 hex digest of the input this is
+# ONLY used as a last resort, our test code will try to use sha1sum(1),
+# openssl(1), or gsha1sum(1) before falling back to using this.  We try
+# all options first because we have a strong and healthy distrust of our
+# Ruby abilities in general, and *especially* when it comes to
+# understanding (and trusting the implementation of) Ruby 1.9 encoding.
+
+require 'digest/sha1'
+$stdout.sync = $stderr.sync = true
+$stdout.binmode
+$stdin.binmode
+bs = 16384
+digest = Digest::SHA1.new
+if buf = $stdin.read(bs)
+  begin
+    digest.update(buf)
+  end while $stdin.read(bs, buf)
+end
+
+$stdout.syswrite("#{digest.hexdigest}\n")
diff --git a/t/t0100-rack-input-hammer.sh b/t/t0100-rack-input-hammer.sh
index c333883..c871913 100755
--- a/t/t0100-rack-input-hammer.sh
+++ b/t/t0100-rack-input-hammer.sh
@@ -2,6 +2,11 @@ nr_client=${nr_client-4}
 . ./test-lib.sh
 test -r random_blob || die "random_blob required, run with 'make $0'"
 
+# basically we don't trust our own implementation of content-md5-put
+# nor our Ruby 1.9 knowledge nor proper use of encodings in Ruby.
+# So we try to use things like curl and sha1sum that are implemented
+# without the Ruby interpreter to validate our own Ruby internals.
+
 t_plan 7 "concurrent rack.input hammer stress test"
 
 t_begin "setup and startup" && {
@@ -35,7 +40,7 @@ t_begin "all responses identical" && {
 }
 
 t_begin "sha1 matches on-disk sha1" && {
-        blob_sha1=$( expr "$(sha1sum < random_blob)" : '\([a-f0-9]\{40\}\)')
+        blob_sha1=$(rsha1 < random_blob)
         t_info blob_sha1=$blob_sha1
         test x"$blob_sha1" = x"$(sort < $curl_out | uniq)"
 }
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9e67d1d..d28eaa0 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -134,6 +134,16 @@ rainbows_wait_start () {
         rainbows_pid=$(cat $pid)
 }
 
+rsha1 () {
+        _cmd="$(which sha1sum 2>/dev/null || :)"
+        test -n "$_cmd" || _cmd="$(which openssl 2>/dev/null || :) sha1"
+        test "$_cmd" != " sha1" || _cmd="$(which gsha1sum 2>/dev/null || :)"
+
+        # last resort, see comments in sha1sum.rb for reasoning
+        test -n "$_cmd" || _cmd=sha1sum.rb
+        expr "$($_cmd < random_blob)" : '\([a-f0-9]\{40\}\)'
+}
+
 case $model in
 Rev) require_check rev Rev::VERSION ;;
 Revactor) require_check revactor Revactor::VERSION ;;