1 #!/bin/sh 2 3 . "`dirname \"$0\"`/common.sh" 4 5 USER1="mailto:resource-car-porsche911@example.com" 6 USER2="mailto:resource-car-fiat500@example.com" 7 SENDER="mailto:paul.boddie@example.com" 8 FBFILE1="$STORE/$USER1/freebusy" 9 FBFILE2="$STORE/$USER2/freebusy" 10 FBSENDERFILE="$STORE/$SENDER/freebusy" 11 QUOTA=cars 12 JOURNALFILE="$JOURNAL/$QUOTA/journal/$SENDER" 13 14 mkdir -p "$PREFS/$USER1" 15 echo 'Europe/Oslo' > "$PREFS/$USER1/TZID" 16 echo 'share' > "$PREFS/$USER1/freebusy_sharing" 17 cat > "$PREFS/$USER1/scheduling_function" <<EOF 18 schedule_in_freebusy 19 check_quota $QUOTA 20 EOF 21 22 mkdir -p "$PREFS/$USER2" 23 echo 'Europe/Oslo' > "$PREFS/$USER2/TZID" 24 echo 'share' > "$PREFS/$USER2/freebusy_sharing" 25 cat > "$PREFS/$USER2/scheduling_function" <<EOF 26 schedule_in_freebusy 27 check_quota $QUOTA 28 EOF 29 30 mkdir -p "$JOURNAL/$QUOTA" 31 echo '* PT1H' > "$JOURNAL/$QUOTA/limits" 32 33 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car.txt" 2>> $ERROR \ 34 | "$SHOWMAIL" \ 35 > out0.tmp 36 37 grep -q 'METHOD:REPLY' out0.tmp \ 38 && ! grep -q '^FREEBUSY' out0.tmp \ 39 && echo "Success" \ 40 || echo "Failed" 41 42 # Attempt to schedule an event. 43 44 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR 45 46 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ 47 && echo "Success" \ 48 || echo "Failed" 49 50 # Present the request to the resource. 51 52 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \ 53 | tee out1r.tmp \ 54 | "$SHOWMAIL" \ 55 > out1.tmp 56 57 grep -q 'METHOD:REPLY' out1.tmp \ 58 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out1.tmp \ 59 && echo "Success" \ 60 || echo "Failed" 61 62 [ -e "$FBFILE1" ] \ 63 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \ 64 && echo "Success" \ 65 || echo "Failed" 66 67 # Check the quota (event is confirmed). 68 69 [ -e "$JOURNALFILE" ] \ 70 && grep -q "event21@example.com" "$JOURNALFILE" \ 71 && echo "Success" \ 72 || echo "Failed" 73 74 # Attempt to schedule another event. 75 76 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR 77 78 grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBSENDERFILE" \ 79 && echo "Success" \ 80 || echo "Failed" 81 82 # Present the request to the resource. 83 84 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \ 85 | tee out2r.tmp \ 86 | "$SHOWMAIL" \ 87 > out2.tmp 88 89 grep -q 'METHOD:REPLY' out2.tmp \ 90 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \ 91 && echo "Success" \ 92 || echo "Failed" 93 94 ! [ -e "$FBFILE2" ] \ 95 || ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \ 96 && echo "Success" \ 97 || echo "Failed" 98 99 # Check the quota (event is not confirmed). 100 101 [ -e "$JOURNALFILE" ] \ 102 && grep -q "event21@example.com" "$JOURNALFILE" \ 103 && ! grep -q "event22@example.com" "$JOURNALFILE" \ 104 && echo "Success" \ 105 || echo "Failed" 106 107 # Increase the quota. 108 109 echo '* PT2H' > "$JOURNAL/$QUOTA/limits" 110 111 # Attempt to schedule the event again. 112 113 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR 114 115 grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBSENDERFILE" \ 116 && echo "Success" \ 117 || echo "Failed" 118 119 # Present the request to the resource. 120 121 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \ 122 | tee out3r.tmp \ 123 | "$SHOWMAIL" \ 124 > out3.tmp 125 126 grep -q 'METHOD:REPLY' out3.tmp \ 127 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out3.tmp \ 128 && echo "Success" \ 129 || echo "Failed" 130 131 [ -e "$FBFILE2" ] \ 132 && grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \ 133 && echo "Success" \ 134 || echo "Failed" 135 136 # Check the quota (event is confirmed). 137 138 [ -e "$JOURNALFILE" ] \ 139 && grep -q "event21@example.com" "$JOURNALFILE" \ 140 && grep -q "event22@example.com" "$JOURNALFILE" \ 141 && echo "Success" \ 142 || echo "Failed" 143 144 # Cancel the first event. 145 146 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR 147 148 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ 149 && echo "Success" \ 150 || echo "Failed" 151 152 # Present the request to the resource. 153 154 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR \ 155 | tee out4r.tmp \ 156 | "$SHOWMAIL" \ 157 > out4.tmp 158 159 ! grep -q 'METHOD:REPLY' out4.tmp \ 160 && echo "Success" \ 161 || echo "Failed" 162 163 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \ 164 && echo "Success" \ 165 || echo "Failed" 166 167 # Check the quota (event is retracted). 168 169 [ -e "$JOURNALFILE" ] \ 170 && ! grep -q "event21@example.com" "$JOURNALFILE" \ 171 && grep -q "event22@example.com" "$JOURNALFILE" \ 172 && echo "Success" \ 173 || echo "Failed" 174 175 # Add collective scheduling tests. 176 177 cat > "$PREFS/$USER1/scheduling_function" <<EOF 178 schedule_in_freebusy 179 schedule_across_quota $QUOTA 180 check_quota $QUOTA 181 EOF 182 183 cat > "$PREFS/$USER2/scheduling_function" <<EOF 184 schedule_in_freebusy 185 schedule_across_quota $QUOTA 186 check_quota $QUOTA 187 EOF 188 189 # Remind the resource about the second event. 190 191 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \ 192 | tee out5r.tmp \ 193 | "$SHOWMAIL" \ 194 > out5.tmp 195 196 grep -q 'METHOD:REPLY' out5.tmp \ 197 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out5.tmp \ 198 && echo "Success" \ 199 || echo "Failed" 200 201 [ -e "$FBFILE2" ] \ 202 && grep -q "^20141126T153000Z${TAB}20141126T163000Z" "$FBFILE2" \ 203 && echo "Success" \ 204 || echo "Failed" 205 206 # Check the quota (event is still confirmed). 207 208 [ -e "$JOURNALFILE" ] \ 209 && ! grep -q "event21@example.com" "$JOURNALFILE" \ 210 && grep -q "event22@example.com" "$JOURNALFILE" \ 211 && echo "Success" \ 212 || echo "Failed" 213 214 # Attempt to schedule the first event. 215 216 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR 217 218 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ 219 && echo "Success" \ 220 || echo "Failed" 221 222 # Present the request to the resource. 223 224 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \ 225 | tee out6r.tmp \ 226 | "$SHOWMAIL" \ 227 > out6.tmp 228 229 grep -q 'METHOD:REPLY' out6.tmp \ 230 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out6.tmp \ 231 && echo "Success" \ 232 || echo "Failed" 233 234 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE1" \ 235 && echo "Success" \ 236 || echo "Failed" 237 238 # Check the quota (event is still retracted and not newly confirmed). 239 240 [ -e "$JOURNALFILE" ] \ 241 && ! grep -q "event21@example.com" "$JOURNALFILE" \ 242 && grep -q "event22@example.com" "$JOURNALFILE" \ 243 && echo "Success" \ 244 || echo "Failed" 245 246 # Attempt to schedule the first event moved earlier. 247 248 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR 249 250 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBSENDERFILE" \ 251 && grep -q "^20141126T143000Z${TAB}20141126T153000Z" "$FBSENDERFILE" \ 252 && echo "Success" \ 253 || echo "Failed" 254 255 # Present the request to the resource. 256 257 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR \ 258 | tee out7r.tmp \ 259 | "$SHOWMAIL" \ 260 > out7.tmp 261 262 grep -q 'METHOD:REPLY' out7.tmp \ 263 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out7.tmp \ 264 && echo "Success" \ 265 || echo "Failed" 266 267 grep -q "^20141126T143000Z${TAB}20141126T153000Z" "$FBFILE1" \ 268 && echo "Success" \ 269 || echo "Failed" 270 271 # Check the quota (event is newly confirmed). 272 273 [ -e "$JOURNALFILE" ] \ 274 && grep -q "event21@example.com" "$JOURNALFILE" \ 275 && grep -q "event22@example.com" "$JOURNALFILE" \ 276 && echo "Success" \ 277 || echo "Failed" 278 279 # Increase the quota. 280 281 echo '* PT3H' > "$JOURNAL/$QUOTA/limits" 282 283 # Attempt to schedule an event involving both resources. 284 285 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR 286 287 grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBSENDERFILE" \ 288 && echo "Success" \ 289 || echo "Failed" 290 291 # Present the request to both resources. 292 293 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR \ 294 | tee out8r.tmp \ 295 | "$SHOWMAIL" \ 296 > out8.tmp 297 298 # Since the email module used by showmail.py cannot stop after reading a single 299 # message, the second message is obtained. 300 301 grep -n '^From ' out8r.tmp \ 302 | tail -n 1 \ 303 | cut -d ':' -f 1 \ 304 | xargs -I{} tail -n +'{}' out8r.tmp \ 305 | "$SHOWMAIL" \ 306 >> out8.tmp 307 308 grep -q 'METHOD:REPLY' out8.tmp \ 309 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out8.tmp \ 310 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out8.tmp \ 311 && echo "Success" \ 312 || echo "Failed" 313 314 ( grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE1" \ 315 && ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE2" ) \ 316 || ( ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE1" \ 317 && grep -q "^20141127T150000Z${TAB}20141127T160000Z" "$FBFILE2" ) \ 318 && echo "Success" \ 319 || echo "Failed" 320 321 # Check the quota (event is confirmed, but only for one resource). 322 323 [ -e "$JOURNALFILE" ] \ 324 && grep -q "event23@example.com" "$JOURNALFILE" \ 325 && echo "Success" \ 326 || echo "Failed"