1#!/bin/sh
23
test_description='pull signature verification tests'
4. ./test-lib.sh
5. "$TEST_DIRECTORY/lib-gpg.sh"
67
test_expect_success GPG 'create repositories with signed commits' '
8echo 1 >a && git add a &&
9test_tick && git commit -m initial &&
10git tag initial &&
1112
git clone . signed &&
13(
14cd signed &&
15echo 2 >b && git add b &&
16test_tick && git commit -S -m "signed"
17) &&
1819
git clone . unsigned &&
20(
21cd unsigned &&
22echo 3 >c && git add c &&
23test_tick && git commit -m "unsigned"
24) &&
2526
git clone . bad &&
27(
28cd bad &&
29echo 4 >d && git add d &&
30test_tick && git commit -S -m "bad" &&
31git cat-file commit HEAD >raw &&
32sed -e "s/^bad/forged bad/" raw >forged &&
33git hash-object -w -t commit forged >forged.commit &&
34git checkout $(cat forged.commit)
35) &&
3637
git clone . untrusted &&
38(
39cd untrusted &&
40echo 5 >e && git add e &&
41test_tick && git commit -SB7227189 -m "untrusted"
42)
43'
4445
test_expect_success GPG 'pull unsigned commit with --verify-signatures' '
46test_when_finished "git reset --hard && git checkout initial" &&
47test_must_fail git pull --ff-only --verify-signatures unsigned 2>pullerror &&
48test_i18ngrep "does not have a GPG signature" pullerror
49'
5051
test_expect_success GPG 'pull commit with bad signature with --verify-signatures' '
52test_when_finished "git reset --hard && git checkout initial" &&
53test_must_fail git pull --ff-only --verify-signatures bad 2>pullerror &&
54test_i18ngrep "has a bad GPG signature" pullerror
55'
5657
test_expect_success GPG 'pull commit with untrusted signature with --verify-signatures' '
58test_when_finished "git reset --hard && git checkout initial" &&
59test_must_fail git pull --ff-only --verify-signatures untrusted 2>pullerror &&
60test_i18ngrep "has an untrusted GPG signature" pullerror
61'
6263
test_expect_success GPG 'pull signed commit with --verify-signatures' '
64test_when_finished "git reset --hard && git checkout initial" &&
65git pull --verify-signatures signed >pulloutput &&
66test_i18ngrep "has a good GPG signature" pulloutput
67'
6869
test_expect_success GPG 'pull commit with bad signature without verification' '
70test_when_finished "git reset --hard && git checkout initial" &&
71git pull --ff-only bad 2>pullerror
72'
7374
test_expect_success GPG 'pull commit with bad signature with --no-verify-signatures' '
75test_when_finished "git reset --hard && git checkout initial" &&
76test_config merge.verifySignatures true &&
77test_config pull.verifySignatures true &&
78git pull --ff-only --no-verify-signatures bad 2>pullerror
79'
8081
test_expect_success GPG 'pull unsigned commit into unborn branch' '
82git init empty-repo &&
83test_must_fail \
84git -C empty-repo pull --verify-signatures .. 2>pullerror &&
85test_i18ngrep "does not have a GPG signature" pullerror
86'
8788
test_done