chiark / gitweb /
36d4dab94602cbc87ae0c4d12c040b50635e99be
[dgit.git] / tests / tests / drs-push-rejects
1 #!/bin/bash
2 set -e
3 . tests/lib
4
5 t-drs
6 t-git-none
7
8 p=pari-extra
9 t-worktree drs
10
11 cd $p
12
13 reporefs () {
14         (set -e
15         if test -d $tmp/git/$p.git; then
16                 cd $tmp/git/$p.git
17                 git show-ref
18         fi)
19 }
20
21 mustfail () {
22         local wantmsg="$1"; shift
23         reporefs >$tmp/show-refs.pre-push
24         set +e
25         git push origin "$@" 2>&1 |tee $tmp/mustfail.txt
26         ps="${PIPESTATUS[*]}"
27         set -e
28         case $ps in
29         "0 0")  fail "push unexpectedly succeeded (instead of: $wantmsg)" ;;
30         *" 0")  ;;
31         *)      fail "tee failed"  ;;
32         esac
33         if ! fgrep "$wantmsg" $tmp/mustfail.txt >/dev/null; then
34                 fail "error message not found"
35         fi
36         reporefs >$tmp/show-refs.post-push
37         diff $tmp/show-refs.{pre,post}-push
38 }
39
40 mustsucceed () {
41         reporefs >$tmp/show-refs.pre-push
42         git push origin "$@"
43         reporefs >$tmp/show-refs.post-push
44         if diff $tmp/show-refs.{pre,post}-push >$tmp/show-refs.diff; then
45                 fail "no refs updated"
46         fi
47 }
48
49 prep () {
50         local suite=$1
51         local csuite=$2
52         cp $tmp/masters/* $tmp/.
53         tag_signer='-u Senatus'
54         tag_message="$p release $version for $suite ($csuite) [dgit]"
55         tag_name=debian/$version
56         push_spec1="HEAD:refs/dgit/$csuite"
57         push_spec2="refs/tags/$tag_name"
58         push_spec="$push_spec1 $push_spec2"
59 }
60 mktag () {
61         git tag -f $tag_signer -m "$tag_message" $tag_name "$@"
62 }
63
64 mkdir $tmp/masters
65 cp $tmp/d[dm].* $tmp/masters
66
67 version=3-2_dummy1
68
69 prep unstable sid
70 tag_signer='-a'
71 mktag
72 mustfail 'missing signature' $push_spec
73
74 git cat-file tag $tag_name >goodtag
75
76 for h in object type tag; do
77   for how in missing dupe; do
78
79     case $how in
80     missing) perl -pe 's/^tag /wombat$&/ if 1..m/^$/'  <goodtag >badtag ;;
81     dupe)   perl -pe 'print if 1..m/^$/ and m/^'$h' /' <goodtag >badtag ;;
82     esac
83
84     rm -f badtag.asc
85     gpg --detach-sign --armor -u Senatus badtag
86     cat badtag.asc >>badtag
87
88     set +e
89     LC_ALL=C git hash-object -w -t tag badtag >badtag.hash 2>badtag.err
90     rc=$?
91     set -e
92
93     if [ $rc = 128 ] && grep 'fatal: corrupt tag' badtag.err; then
94       continue
95     elif [ $rc != 0 ]; then
96       cat badtag.err
97       fail "could not make tag"
98     fi
99
100     read <badtag.hash badtag
101     git update-ref refs/tags/$tag_name $badtag
102
103     mustfail 'multiple headers '$h' in signed tag object' $push_spec
104   done
105 done
106
107 prep unstable sid
108 tag_message='something'
109 mktag
110 mustfail 'tag message not in expected format' $push_spec
111
112 prep unstable sid
113 mktag
114 mustfail 'sid != sponge' HEAD:refs/dgit/sponge $push_spec2
115
116 # fixme test --sig-policy-url string
117 # fixme cannot test   reject "signature is not of type 00!";
118
119 prep unstable sid
120 mktag
121 mustfail 'push is missing tag ref update' $push_spec1
122 mustfail 'push is missing head ref update' $push_spec2
123 mustfail 'pushing unexpected ref' $push_spec HEAD:refs/wombat
124 mustfail 'pushing multiple heads' $push_spec HEAD:refs/dgit/wombat
125 mustfail 'pushing multiple tags' $push_spec HEAD:refs/tags/debian/wombat
126
127 # fixme:
128 #    reject "unknown suite";
129 #    or reject "command string not understood";
130 #    reject "unknown method" unless $mainfunc;
131
132
133 prep unstable sid
134 mktag
135 cp $tmp/dm.gpg $tmp/dd.gpg
136 mustfail 'key not found in keyrings' $push_spec
137
138 prep unstable sid
139 mktag HEAD~
140 mustfail 'tag refers to wrong commit' $push_spec
141
142 prep unstable sid
143 mktag HEAD~:
144 mustfail 'tag refers to wrong kind of object' $push_spec
145
146 prep unstable sid
147 tag_name=debian/wombat
148 mktag
149 #git update-ref debian/$version debian/wombat
150 mustfail 'tag name in tag is wrong' \
151         refs/tags/debian/wombat:refs/tags/debian/$version $push_spec1
152
153 prep unstable sid
154 mktag
155 mustsucceed $push_spec # succeeds
156
157 mktag
158 mustfail 'not replacing previously-pushed version' $push_spec
159
160 prep_dm_mangle () {
161         prep unstable sid
162         perl -i.bak -pe '
163                 next unless m/^fingerprint: 3A82860837A0CD32/i../^$/;
164         ' -e "$1" $tmp/dm.txt
165         tag_signer='-u Populus'
166         mktag
167 }
168
169 git commit --amend --message 'Make it not a fast forward'
170 version=3-2_dummy2
171 prep unstable sid
172 mktag
173 mustfail 'not fast forward on dgit branch' +$push_spec1 +$push_spec2
174
175 git checkout v2
176 version=3-2_dummy2
177
178 prep_dm_mangle ''
179 perl -i.bak -ne 'print if 1..s/(pari-extra).*\n/$1/' $tmp/dm.txt
180 mustfail '' $push_spec # malformed (truncated) dm.txt; don't care about msg
181
182 prep_dm_mangle 's/allow:/asponge:/i'
183 mustfail 'missing Allow section in permission' $push_spec
184
185 prep_dm_mangle 's/\bpari-extra\b/sponge/i'
186 mustfail "package $p not allowed for key" $push_spec
187
188 prep_dm_mangle 'y/0-9/5-90-4/ if m/^fingerprint:/i'
189 mustfail "not in permissions list although in keyring" $push_spec
190
191 prep_dm_mangle ''
192 mustsucceed $push_spec # succeeds
193
194 echo ok.