signed push: fortify against replay attacks
[git/jrn.git] / t / t5534-push-signed.sh
blob6db59ceb32fb8ccb6aeba212a23cb019bc15b049
1 #!/bin/sh
3 test_description='signed push'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-gpg.sh
8 prepare_dst () {
9 rm -fr dst &&
10 test_create_repo dst &&
12 git push dst master:noop master:ff master:noff
15 test_expect_success setup '
16 # master, ff and noff branches pointing at the same commit
17 test_tick &&
18 git commit --allow-empty -m initial &&
20 git checkout -b noop &&
21 git checkout -b ff &&
22 git checkout -b noff &&
24 # noop stays the same, ff advances, noff rewrites
25 test_tick &&
26 git commit --allow-empty --amend -m rewritten &&
27 git checkout ff &&
29 test_tick &&
30 git commit --allow-empty -m second
33 test_expect_success 'unsigned push does not send push certificate' '
34 prepare_dst &&
35 mkdir -p dst/.git/hooks &&
36 write_script dst/.git/hooks/post-receive <<-\EOF &&
37 if test -n "${GIT_PUSH_CERT-}"
38 then
39 git cat-file blob $GIT_PUSH_CERT >../push-cert
41 EOF
43 git push dst noop ff +noff &&
44 test -f dst/push-cert &&
45 ! test -s dst/push-cert
48 test_expect_success GPG 'signed push sends push certificate' '
49 prepare_dst &&
50 mkdir -p dst/.git/hooks &&
51 write_script dst/.git/hooks/post-receive <<-\EOF &&
52 if test -n "${GIT_PUSH_CERT-}"
53 then
54 git cat-file blob $GIT_PUSH_CERT >../push-cert
55 fi &&
57 cat >../push-cert-status <<E_O_F
58 SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
59 KEY=${GIT_PUSH_CERT_KEY-nokey}
60 STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
61 NONCE=${GIT_PUSH_CERT_NONCE-nononce}
62 E_O_F
64 EOF
66 git push --signed dst noop ff +noff &&
69 cat <<-\EOF &&
70 SIGNER=C O Mitter <committer@example.com>
71 KEY=13B6F51ECDDE430D
72 STATUS=G
73 EOF
74 sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert
75 ) >expect &&
77 grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert &&
78 grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert &&
79 test_cmp expect dst/push-cert-status
82 test_done