2344995a1157cdddc08102d06d73c04690cb67c0
1#!/bin/sh
2
3test_description='merge signature verification tests'
4. ./test-lib.sh
5. "$TEST_DIRECTORY/lib-gpg.sh"
6
7test_expect_success GPG 'create signed commits' '
8 echo 1 >file && git add file &&
9 test_tick && git commit -m initial &&
10 git tag initial &&
11
12 git checkout -b side-signed &&
13 echo 3 >elif && git add elif &&
14 test_tick && git commit -S -m "signed on side" &&
15 git checkout initial &&
16
17 git checkout -b side-unsigned &&
18 echo 3 >foo && git add foo &&
19 test_tick && git commit -m "unsigned on side" &&
20 git checkout initial &&
21
22 git checkout -b side-bad &&
23 echo 3 >bar && git add bar &&
24 test_tick && git commit -S -m "bad on side" &&
25 git cat-file commit side-bad >raw &&
26 sed -e "s/bad/forged bad/" raw >forged &&
27 git hash-object -w -t commit forged >forged.commit &&
28 git checkout initial &&
29
30 git checkout -b side-untrusted &&
31 echo 3 >baz && git add baz &&
32 test_tick && git commit -SB7227189 -m "untrusted on side" &&
33
34 git checkout master
35'
36
37test_expect_success GPG 'merge unsigned commit with verification' '
38 test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
39 test_i18ngrep "does not have a GPG signature" mergeerror
40'
41
42test_expect_success GPG 'merge unsigned commit with merge.verifySignatures=true' '
43 test_config merge.verifySignatures true &&
44 test_must_fail git merge --ff-only side-unsigned 2>mergeerror &&
45 test_i18ngrep "does not have a GPG signature" mergeerror
46'
47
48test_expect_success GPG 'merge commit with bad signature with verification' '
49 test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
50 test_i18ngrep "has a bad GPG signature" mergeerror
51'
52
53test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true' '
54 test_config merge.verifySignatures true &&
55 test_must_fail git merge --ff-only $(cat forged.commit) 2>mergeerror &&
56 test_i18ngrep "has a bad GPG signature" mergeerror
57'
58
59test_expect_success GPG 'merge commit with untrusted signature with verification' '
60 test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
61 test_i18ngrep "has an untrusted GPG signature" mergeerror
62'
63
64test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true' '
65 test_config merge.verifySignatures true &&
66 test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
67 test_i18ngrep "has an untrusted GPG signature" mergeerror
68'
69
70test_expect_success GPG 'merge signed commit with verification' '
71 test_when_finished "git checkout initial" &&
72 git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
73 test_i18ngrep "has a good GPG signature" mergeoutput
74'
75
76test_expect_success GPG 'merge signed commit with merge.verifySignatures=true' '
77 test_when_finished "git checkout initial" &&
78 test_config merge.verifySignatures true &&
79 git merge --verbose --ff-only side-signed >mergeoutput &&
80 test_i18ngrep "has a good GPG signature" mergeoutput
81'
82
83test_expect_success GPG 'merge commit with bad signature without verification' '
84 test_when_finished "git checkout initial" &&
85 git merge $(cat forged.commit)
86'
87
88test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=false' '
89 test_when_finished "git checkout initial" &&
90 test_config merge.verifySignatures false &&
91 git merge $(cat forged.commit)
92'
93
94test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true and --no-verify-signatures' '
95 test_when_finished "git checkout initial" &&
96 test_config merge.verifySignatures true &&
97 git merge --no-verify-signatures $(cat forged.commit)
98'
99
100test_done