3 test_description
='signed tag tests'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
9 .
"$TEST_DIRECTORY/lib-gpg.sh"
11 test_expect_success GPGSSH
'create signed tags ssh' '
12 test_when_finished "test_unconfig commit.gpgsign" &&
13 test_config gpg.format ssh &&
14 test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
16 echo 1 >file && git add file &&
17 test_tick && git commit -m initial &&
18 git tag -s -m initial initial &&
21 echo 2 >file && test_tick && git commit -a -m second &&
22 git tag -s -m second second &&
25 echo 3 >elif && git add elif &&
26 test_tick && git commit -m "third on side" &&
29 test_tick && git merge -S side &&
30 git tag -s -m merge merge &&
32 echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
33 git tag -a -m fourth-unsigned fourth-unsigned &&
35 test_tick && git commit --amend -S -m "fourth signed" &&
36 git tag -s -m fourth fourth-signed &&
38 echo 5 >file && test_tick && git commit -a -m "fifth" &&
39 git tag fifth-unsigned &&
41 git config commit.gpgsign true &&
42 echo 6 >file && test_tick && git commit -a -m "sixth" &&
43 git tag -a -m sixth sixth-unsigned &&
45 test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
46 git tag -m seventh -s seventh-signed &&
48 echo 8 >file && test_tick && git commit -a -m eighth &&
49 git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt
52 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'create signed tags with keys having defined lifetimes' '
53 test_when_finished "test_unconfig commit.gpgsign" &&
54 test_config gpg.format ssh &&
56 echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" &&
57 git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed &&
59 echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" &&
60 git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed &&
62 echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" &&
63 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed &&
65 echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" &&
66 git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed
69 test_expect_success GPGSSH
'verify and show ssh signatures' '
70 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
72 for tag in initial second merge fourth-signed sixth-signed seventh-signed
74 git verify-tag $tag 2>actual &&
75 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
76 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
77 echo $tag OK || exit 1
81 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
83 test_must_fail git verify-tag $tag 2>actual &&
84 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
85 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
86 echo $tag OK || exit 1
90 for tag in eighth-signed-alt
92 test_must_fail git verify-tag $tag 2>actual &&
93 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
94 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
95 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual &&
96 echo $tag OK || exit 1
101 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'verify-tag exits failure on expired signature key' '
102 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
103 test_must_fail git verify-tag expired-signed 2>actual &&
104 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
107 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'verify-tag exits failure on not yet valid signature key' '
108 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
109 test_must_fail git verify-tag notyetvalid-signed 2>actual &&
110 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
113 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'verify-tag succeeds with tag date and key validity matching' '
114 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
115 git verify-tag timeboxedvalid-signed 2>actual &&
116 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
117 ! grep "${GPGSSH_BAD_SIGNATURE}" actual
120 test_expect_success GPGSSH
,GPGSSH_VERIFYTIME
'verify-tag fails with tag date outside of key validity' '
121 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
122 test_must_fail git verify-tag timeboxedinvalid-signed 2>actual &&
123 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual
126 test_expect_success GPGSSH
'detect fudged ssh signature' '
127 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
128 git cat-file tag seventh-signed >raw &&
129 sed -e "/^tag / s/seventh/7th-forged/" raw >forged1 &&
130 git hash-object -w -t tag forged1 >forged1.tag &&
131 test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
132 grep "${GPGSSH_BAD_SIGNATURE}" actual1 &&
133 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual1 &&
134 ! grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual1
137 test_expect_success GPGSSH
'verify ssh signatures with --raw' '
138 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
140 for tag in initial second merge fourth-signed sixth-signed seventh-signed
142 git verify-tag --raw $tag 2>actual &&
143 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
144 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
145 echo $tag OK || exit 1
149 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
151 test_must_fail git verify-tag --raw $tag 2>actual &&
152 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
153 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
154 echo $tag OK || exit 1
158 for tag in eighth-signed-alt
160 test_must_fail git verify-tag --raw $tag 2>actual &&
161 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
162 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
163 echo $tag OK || exit 1
168 test_expect_success GPGSSH
'verify signatures with --raw ssh' '
169 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
170 git verify-tag --raw sixth-signed 2>actual &&
171 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
172 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
176 test_expect_success GPGSSH
'verify multiple tags ssh' '
177 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
178 tags="seventh-signed sixth-signed" &&
181 git verify-tag -v --raw $i || return 1
182 done >expect.stdout 2>expect.stderr.1 &&
183 grep "^${GPGSSH_GOOD_SIGNATURE_TRUSTED}" <expect.stderr.1 >expect.stderr &&
184 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
185 grep "^${GPGSSH_GOOD_SIGNATURE_TRUSTED}" <actual.stderr.1 >actual.stderr &&
186 test_cmp expect.stdout actual.stdout &&
187 test_cmp expect.stderr actual.stderr
190 test_expect_success GPGSSH
'verifying tag with --format - ssh' '
191 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
192 cat >expect <<-\EOF &&
193 tagname : fourth-signed
195 git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
196 test_cmp expect actual
199 test_expect_success GPGSSH
'verifying a forged tag with --format should fail silently - ssh' '
200 test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
201 test_must_be_empty actual-forged
204 test_expect_success GPGSSH
'rev-list --format=%G' '
205 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
206 git rev-list -1 --format="%G? %H" sixth-signed >actual &&
207 cat >expect <<-EOF &&
208 commit $(git rev-parse sixth-signed^0)
209 G $(git rev-parse sixth-signed^0)
211 test_cmp expect actual