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