]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7030-verify-tag.sh
checkout -p: handle tree arguments correctly again
[thirdparty/git.git] / t / t7030-verify-tag.sh
CommitLineData
d66aeff2 1#!/bin/sh
2
3test_description='signed tag tests'
4. ./test-lib.sh
5. "$TEST_DIRECTORY/lib-gpg.sh"
6
7test_expect_success GPG 'create signed tags' '
8 echo 1 >file && git add file &&
9 test_tick && git commit -m initial &&
10 git tag -s -m initial initial &&
11 git branch side &&
12
13 echo 2 >file && test_tick && git commit -a -m second &&
14 git tag -s -m second second &&
15
16 git checkout side &&
17 echo 3 >elif && git add elif &&
18 test_tick && git commit -m "third on side" &&
19
20 git checkout master &&
21 test_tick && git merge -S side &&
22 git tag -s -m merge merge &&
23
24 echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
25 git tag -a -m fourth-unsigned fourth-unsigned &&
26
27 test_tick && git commit --amend -S -m "fourth signed" &&
28 git tag -s -m fourth fourth-signed &&
29
30 echo 5 >file && test_tick && git commit -a -m "fifth" &&
31 git tag fifth-unsigned &&
32
33 git config commit.gpgsign true &&
34 echo 6 >file && test_tick && git commit -a -m "sixth" &&
35 git tag -a -m sixth sixth-unsigned &&
36
37 test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
38 git tag -m seventh -s seventh-signed &&
39
40 echo 8 >file && test_tick && git commit -a -m eighth &&
41 git tag -uB7227189 -m eighth eighth-signed-alt
42'
43
53fc9993
HS
44test_expect_success GPGSM 'create signed tags x509 ' '
45 test_config gpg.format x509 &&
46 test_config user.signingkey $GIT_COMMITTER_EMAIL &&
aa74be31
EN
47 echo 9 >file && test_tick && git commit -a -m "ninth gpgsm-signed" &&
48 git tag -s -m ninth ninth-signed-x509
53fc9993
HS
49'
50
d66aeff2 51test_expect_success GPG 'verify and show signatures' '
52 (
53 for tag in initial second merge fourth-signed sixth-signed seventh-signed
54 do
55 git verify-tag $tag 2>actual &&
56 grep "Good signature from" actual &&
57 ! grep "BAD signature from" actual &&
58 echo $tag OK || exit 1
59 done
60 ) &&
61 (
62 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
63 do
64 test_must_fail git verify-tag $tag 2>actual &&
65 ! grep "Good signature from" actual &&
66 ! grep "BAD signature from" actual &&
67 echo $tag OK || exit 1
68 done
69 ) &&
70 (
71 for tag in eighth-signed-alt
72 do
73 git verify-tag $tag 2>actual &&
74 grep "Good signature from" actual &&
75 ! grep "BAD signature from" actual &&
76 grep "not certified" actual &&
77 echo $tag OK || exit 1
78 done
79 )
80'
81
53fc9993 82test_expect_success GPGSM 'verify and show signatures x509' '
aa74be31 83 git verify-tag ninth-signed-x509 2>actual &&
53fc9993
HS
84 grep "Good signature from" actual &&
85 ! grep "BAD signature from" actual &&
aa74be31 86 echo ninth-signed-x509 OK
53fc9993
HS
87'
88
54887b46
HJI
89test_expect_success GPGSM 'verify and show signatures x509 with low minTrustLevel' '
90 test_config gpg.minTrustLevel undefined &&
91 git verify-tag ninth-signed-x509 2>actual &&
92 grep "Good signature from" actual &&
93 ! grep "BAD signature from" actual &&
94 echo ninth-signed-x509 OK
95'
96
97test_expect_success GPGSM 'verify and show signatures x509 with matching minTrustLevel' '
98 test_config gpg.minTrustLevel fully &&
99 git verify-tag ninth-signed-x509 2>actual &&
100 grep "Good signature from" actual &&
101 ! grep "BAD signature from" actual &&
102 echo ninth-signed-x509 OK
103'
104
105test_expect_success GPGSM 'verify and show signatures x509 with high minTrustLevel' '
106 test_config gpg.minTrustLevel ultimate &&
107 test_must_fail git verify-tag ninth-signed-x509 2>actual &&
108 grep "Good signature from" actual &&
109 ! grep "BAD signature from" actual &&
110 echo ninth-signed-x509 OK
111'
112
d66aeff2 113test_expect_success GPG 'detect fudged signature' '
114 git cat-file tag seventh-signed >raw &&
2f3cbcd8 115 sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
d66aeff2 116 git hash-object -w -t tag forged1 >forged1.tag &&
117 test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
118 grep "BAD signature from" actual1 &&
119 ! grep "Good signature from" actual1
120'
121
e18443ec 122test_expect_success GPG 'verify signatures with --raw' '
123 (
124 for tag in initial second merge fourth-signed sixth-signed seventh-signed
125 do
126 git verify-tag --raw $tag 2>actual &&
127 grep "GOODSIG" actual &&
128 ! grep "BADSIG" actual &&
129 echo $tag OK || exit 1
130 done
131 ) &&
132 (
133 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
134 do
135 test_must_fail git verify-tag --raw $tag 2>actual &&
136 ! grep "GOODSIG" actual &&
137 ! grep "BADSIG" actual &&
138 echo $tag OK || exit 1
139 done
140 ) &&
141 (
142 for tag in eighth-signed-alt
143 do
144 git verify-tag --raw $tag 2>actual &&
145 grep "GOODSIG" actual &&
146 ! grep "BADSIG" actual &&
147 grep "TRUST_UNDEFINED" actual &&
148 echo $tag OK || exit 1
149 done
150 )
151'
152
53fc9993 153test_expect_success GPGSM 'verify signatures with --raw x509' '
aa74be31 154 git verify-tag --raw ninth-signed-x509 2>actual &&
53fc9993
HS
155 grep "GOODSIG" actual &&
156 ! grep "BADSIG" actual &&
aa74be31 157 echo ninth-signed-x509 OK
53fc9993
HS
158'
159
3e1e7454
ST
160test_expect_success GPG 'verify multiple tags' '
161 tags="fourth-signed sixth-signed seventh-signed" &&
162 for i in $tags
163 do
164 git verify-tag -v --raw $i || return 1
165 done >expect.stdout 2>expect.stderr.1 &&
166 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
167 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
168 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
169 test_cmp expect.stdout actual.stdout &&
170 test_cmp expect.stderr actual.stderr
171'
172
53fc9993 173test_expect_success GPGSM 'verify multiple tags x509' '
aa74be31 174 tags="seventh-signed ninth-signed-x509" &&
53fc9993
HS
175 for i in $tags
176 do
177 git verify-tag -v --raw $i || return 1
178 done >expect.stdout 2>expect.stderr.1 &&
179 grep "^.GNUPG:." <expect.stderr.1 >expect.stderr &&
180 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
181 grep "^.GNUPG:." <actual.stderr.1 >actual.stderr &&
182 test_cmp expect.stdout actual.stdout &&
183 test_cmp expect.stderr actual.stderr
184'
185
b42ca35e
ST
186test_expect_success GPG 'verifying tag with --format' '
187 cat >expect <<-\EOF &&
02c5433e 188 tagname : fourth-signed
b42ca35e 189 EOF
02c5433e
ST
190 git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
191 test_cmp expect actual
192'
193
b42ca35e 194test_expect_success GPG 'verifying a forged tag with --format should fail silently' '
02c5433e 195 test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
d3c6751b 196 test_must_be_empty actual-forged
02c5433e
ST
197'
198
d66aeff2 199test_done