1#!/bin/sh
23
test_description='signed push'
45
. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-gpg.sh
78
prepare_dst () {
9rm -fr dst &&
10test_create_repo dst &&
1112
git push dst master:noop master:ff master:noff
13}
1415
test_expect_success setup '
16# master, ff and noff branches pointing at the same commit
17test_tick &&
18git commit --allow-empty -m initial &&
1920
git checkout -b noop &&
21git checkout -b ff &&
22git checkout -b noff &&
2324
# noop stays the same, ff advances, noff rewrites
25test_tick &&
26git commit --allow-empty --amend -m rewritten &&
27git checkout ff &&
2829
test_tick &&
30git commit --allow-empty -m second
31'
3233
test_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 list
38cat >/dev/null
39# record the push certificate
40if test -n "${GIT_PUSH_CERT-}"
41then
42git cat-file blob $GIT_PUSH_CERT >../push-cert
43fi
44EOF
4546
git push dst noop ff +noff &&
47! test -f dst/push-cert
48'
4950
test_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 list
55cat >/dev/null
56# record the push certificate
57if test -n "${GIT_PUSH_CERT-}"
58then
59git cat-file blob $GIT_PUSH_CERT >../push-cert
60fi
61EOF
6263
git push dst noop ff +noff &&
64! test -f dst/push-cert
65'
6667
test_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" err
72'
7374
test_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-}"
79then
80git cat-file blob $GIT_PUSH_CERT >../push-cert
81fi
82EOF
83git push dst noop &&
84! test -f dst/push-cert
85'
8687
test_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 list
93cat >/dev/null
94# record the push certificate
95if test -n "${GIT_PUSH_CERT-}"
96then
97git cat-file blob $GIT_PUSH_CERT >../push-cert
98fi &&
99100
cat >../push-cert-status <<E_O_F
101SIGNER=${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_F
107108
EOF
109110
git push --signed dst noop ff +noff &&
111112
(
113cat <<-\EOF &&
114SIGNER=C O Mitter <committer@example.com>
115KEY=13B6F51ECDDE430D
116STATUS=G
117NONCE_STATUS=OK
118EOF
119sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
120) >expect &&
121122
grep "$(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-status
125'
126127
test_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 list
133cat >/dev/null
134# record the push certificate
135if test -n "${GIT_PUSH_CERT-}"
136then
137git cat-file blob $GIT_PUSH_CERT >../push-cert
138fi &&
139140
cat >../push-cert-status <<E_O_F
141SIGNER=${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_F
147148
EOF
149150
unset 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=13B6F51ECDDE430D
160STATUS=G
161NONCE_STATUS=OK
162EOF
163sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
164) >expect &&
165166
grep "$(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-status
169'
170171
test_done