brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='signed tag tests' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | . "$TEST_DIRECTORY/lib-gpg.sh" |
| 9 | |
| 10 | test_expect_success GPG 'create signed tags' ' |
| 11 | echo 1 >file && git add file && |
| 12 | test_tick && git commit -m initial && |
| 13 | git tag -s -m initial initial && |
| 14 | git branch side && |
| 15 | |
| 16 | echo 2 >file && test_tick && git commit -a -m second && |
| 17 | git tag -s -m second second && |
| 18 | |
| 19 | git checkout side && |
| 20 | echo 3 >elif && git add elif && |
| 21 | test_tick && git commit -m "third on side" && |
| 22 | |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 23 | git checkout main && |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 24 | test_tick && git merge -S side && |
| 25 | git tag -s -m merge merge && |
| 26 | |
| 27 | echo 4 >file && test_tick && git commit -a -S -m "fourth unsigned" && |
| 28 | git tag -a -m fourth-unsigned fourth-unsigned && |
| 29 | |
| 30 | test_tick && git commit --amend -S -m "fourth signed" && |
| 31 | git tag -s -m fourth fourth-signed && |
| 32 | |
| 33 | echo 5 >file && test_tick && git commit -a -m "fifth" && |
| 34 | git tag fifth-unsigned && |
| 35 | |
| 36 | git config commit.gpgsign true && |
| 37 | echo 6 >file && test_tick && git commit -a -m "sixth" && |
| 38 | git tag -a -m sixth sixth-unsigned && |
| 39 | |
| 40 | test_tick && git rebase -f HEAD^^ && git tag -s -m 6th sixth-signed HEAD^ && |
| 41 | git tag -m seventh -s seventh-signed && |
| 42 | |
| 43 | echo 8 >file && test_tick && git commit -a -m eighth && |
| 44 | git tag -uB7227189 -m eighth eighth-signed-alt |
| 45 | ' |
| 46 | |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 47 | test_expect_success GPGSM 'create signed tags x509 ' ' |
| 48 | test_config gpg.format x509 && |
| 49 | test_config user.signingkey $GIT_COMMITTER_EMAIL && |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 50 | echo 9 >file && test_tick && git commit -a -m "ninth gpgsm-signed" && |
| 51 | git tag -s -m ninth ninth-signed-x509 |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 52 | ' |
| 53 | |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 54 | test_expect_success GPG 'verify and show signatures' ' |
| 55 | ( |
| 56 | for tag in initial second merge fourth-signed sixth-signed seventh-signed |
| 57 | do |
| 58 | git verify-tag $tag 2>actual && |
| 59 | grep "Good signature from" actual && |
| 60 | ! grep "BAD signature from" actual && |
| 61 | echo $tag OK || exit 1 |
| 62 | done |
| 63 | ) && |
| 64 | ( |
| 65 | for tag in fourth-unsigned fifth-unsigned sixth-unsigned |
| 66 | do |
| 67 | test_must_fail git verify-tag $tag 2>actual && |
| 68 | ! grep "Good signature from" actual && |
| 69 | ! grep "BAD signature from" actual && |
| 70 | echo $tag OK || exit 1 |
| 71 | done |
| 72 | ) && |
| 73 | ( |
| 74 | for tag in eighth-signed-alt |
| 75 | do |
| 76 | git verify-tag $tag 2>actual && |
| 77 | grep "Good signature from" actual && |
| 78 | ! grep "BAD signature from" actual && |
| 79 | grep "not certified" actual && |
| 80 | echo $tag OK || exit 1 |
| 81 | done |
| 82 | ) |
| 83 | ' |
| 84 | |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 85 | test_expect_success GPGSM 'verify and show signatures x509' ' |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 86 | git verify-tag ninth-signed-x509 2>actual && |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 87 | grep "Good signature from" actual && |
| 88 | ! grep "BAD signature from" actual && |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 89 | echo ninth-signed-x509 OK |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 90 | ' |
| 91 | |
Hans Jerry Illikainen | 54887b4 | 2019-12-27 13:55:57 +0000 | [diff] [blame] | 92 | test_expect_success GPGSM 'verify and show signatures x509 with low minTrustLevel' ' |
| 93 | test_config gpg.minTrustLevel undefined && |
| 94 | git verify-tag ninth-signed-x509 2>actual && |
| 95 | grep "Good signature from" actual && |
| 96 | ! grep "BAD signature from" actual && |
| 97 | echo ninth-signed-x509 OK |
| 98 | ' |
| 99 | |
| 100 | test_expect_success GPGSM 'verify and show signatures x509 with matching minTrustLevel' ' |
| 101 | test_config gpg.minTrustLevel fully && |
| 102 | git verify-tag ninth-signed-x509 2>actual && |
| 103 | grep "Good signature from" actual && |
| 104 | ! grep "BAD signature from" actual && |
| 105 | echo ninth-signed-x509 OK |
| 106 | ' |
| 107 | |
| 108 | test_expect_success GPGSM 'verify and show signatures x509 with high minTrustLevel' ' |
| 109 | test_config gpg.minTrustLevel ultimate && |
| 110 | test_must_fail git verify-tag ninth-signed-x509 2>actual && |
| 111 | grep "Good signature from" actual && |
| 112 | ! grep "BAD signature from" actual && |
| 113 | echo ninth-signed-x509 OK |
| 114 | ' |
| 115 | |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 116 | test_expect_success GPG 'detect fudged signature' ' |
| 117 | git cat-file tag seventh-signed >raw && |
Jeff King | ad5dfea | 2023-01-18 15:36:22 -0500 | [diff] [blame] | 118 | sed -e "/^tag / s/seventh/7th-forged/" raw >forged1 && |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 119 | git hash-object -w -t tag forged1 >forged1.tag && |
| 120 | test_must_fail git verify-tag $(cat forged1.tag) 2>actual1 && |
| 121 | grep "BAD signature from" actual1 && |
| 122 | ! grep "Good signature from" actual1 |
| 123 | ' |
| 124 | |
brian m. carlson | e18443e | 2015-06-21 23:14:43 +0000 | [diff] [blame] | 125 | test_expect_success GPG 'verify signatures with --raw' ' |
| 126 | ( |
| 127 | for tag in initial second merge fourth-signed sixth-signed seventh-signed |
| 128 | do |
| 129 | git verify-tag --raw $tag 2>actual && |
| 130 | grep "GOODSIG" actual && |
| 131 | ! grep "BADSIG" actual && |
| 132 | echo $tag OK || exit 1 |
| 133 | done |
| 134 | ) && |
| 135 | ( |
| 136 | for tag in fourth-unsigned fifth-unsigned sixth-unsigned |
| 137 | do |
| 138 | test_must_fail git verify-tag --raw $tag 2>actual && |
| 139 | ! grep "GOODSIG" actual && |
| 140 | ! grep "BADSIG" actual && |
| 141 | echo $tag OK || exit 1 |
| 142 | done |
| 143 | ) && |
| 144 | ( |
| 145 | for tag in eighth-signed-alt |
| 146 | do |
| 147 | git verify-tag --raw $tag 2>actual && |
| 148 | grep "GOODSIG" actual && |
| 149 | ! grep "BADSIG" actual && |
| 150 | grep "TRUST_UNDEFINED" actual && |
| 151 | echo $tag OK || exit 1 |
| 152 | done |
| 153 | ) |
| 154 | ' |
| 155 | |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 156 | test_expect_success GPGSM 'verify signatures with --raw x509' ' |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 157 | git verify-tag --raw ninth-signed-x509 2>actual && |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 158 | grep "GOODSIG" actual && |
| 159 | ! grep "BADSIG" actual && |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 160 | echo ninth-signed-x509 OK |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 161 | ' |
| 162 | |
Santiago Torres | 3e1e745 | 2016-04-17 18:26:57 -0400 | [diff] [blame] | 163 | test_expect_success GPG 'verify multiple tags' ' |
| 164 | tags="fourth-signed sixth-signed seventh-signed" && |
| 165 | for i in $tags |
| 166 | do |
| 167 | git verify-tag -v --raw $i || return 1 |
| 168 | done >expect.stdout 2>expect.stderr.1 && |
| 169 | grep "^.GNUPG:." <expect.stderr.1 >expect.stderr && |
| 170 | git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 && |
| 171 | grep "^.GNUPG:." <actual.stderr.1 >actual.stderr && |
| 172 | test_cmp expect.stdout actual.stdout && |
| 173 | test_cmp expect.stderr actual.stderr |
| 174 | ' |
| 175 | |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 176 | test_expect_success GPGSM 'verify multiple tags x509' ' |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 177 | tags="seventh-signed ninth-signed-x509" && |
Henning Schild | 53fc999 | 2018-07-20 10:28:07 +0200 | [diff] [blame] | 178 | for i in $tags |
| 179 | do |
| 180 | git verify-tag -v --raw $i || return 1 |
| 181 | done >expect.stdout 2>expect.stderr.1 && |
| 182 | grep "^.GNUPG:." <expect.stderr.1 >expect.stderr && |
| 183 | git verify-tag -v --raw $tags >actual.stdout 2>actual.stderr.1 && |
| 184 | grep "^.GNUPG:." <actual.stderr.1 >actual.stderr && |
| 185 | test_cmp expect.stdout actual.stdout && |
| 186 | test_cmp expect.stderr actual.stderr |
| 187 | ' |
| 188 | |
Santiago Torres | b42ca35 | 2017-03-23 18:28:47 -0400 | [diff] [blame] | 189 | test_expect_success GPG 'verifying tag with --format' ' |
| 190 | cat >expect <<-\EOF && |
Santiago Torres | 02c5433 | 2017-01-17 18:37:22 -0500 | [diff] [blame] | 191 | tagname : fourth-signed |
Santiago Torres | b42ca35 | 2017-03-23 18:28:47 -0400 | [diff] [blame] | 192 | EOF |
Santiago Torres | 02c5433 | 2017-01-17 18:37:22 -0500 | [diff] [blame] | 193 | git verify-tag --format="tagname : %(tag)" "fourth-signed" >actual && |
| 194 | test_cmp expect actual |
| 195 | ' |
| 196 | |
ZheNing Hu | b9dee07 | 2021-07-26 03:26:50 +0000 | [diff] [blame] | 197 | test_expect_success GPG 'verifying tag with --format="%(rest)" must fail' ' |
| 198 | test_must_fail git verify-tag --format="%(rest)" "fourth-signed" |
| 199 | ' |
| 200 | |
Santiago Torres | b42ca35 | 2017-03-23 18:28:47 -0400 | [diff] [blame] | 201 | test_expect_success GPG 'verifying a forged tag with --format should fail silently' ' |
Santiago Torres | 02c5433 | 2017-01-17 18:37:22 -0500 | [diff] [blame] | 202 | test_must_fail git verify-tag --format="tagname : %(tag)" $(cat forged1.tag) >actual-forged && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 203 | test_must_be_empty actual-forged |
Santiago Torres | 02c5433 | 2017-01-17 18:37:22 -0500 | [diff] [blame] | 204 | ' |
| 205 | |
brian m. carlson | d66aeff | 2015-06-21 23:14:37 +0000 | [diff] [blame] | 206 | test_done |