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