t0013: add a basic sha1 collision detection test
authorJeff King <peff@peff.net>
Thu, 16 Mar 2017 22:09:36 +0000 (18:09 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Mar 2017 17:40:25 +0000 (10:40 -0700)
We don't actually have a Git-object collision, so the best
we can do is to run one of the shattered PDFs through
test-sha1. This should trigger the collision check and die.

In a sense this isn't really checking anything that the
upstream sha1collisiondetection project doesn't cover
already. But it at least makes sure that our build correctly
uses the library.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
t/t0013-sha1dc.sh [new file with mode: 0755]
t/t0013/shattered-1.pdf [new file with mode: 0644]
index 05a96d717749abc8e3429bda4dbf0c46888d229f..fc9d89498b47d9ca7ae07b2fdef7563d95a67465 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2236,6 +2236,7 @@ GIT-BUILD-OPTIONS: FORCE
        @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+
        @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
        @echo PAGER_ENV=\''$(subst ','\'',$(subst ','\'',$(PAGER_ENV)))'\' >>$@+
+       @echo DC_SHA1=\''$(subst ','\'',$(subst ','\'',$(DC_SHA1)))'\' >>$@+
 ifdef TEST_OUTPUT_DIRECTORY
        @echo TEST_OUTPUT_DIRECTORY=\''$(subst ','\'',$(subst ','\'',$(TEST_OUTPUT_DIRECTORY)))'\' >>$@+
 endif
diff --git a/t/t0013-sha1dc.sh b/t/t0013-sha1dc.sh
new file mode 100755 (executable)
index 0000000..6d655cb
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+test_description='test sha1 collision detection'
+. ./test-lib.sh
+TEST_DATA="$TEST_DIRECTORY/t0013"
+
+if test -z "$DC_SHA1"
+then
+       skip_all='skipping sha1 collision tests, DC_SHA1 not set'
+       test_done
+fi
+
+test_expect_success 'test-sha1 detects shattered pdf' '
+       test_must_fail test-sha1 <"$TEST_DATA/shattered-1.pdf" 2>err &&
+       test_i18ngrep collision err &&
+       grep 38762cf7f55934b34d179ae6a4c80cadccbb7f0a err
+'
+
+test_done
diff --git a/t/t0013/shattered-1.pdf b/t/t0013/shattered-1.pdf
new file mode 100644 (file)
index 0000000..ba9aaa1
Binary files /dev/null and b/t/t0013/shattered-1.pdf differ