blob: 61330f71b1749c92a79153a3fce4f1834bfed248 [file] [log] [blame]
Sebastian Götteefed0022013-03-31 18:02:24 +02001#!/bin/sh
2
3test_description='merge signature verification tests'
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Sebastian Götteefed0022013-03-31 18:02:24 +02007. ./test-lib.sh
8. "$TEST_DIRECTORY/lib-gpg.sh"
9
10test_expect_success GPG 'create signed commits' '
11 echo 1 >file && git add file &&
12 test_tick && git commit -m initial &&
13 git tag initial &&
14
15 git checkout -b side-signed &&
16 echo 3 >elif && git add elif &&
17 test_tick && git commit -S -m "signed on side" &&
18 git checkout initial &&
19
20 git checkout -b side-unsigned &&
21 echo 3 >foo && git add foo &&
22 test_tick && git commit -m "unsigned on side" &&
23 git checkout initial &&
24
25 git checkout -b side-bad &&
26 echo 3 >bar && git add bar &&
27 test_tick && git commit -S -m "bad on side" &&
28 git cat-file commit side-bad >raw &&
SZEDER Gábor2f3cbcd2018-06-04 15:39:26 +020029 sed -e "s/^bad/forged bad/" raw >forged &&
Sebastian Götteefed0022013-03-31 18:02:24 +020030 git hash-object -w -t commit forged >forged.commit &&
31 git checkout initial &&
32
Sebastian Götteeb307ae2013-03-31 18:02:46 +020033 git checkout -b side-untrusted &&
34 echo 3 >baz && git add baz &&
Jeff King99094a72015-03-20 06:07:15 -040035 test_tick && git commit -SB7227189 -m "untrusted on side" &&
Sebastian Götteeb307ae2013-03-31 18:02:46 +020036
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000037 git checkout main
Sebastian Götteefed0022013-03-31 18:02:24 +020038'
39
40test_expect_success GPG 'merge unsigned commit with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080041 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +020042 test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
43 test_i18ngrep "does not have a GPG signature" mergeerror
44'
45
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000046test_expect_success GPG 'merge unsigned commit with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080047 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000048 test_config merge.verifySignatures true &&
49 test_must_fail git merge --ff-only side-unsigned 2>mergeerror &&
50 test_i18ngrep "does not have a GPG signature" mergeerror
51'
52
Sebastian Götteefed0022013-03-31 18:02:24 +020053test_expect_success GPG 'merge commit with bad signature with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080054 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +020055 test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
56 test_i18ngrep "has a bad GPG signature" mergeerror
57'
58
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000059test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080060 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000061 test_config merge.verifySignatures true &&
62 test_must_fail git merge --ff-only $(cat forged.commit) 2>mergeerror &&
63 test_i18ngrep "has a bad GPG signature" mergeerror
64'
65
Sebastian Götteeb307ae2013-03-31 18:02:46 +020066test_expect_success GPG 'merge commit with untrusted signature with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080067 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteeb307ae2013-03-31 18:02:46 +020068 test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
69 test_i18ngrep "has an untrusted GPG signature" mergeerror
70'
71
Hans Jerry Illikainen54887b42019-12-27 13:55:57 +000072test_expect_success GPG 'merge commit with untrusted signature with verification and high minTrustLevel' '
73 test_when_finished "git reset --hard && git checkout initial" &&
74 test_config gpg.minTrustLevel marginal &&
75 test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
76 test_i18ngrep "has an untrusted GPG signature" mergeerror
77'
78
79test_expect_success GPG 'merge commit with untrusted signature with verification and low minTrustLevel' '
80 test_when_finished "git reset --hard && git checkout initial" &&
81 test_config gpg.minTrustLevel undefined &&
82 git merge --ff-only --verify-signatures side-untrusted >mergeoutput &&
83 test_i18ngrep "has a good GPG signature" mergeoutput
84'
85
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000086test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080087 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000088 test_config merge.verifySignatures true &&
89 test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
90 test_i18ngrep "has an untrusted GPG signature" mergeerror
91'
92
Hans Jerry Illikainen54887b42019-12-27 13:55:57 +000093test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true and minTrustLevel' '
94 test_when_finished "git reset --hard && git checkout initial" &&
95 test_config merge.verifySignatures true &&
96 test_config gpg.minTrustLevel marginal &&
97 test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
98 test_i18ngrep "has an untrusted GPG signature" mergeerror
99'
100
Sebastian Götteefed0022013-03-31 18:02:24 +0200101test_expect_success GPG 'merge signed commit with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800102 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +0200103 git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
104 test_i18ngrep "has a good GPG signature" mergeoutput
105'
106
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000107test_expect_success GPG 'merge signed commit with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800108 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000109 test_config merge.verifySignatures true &&
110 git merge --verbose --ff-only side-signed >mergeoutput &&
111 test_i18ngrep "has a good GPG signature" mergeoutput
112'
113
Sebastian Götteefed0022013-03-31 18:02:24 +0200114test_expect_success GPG 'merge commit with bad signature without verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800115 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +0200116 git merge $(cat forged.commit)
117'
118
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000119test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=false' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800120 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000121 test_config merge.verifySignatures false &&
122 git merge $(cat forged.commit)
123'
124
125test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true and --no-verify-signatures' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800126 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000127 test_config merge.verifySignatures true &&
128 git merge --no-verify-signatures $(cat forged.commit)
129'
130
Jeff King7488ba32018-11-06 02:51:15 -0500131test_expect_success GPG 'merge unsigned commit into unborn branch' '
132 test_when_finished "git checkout initial" &&
133 git checkout --orphan unborn &&
134 test_must_fail git merge --verify-signatures side-unsigned 2>mergeerror &&
135 test_i18ngrep "does not have a GPG signature" mergeerror
136'
137
Sebastian Götteefed0022013-03-31 18:02:24 +0200138test_done