blob: a426f3a89aa76fb9b89464988211264e56314a60 [file] [log] [blame]
Sebastian Götteefed0022013-03-31 18:02:24 +02001#!/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 &&
SZEDER Gábor2f3cbcd2018-06-04 15:39:26 +020026 sed -e "s/^bad/forged bad/" raw >forged &&
Sebastian Götteefed0022013-03-31 18:02:24 +020027 git hash-object -w -t commit forged >forged.commit &&
28 git checkout initial &&
29
Sebastian Götteeb307ae2013-03-31 18:02:46 +020030 git checkout -b side-untrusted &&
31 echo 3 >baz && git add baz &&
Jeff King99094a72015-03-20 06:07:15 -040032 test_tick && git commit -SB7227189 -m "untrusted on side" &&
Sebastian Götteeb307ae2013-03-31 18:02:46 +020033
Sebastian Götteefed0022013-03-31 18:02:24 +020034 git checkout master
35'
36
37test_expect_success GPG 'merge unsigned commit with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080038 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +020039 test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
40 test_i18ngrep "does not have a GPG signature" mergeerror
41'
42
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000043test_expect_success GPG 'merge unsigned commit with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080044 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000045 test_config merge.verifySignatures true &&
46 test_must_fail git merge --ff-only side-unsigned 2>mergeerror &&
47 test_i18ngrep "does not have a GPG signature" mergeerror
48'
49
Sebastian Götteefed0022013-03-31 18:02:24 +020050test_expect_success GPG 'merge commit with bad signature with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080051 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +020052 test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
53 test_i18ngrep "has a bad GPG signature" mergeerror
54'
55
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000056test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080057 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000058 test_config merge.verifySignatures true &&
59 test_must_fail git merge --ff-only $(cat forged.commit) 2>mergeerror &&
60 test_i18ngrep "has a bad GPG signature" mergeerror
61'
62
Sebastian Götteeb307ae2013-03-31 18:02:46 +020063test_expect_success GPG 'merge commit with untrusted signature with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080064 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteeb307ae2013-03-31 18:02:46 +020065 test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
66 test_i18ngrep "has an untrusted GPG signature" mergeerror
67'
68
Hans Jerry Illikainen54887b42019-12-27 13:55:57 +000069test_expect_success GPG 'merge commit with untrusted signature with verification and high minTrustLevel' '
70 test_when_finished "git reset --hard && git checkout initial" &&
71 test_config gpg.minTrustLevel marginal &&
72 test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
73 test_i18ngrep "has an untrusted GPG signature" mergeerror
74'
75
76test_expect_success GPG 'merge commit with untrusted signature with verification and low minTrustLevel' '
77 test_when_finished "git reset --hard && git checkout initial" &&
78 test_config gpg.minTrustLevel undefined &&
79 git merge --ff-only --verify-signatures side-untrusted >mergeoutput &&
80 test_i18ngrep "has a good GPG signature" mergeoutput
81'
82
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000083test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080084 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +000085 test_config merge.verifySignatures true &&
86 test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
87 test_i18ngrep "has an untrusted GPG signature" mergeerror
88'
89
Hans Jerry Illikainen54887b42019-12-27 13:55:57 +000090test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true and minTrustLevel' '
91 test_when_finished "git reset --hard && git checkout initial" &&
92 test_config merge.verifySignatures true &&
93 test_config gpg.minTrustLevel marginal &&
94 test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
95 test_i18ngrep "has an untrusted GPG signature" mergeerror
96'
97
Sebastian Götteefed0022013-03-31 18:02:24 +020098test_expect_success GPG 'merge signed commit with verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -080099 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +0200100 git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
101 test_i18ngrep "has a good GPG signature" mergeoutput
102'
103
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000104test_expect_success GPG 'merge signed commit with merge.verifySignatures=true' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800105 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000106 test_config merge.verifySignatures true &&
107 git merge --verbose --ff-only side-signed >mergeoutput &&
108 test_i18ngrep "has a good GPG signature" mergeoutput
109'
110
Sebastian Götteefed0022013-03-31 18:02:24 +0200111test_expect_success GPG 'merge commit with bad signature without verification' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800112 test_when_finished "git reset --hard && git checkout initial" &&
Sebastian Götteefed0022013-03-31 18:02:24 +0200113 git merge $(cat forged.commit)
114'
115
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000116test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=false' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800117 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000118 test_config merge.verifySignatures false &&
119 git merge $(cat forged.commit)
120'
121
122test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true and --no-verify-signatures' '
Junio C Hamanofb2afea2017-12-15 11:42:36 -0800123 test_when_finished "git reset --hard && git checkout initial" &&
Hans Jerry Illikainenca779e82017-12-10 06:53:57 +0000124 test_config merge.verifySignatures true &&
125 git merge --no-verify-signatures $(cat forged.commit)
126'
127
Jeff King7488ba32018-11-06 02:51:15 -0500128test_expect_success GPG 'merge unsigned commit into unborn branch' '
129 test_when_finished "git checkout initial" &&
130 git checkout --orphan unborn &&
131 test_must_fail git merge --verify-signatures side-unsigned 2>mergeerror &&
132 test_i18ngrep "does not have a GPG signature" mergeerror
133'
134
Sebastian Götteefed0022013-03-31 18:02:24 +0200135test_done