Merge branch 'ar/fix-git-pull-no-verify'
[git/debian.git] / t / t7031-verify-tag-signed-ssh.sh
blob06c9dd6c9339f24e81fc81757daf00d5b1a63fa3
1 #!/bin/sh
3 test_description='signed tag tests'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY/lib-gpg.sh"
10 test_expect_success GPGSSH 'create signed tags ssh' '
11 test_when_finished "test_unconfig commit.gpgsign" &&
12 test_config gpg.format ssh &&
13 test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
15 echo 1 >file && git add file &&
16 test_tick && git commit -m initial &&
17 git tag -s -m initial initial &&
18 git branch side &&
20 echo 2 >file && test_tick && git commit -a -m second &&
21 git tag -s -m second second &&
23 git checkout side &&
24 echo 3 >elif && git add elif &&
25 test_tick && git commit -m "third on side" &&
27 git checkout main &&
28 test_tick && git merge -S side &&
29 git tag -s -m merge merge &&
31 echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" &&
32 git tag -a -m fourth-unsigned fourth-unsigned &&
34 test_tick && git commit --amend -S -m "fourth signed" &&
35 git tag -s -m fourth fourth-signed &&
37 echo 5 >file && test_tick && git commit -a -m "fifth" &&
38 git tag fifth-unsigned &&
40 git config commit.gpgsign true &&
41 echo 6 >file && test_tick && git commit -a -m "sixth" &&
42 git tag -a -m sixth sixth-unsigned &&
44 test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ &&
45 git tag -m seventh -s seventh-signed &&
47 echo 8 >file && test_tick && git commit -a -m eighth &&
48 git tag -u"${GPGSSH_KEY_UNTRUSTED}" -m eighth eighth-signed-alt
51 test_expect_success GPGSSH 'verify and show ssh signatures' '
52 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
54 for tag in initial second merge fourth-signed sixth-signed seventh-signed
56 git verify-tag $tag 2>actual &&
57 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
58 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
59 echo $tag OK || exit 1
60 done
61 ) &&
63 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
65 test_must_fail git verify-tag $tag 2>actual &&
66 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
67 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
68 echo $tag OK || exit 1
69 done
70 ) &&
72 for tag in eighth-signed-alt
74 test_must_fail git verify-tag $tag 2>actual &&
75 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
76 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
77 grep "${GPGSSH_KEY_NOT_TRUSTED}" actual &&
78 echo $tag OK || exit 1
79 done
83 test_expect_success GPGSSH 'detect fudged ssh signature' '
84 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
85 git cat-file tag seventh-signed >raw &&
86 sed -e "/^tag / s/seventh/7th forged/" raw >forged1 &&
87 git hash-object -w -t tag forged1 >forged1.tag &&
88 test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 &&
89 grep "${GPGSSH_BAD_SIGNATURE}" actual1 &&
90 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual1 &&
91 ! grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual1
94 test_expect_success GPGSSH 'verify ssh signatures with --raw' '
95 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
97 for tag in initial second merge fourth-signed sixth-signed seventh-signed
99 git verify-tag --raw $tag 2>actual &&
100 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
101 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
102 echo $tag OK || exit 1
103 done
104 ) &&
106 for tag in fourth-unsigned fifth-unsigned sixth-unsigned
108 test_must_fail git verify-tag --raw $tag 2>actual &&
109 ! grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
110 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
111 echo $tag OK || exit 1
112 done
113 ) &&
115 for tag in eighth-signed-alt
117 test_must_fail git verify-tag --raw $tag 2>actual &&
118 grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual &&
119 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
120 echo $tag OK || exit 1
121 done
125 test_expect_success GPGSSH 'verify signatures with --raw ssh' '
126 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
127 git verify-tag --raw sixth-signed 2>actual &&
128 grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual &&
129 ! grep "${GPGSSH_BAD_SIGNATURE}" actual &&
130 echo sixth-signed OK
133 test_expect_success GPGSSH 'verify multiple tags ssh' '
134 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
135 tags="seventh-signed sixth-signed" &&
136 for i in $tags
138 git verify-tag -v --raw $i || return 1
139 done >expect.stdout 2>expect.stderr.1 &&
140 grep "^${GPGSSH_GOOD_SIGNATURE_TRUSTED}" <expect.stderr.1 >expect.stderr &&
141 git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 &&
142 grep "^${GPGSSH_GOOD_SIGNATURE_TRUSTED}" <actual.stderr.1 >actual.stderr &&
143 test_cmp expect.stdout actual.stdout &&
144 test_cmp expect.stderr actual.stderr
147 test_expect_success GPGSSH 'verifying tag with --format - ssh' '
148 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
149 cat >expect <<-\EOF &&
150 tagname : fourth-signed
152 git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual &&
153 test_cmp expect actual
156 test_expect_success GPGSSH 'verifying a forged tag with --format should fail silently - ssh' '
157 test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged &&
158 test_must_be_empty actual-forged
161 test_done