1#!/bin/sh23test_description='signed push'45. ./test-lib.sh6. "$TEST_DIRECTORY"/lib-gpg.sh78prepare_dst () {9rm -fr dst &&10test_create_repo dst &&1112git push dst master:noop master:ff master:noff13}1415test_expect_success setup '16# master, ff and noff branches pointing at the same commit17test_tick &&18git commit --allow-empty -m initial &&1920git checkout -b noop &&21git checkout -b ff &&22git checkout -b noff &&2324# noop stays the same, ff advances, noff rewrites25test_tick &&26git commit --allow-empty --amend -m rewritten &&27git checkout ff &&2829test_tick &&30git commit --allow-empty -m second31'3233test_expect_success 'unsigned push does not send push certificate' '34prepare_dst &&35mkdir -p dst/.git/hooks &&36write_script dst/.git/hooks/post-receive <<-\EOF &&37# discard the update list38cat >/dev/null39# record the push certificate40if test -n "${GIT_PUSH_CERT-}"41then42git cat-file blob $GIT_PUSH_CERT >../push-cert43fi44EOF4546git push dst noop ff +noff &&47! test -f dst/push-cert48'4950test_expect_success 'talking with a receiver without push certificate support' '51prepare_dst &&52mkdir -p dst/.git/hooks &&53write_script dst/.git/hooks/post-receive <<-\EOF &&54# discard the update list55cat >/dev/null56# record the push certificate57if test -n "${GIT_PUSH_CERT-}"58then59git cat-file blob $GIT_PUSH_CERT >../push-cert60fi61EOF6263git push dst noop ff +noff &&64! test -f dst/push-cert65'6667test_expect_success 'push --signed fails with a receiver without push certificate support' '68prepare_dst &&69mkdir -p dst/.git/hooks &&70test_must_fail git push --signed dst noop ff +noff 2>err &&71test_i18ngrep "the receiving end does not support" err72'7374test_expect_success GPG 'no certificate for a signed push with no update' '75prepare_dst &&76mkdir -p dst/.git/hooks &&77write_script dst/.git/hooks/post-receive <<-\EOF &&78if test -n "${GIT_PUSH_CERT-}"79then80git cat-file blob $GIT_PUSH_CERT >../push-cert81fi82EOF83git push dst noop &&84! test -f dst/push-cert85'8687test_expect_success GPG 'signed push sends push certificate' '88prepare_dst &&89mkdir -p dst/.git/hooks &&90git -C dst config receive.certnonceseed sekrit &&91write_script dst/.git/hooks/post-receive <<-\EOF &&92# discard the update list93cat >/dev/null94# record the push certificate95if test -n "${GIT_PUSH_CERT-}"96then97git cat-file blob $GIT_PUSH_CERT >../push-cert98fi &&99100cat >../push-cert-status <<E_O_F101SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}102KEY=${GIT_PUSH_CERT_KEY-nokey}103STATUS=${GIT_PUSH_CERT_STATUS-nostatus}104NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}105NONCE=${GIT_PUSH_CERT_NONCE-nononce}106E_O_F107108EOF109110git push --signed dst noop ff +noff &&111112(113cat <<-\EOF &&114SIGNER=C O Mitter <committer@example.com>115KEY=13B6F51ECDDE430D116STATUS=G117NONCE_STATUS=OK118EOF119sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert120) >expect &&121122grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert &&123grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert &&124test_cmp expect dst/push-cert-status125'126127test_expect_success GPG 'fail without key and heed user.signingkey' '128prepare_dst &&129mkdir -p dst/.git/hooks &&130git -C dst config receive.certnonceseed sekrit &&131write_script dst/.git/hooks/post-receive <<-\EOF &&132# discard the update list133cat >/dev/null134# record the push certificate135if test -n "${GIT_PUSH_CERT-}"136then137git cat-file blob $GIT_PUSH_CERT >../push-cert138fi &&139140cat >../push-cert-status <<E_O_F141SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}142KEY=${GIT_PUSH_CERT_KEY-nokey}143STATUS=${GIT_PUSH_CERT_STATUS-nostatus}144NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}145NONCE=${GIT_PUSH_CERT_NONCE-nononce}146E_O_F147148EOF149150unset GIT_COMMITTER_EMAIL &&151git config user.email hasnokey@nowhere.com &&152test_must_fail git push --signed dst noop ff +noff &&153git config user.signingkey committer@example.com &&154git push --signed dst noop ff +noff &&155156(157cat <<-\EOF &&158SIGNER=C O Mitter <committer@example.com>159KEY=13B6F51ECDDE430D160STATUS=G161NONCE_STATUS=OK162EOF163sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert164) >expect &&165166grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert &&167grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert &&168test_cmp expect dst/push-cert-status169'170171test_done