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