@@ -103,71 +103,81 @@ test_expect_success GPG 'strip both OpenPGP signatures with --signed-commits=war
103103 test_line_count = 2 out
104104'
105105
106- test_expect_success GPG ' import commit with no signature with --signed-commits=strip-if-invalid' '
107- git fast-export main >output &&
108- git -C new fast-import --quiet --signed-commits=strip-if-invalid <output >log 2>&1 &&
109- test_must_be_empty log
110- '
111-
112- test_expect_success GPG ' keep valid OpenPGP signature with --signed-commits=strip-if-invalid' '
113- rm -rf new &&
114- git init new &&
115-
116- git fast-export --signed-commits=verbatim openpgp-signing >output &&
117- git -C new fast-import --quiet --signed-commits=strip-if-invalid <output >log 2>&1 &&
118- IMPORTED=$(git -C new rev-parse --verify refs/heads/openpgp-signing) &&
119- test $OPENPGP_SIGNING = $IMPORTED &&
120- git -C new cat-file commit "$IMPORTED" >actual &&
121- test_grep -E "^gpgsig(-sha256)? " actual &&
122- test_must_be_empty log
123- '
124-
125- test_expect_success GPG ' strip signature invalidated by message change with --signed-commits=strip-if-invalid' '
126- rm -rf new &&
127- git init new &&
128-
129- git fast-export --signed-commits=verbatim openpgp-signing >output &&
130-
131- # Change the commit message, which invalidates the signature.
132- # The commit message length should not change though, otherwise the
133- # corresponding `data <length>` command would have to be changed too.
134- sed "s/OpenPGP signed commit/OpenPGP forged commit/" output >modified &&
135-
136- git -C new fast-import --quiet --signed-commits=strip-if-invalid <modified >log 2>&1 &&
137-
138- IMPORTED=$(git -C new rev-parse --verify refs/heads/openpgp-signing) &&
139- test $OPENPGP_SIGNING != $IMPORTED &&
140- git -C new cat-file commit "$IMPORTED" >actual &&
141- test_grep ! -E "^gpgsig" actual &&
142- test_grep "stripping invalid signature" log
143- '
144-
145- test_expect_success GPGSM ' keep valid X.509 signature with --signed-commits=strip-if-invalid' '
146- rm -rf new &&
147- git init new &&
148-
149- git fast-export --signed-commits=verbatim x509-signing >output &&
150- git -C new fast-import --quiet --signed-commits=strip-if-invalid <output >log 2>&1 &&
151- IMPORTED=$(git -C new rev-parse --verify refs/heads/x509-signing) &&
152- test $X509_SIGNING = $IMPORTED &&
153- git -C new cat-file commit "$IMPORTED" >actual &&
154- test_grep -E "^gpgsig(-sha256)? " actual &&
155- test_must_be_empty log
156- '
157-
158- test_expect_success GPGSSH ' keep valid SSH signature with --signed-commits=strip-if-invalid' '
159- rm -rf new &&
160- git init new &&
161-
162- test_config -C new gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
163-
164- git fast-export --signed-commits=verbatim ssh-signing >output &&
165- git -C new fast-import --quiet --signed-commits=strip-if-invalid <output >log 2>&1 &&
166- IMPORTED=$(git -C new rev-parse --verify refs/heads/ssh-signing) &&
167- test $SSH_SIGNING = $IMPORTED &&
168- git -C new cat-file commit "$IMPORTED" >actual &&
169- test_grep -E "^gpgsig(-sha256)? " actual &&
170- test_must_be_empty log
171- '
106+ for mode in strip-if-invalid resign-if-invalid
107+ do
108+ test_expect_success GPG " import commit with no signature with --signed-commits=$mode " '
109+ git fast-export main >output &&
110+ git -C new fast-import --quiet --signed-commits=$mode <output >log 2>&1 &&
111+ test_must_be_empty log
112+ '
113+
114+ test_expect_success GPG " keep valid OpenPGP signature with --signed-commits=$mode " '
115+ rm -rf new &&
116+ git init new &&
117+
118+ git fast-export --signed-commits=verbatim openpgp-signing >output &&
119+ git -C new fast-import --quiet --signed-commits=$mode <output >log 2>&1 &&
120+ IMPORTED=$(git -C new rev-parse --verify refs/heads/openpgp-signing) &&
121+ test $OPENPGP_SIGNING = $IMPORTED &&
122+ git -C new cat-file commit "$IMPORTED" >actual &&
123+ test_grep -E "^gpgsig(-sha256)? " actual &&
124+ test_must_be_empty log
125+ '
126+
127+ test_expect_success GPG " strip signature invalidated by message change with --signed-commits=$mode " '
128+ rm -rf new &&
129+ git init new &&
130+
131+ git fast-export --signed-commits=verbatim openpgp-signing >output &&
132+
133+ # Change the commit message, which invalidates the signature.
134+ # The commit message length should not change though, otherwise the
135+ # corresponding `data <length>` command would have to be changed too.
136+ sed "s/OpenPGP signed commit/OpenPGP forged commit/" output >modified &&
137+
138+ git -C new fast-import --quiet --signed-commits=$mode <modified >log 2>&1 &&
139+
140+ IMPORTED=$(git -C new rev-parse --verify refs/heads/openpgp-signing) &&
141+ test $OPENPGP_SIGNING != $IMPORTED &&
142+ git -C new cat-file commit "$IMPORTED" >actual &&
143+ test_grep "stripping invalid signature" log &&
144+
145+ if test "$mode" = strip-if-invalid
146+ then
147+ test_grep ! -E "^gpgsig" actual
148+ else
149+ test_grep -E "^gpgsig(-sha256)? " actual &&
150+ git -C new verify-commit "$IMPORTED"
151+ fi
152+ '
153+
154+ test_expect_success GPGSM " keep valid X.509 signature with --signed-commits=$mode " '
155+ rm -rf new &&
156+ git init new &&
157+
158+ git fast-export --signed-commits=verbatim x509-signing >output &&
159+ git -C new fast-import --quiet --signed-commits=$mode <output >log 2>&1 &&
160+ IMPORTED=$(git -C new rev-parse --verify refs/heads/x509-signing) &&
161+ test $X509_SIGNING = $IMPORTED &&
162+ git -C new cat-file commit "$IMPORTED" >actual &&
163+ test_grep -E "^gpgsig(-sha256)? " actual &&
164+ test_must_be_empty log
165+ '
166+
167+ test_expect_success GPGSSH " keep valid SSH signature with --signed-commits=$mode " '
168+ rm -rf new &&
169+ git init new &&
170+
171+ test_config -C new gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
172+
173+ git fast-export --signed-commits=verbatim ssh-signing >output &&
174+ git -C new fast-import --quiet --signed-commits=$mode <output >log 2>&1 &&
175+ IMPORTED=$(git -C new rev-parse --verify refs/heads/ssh-signing) &&
176+ test $SSH_SIGNING = $IMPORTED &&
177+ git -C new cat-file commit "$IMPORTED" >actual &&
178+ test_grep -E "^gpgsig(-sha256)? " actual &&
179+ test_must_be_empty log
180+ '
181+ done
172182
173183test_done
0 commit comments