Documentation/diff-config: fix description of diff.renames
[git.git] / t / t7510-signed-commit.sh
blob18e5cf06630273a6131d13d9a82f085d33f15153
1 #!/bin/sh
3 test_description='signed commit tests'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY/lib-gpg.sh"
7 test_expect_success GPG 'create signed commits' '
8 test_when_finished "test_unconfig commit.gpgsign" &&
10 echo 1 >file && git add file &&
11 test_tick && git commit -S -m initial &&
12 git tag initial &&
13 git branch side &&
15 echo 2 >file && test_tick && git commit -a -S -m second &&
16 git tag second &&
18 git checkout side &&
19 echo 3 >elif && git add elif &&
20 test_tick && git commit -m "third on side" &&
22 git checkout master &&
23 test_tick && git merge -S side &&
24 git tag merge &&
26 echo 4 >file && test_tick && git commit -a -m "fourth unsigned" &&
27 git tag fourth-unsigned &&
29 test_tick && git commit --amend -S -m "fourth signed" &&
30 git tag fourth-signed &&
32 git config commit.gpgsign true &&
33 echo 5 >file && test_tick && git commit -a -m "fifth signed" &&
34 git tag fifth-signed &&
36 git config commit.gpgsign false &&
37 echo 6 >file && test_tick && git commit -a -m "sixth" &&
38 git tag sixth-unsigned &&
40 git config commit.gpgsign true &&
41 echo 7 >file && test_tick && git commit -a -m "seventh" --no-gpg-sign &&
42 git tag seventh-unsigned &&
44 test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
45 git tag seventh-signed &&
47 echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
48 git tag eighth-signed-alt
51 test_expect_success GPG 'verify and show signatures' '
53 for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
55 git verify-commit $commit &&
56 git show --pretty=short --show-signature $commit >actual &&
57 grep "Good signature from" actual &&
58 ! grep "BAD signature from" actual &&
59 echo $commit OK || exit 1
60 done
61 ) &&
63 for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
65 test_must_fail git verify-commit $commit &&
66 git show --pretty=short --show-signature $commit >actual &&
67 ! grep "Good signature from" actual &&
68 ! grep "BAD signature from" actual &&
69 echo $commit OK || exit 1
70 done
71 ) &&
73 for commit in eighth-signed-alt
75 git show --pretty=short --show-signature $commit >actual &&
76 grep "Good signature from" actual &&
77 ! grep "BAD signature from" actual &&
78 grep "not certified" actual &&
79 echo $commit OK || exit 1
80 done
84 test_expect_success GPG 'verify-commit exits success on untrusted signature' '
85 git verify-commit eighth-signed-alt 2>actual &&
86 grep "Good signature from" actual &&
87 ! grep "BAD signature from" actual &&
88 grep "not certified" actual
91 test_expect_success GPG 'verify signatures with --raw' '
93 for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
95 git verify-commit --raw $commit 2>actual &&
96 grep "GOODSIG" actual &&
97 ! grep "BADSIG" actual &&
98 echo $commit OK || exit 1
99 done
100 ) &&
102 for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
104 test_must_fail git verify-commit --raw $commit 2>actual &&
105 ! grep "GOODSIG" actual &&
106 ! grep "BADSIG" actual &&
107 echo $commit OK || exit 1
108 done
109 ) &&
111 for commit in eighth-signed-alt
113 git verify-commit --raw $commit 2>actual &&
114 grep "GOODSIG" actual &&
115 ! grep "BADSIG" actual &&
116 grep "TRUST_UNDEFINED" actual &&
117 echo $commit OK || exit 1
118 done
122 test_expect_success GPG 'show signed commit with signature' '
123 git show -s initial >commit &&
124 git show -s --show-signature initial >show &&
125 git verify-commit -v initial >verify.1 2>verify.2 &&
126 git cat-file commit initial >cat &&
127 grep -v -e "gpg: " -e "Warning: " show >show.commit &&
128 grep -e "gpg: " -e "Warning: " show >show.gpg &&
129 grep -v "^ " cat | grep -v "^gpgsig " >cat.commit &&
130 test_cmp show.commit commit &&
131 test_cmp show.gpg verify.2 &&
132 test_cmp cat.commit verify.1
135 test_expect_success GPG 'detect fudged signature' '
136 git cat-file commit seventh-signed >raw &&
138 sed -e "s/seventh/7th forged/" raw >forged1 &&
139 git hash-object -w -t commit forged1 >forged1.commit &&
140 ! git verify-commit $(cat forged1.commit) &&
141 git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&
142 grep "BAD signature from" actual1 &&
143 ! grep "Good signature from" actual1
146 test_expect_success GPG 'detect fudged signature with NUL' '
147 git cat-file commit seventh-signed >raw &&
148 cat raw >forged2 &&
149 echo Qwik | tr "Q" "\000" >>forged2 &&
150 git hash-object -w -t commit forged2 >forged2.commit &&
151 ! git verify-commit $(cat forged2.commit) &&
152 git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
153 grep "BAD signature from" actual2 &&
154 ! grep "Good signature from" actual2
157 test_expect_success GPG 'amending already signed commit' '
158 git checkout fourth-signed^0 &&
159 git commit --amend -S --no-edit &&
160 git verify-commit HEAD &&
161 git show -s --show-signature HEAD >actual &&
162 grep "Good signature from" actual &&
163 ! grep "BAD signature from" actual
166 test_expect_success GPG 'show good signature with custom format' '
167 cat >expect <<-\EOF &&
169 13B6F51ECDDE430D
170 C O Mitter <committer@example.com>
172 git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
173 test_cmp expect actual
176 test_expect_success GPG 'show bad signature with custom format' '
177 cat >expect <<-\EOF &&
179 13B6F51ECDDE430D
180 C O Mitter <committer@example.com>
182 git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
183 test_cmp expect actual
186 test_expect_success GPG 'show unknown signature with custom format' '
187 cat >expect <<-\EOF &&
189 61092E85B7227189
190 Eris Discordia <discord@example.net>
192 git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
193 test_cmp expect actual
196 test_expect_success GPG 'show lack of signature with custom format' '
197 cat >expect <<-\EOF &&
202 git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
203 test_cmp expect actual
206 test_done