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 SENDER1="mailto:paul.boddie@example.com" 8 SENDER2="mailto:vincent.vole@example.com" 9 SENDERADDRESS1="paul.boddie@example.com" 10 SENDERADDRESS2="vincent.vole@example.com" 11 QUOTA=cars 12 13 # Test quota enforcement on two resources, first checking whether the resources 14 # can schedule an incoming reservation, then checking whether the reservation 15 # would exceed the organiser's quota applying collectively to both resources. 16 17 # The result should be the first scheduling attempt being declined because it 18 # attempts to reserve an indefinite amount of time, with the second attempt 19 # succeeding but only for one resource because the quota is used up reserving 20 # one of the two resources requested. This reservation is then cancelled. 21 22 # Another attempt is made by a user with a larger quota, and this succeeds in 23 # reserving both resources. 24 25 mkdir -p "$PREFS/$USER1" 26 echo 'Europe/Oslo' > "$PREFS/$USER1/TZID" 27 echo 'share' > "$PREFS/$USER1/freebusy_sharing" 28 cat > "$PREFS/$USER1/scheduling_function" <<EOF 29 schedule_in_freebusy 30 check_quota $QUOTA 31 EOF 32 33 mkdir -p "$PREFS/$USER2" 34 echo 'Europe/Oslo' > "$PREFS/$USER2/TZID" 35 echo 'share' > "$PREFS/$USER2/freebusy_sharing" 36 cat > "$PREFS/$USER2/scheduling_function" <<EOF 37 schedule_in_freebusy 38 check_quota $QUOTA 39 EOF 40 41 cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS 42 mailto:vincent.vole@example.com PT10H 43 * PT5H 44 EOF 45 46 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car-all.txt" 2>> $ERROR \ 47 | "$SHOWMAIL" \ 48 > out0.tmp 49 50 grep -q 'METHOD:REPLY' out0.tmp \ 51 && ! grep -q '^FREEBUSY' out0.tmp \ 52 && echo "Success" \ 53 || echo "Failed" 54 55 # Attempt to schedule an event. 56 57 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars-recurring.txt" 2>> $ERROR 58 59 "$LIST_SCRIPT" $LIST_ARGS "$SENDER1" "freebusy" \ 60 > out0f.tmp 61 62 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out0f.tmp" \ 63 && grep -q "^20141206T150000Z${TAB}20141206T160000Z" "out0f.tmp" \ 64 && echo "Success" \ 65 || echo "Failed" 66 67 # Present the request to the resource. 68 69 "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars-recurring.txt" 2>> $ERROR \ 70 | tee out1r.tmp \ 71 | "$SHOWMAIL" \ 72 > out1.tmp 73 74 grep -q 'METHOD:REPLY' out1.tmp \ 75 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out1.tmp \ 76 && echo "Success" \ 77 || echo "Failed" 78 79 "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \ 80 > out1f.tmp 81 82 "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \ 83 > out1f2.tmp 84 85 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out1f.tmp" \ 86 && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "out1f.tmp" \ 87 && ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out1f2.tmp" \ 88 && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "out1f2.tmp" \ 89 && echo "Success" \ 90 || echo "Failed" 91 92 # Check the quota (event is not confirmed). 93 94 "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER1" \ 95 > out1e.tmp 96 97 ! grep -q "event25@example.com" "out1e.tmp" \ 98 && echo "Success" \ 99 || echo "Failed" 100 101 # Modify the event and attempt to schedule it again. 102 103 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-request-cars-recurring.txt" \ 104 | "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR 105 106 "$LIST_SCRIPT" $LIST_ARGS "$SENDER1" "freebusy" \ 107 > out1s.tmp 108 109 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out1s.tmp" \ 110 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out1s.tmp" \ 111 && echo "Success" \ 112 || echo "Failed" 113 114 # Present the request to the resource. 115 116 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-request-cars-recurring.txt" \ 117 | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ 118 | tee out2r.tmp \ 119 | "$SHOWMAIL" \ 120 > out2.tmp 121 122 # Since the email module used by showmail.py cannot stop after reading a single 123 # message, the second message is obtained. 124 125 "$SHOWMAIL" 1 < out2r.tmp \ 126 >> out2.tmp 127 128 grep -q 'METHOD:REPLY' out2.tmp \ 129 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out2.tmp \ 130 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \ 131 && echo "Success" \ 132 || echo "Failed" 133 134 "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \ 135 > out2f.tmp 136 137 "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \ 138 > out2f2.tmp 139 140 ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out2f.tmp" \ 141 && ! grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out2f.tmp" \ 142 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out2f2.tmp" \ 143 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out2f2.tmp" ) \ 144 || ( ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out2f2.tmp" \ 145 && ! grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out2f2.tmp" \ 146 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out2f.tmp" \ 147 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out2f.tmp" ) \ 148 && echo "Success" \ 149 || echo "Failed" 150 151 # Check the quota (event is confirmed for one resource). 152 153 "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER1" \ 154 > out2e.tmp 155 156 grep -q "event25@example.com" "out2e.tmp" \ 157 && echo "Success" \ 158 || echo "Failed" 159 160 # Cancel the event. 161 162 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-cancel-cars-recurring.txt" \ 163 | "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR 164 165 "$LIST_SCRIPT" $LIST_ARGS "$SENDER1" "freebusy" \ 166 > out2s.tmp 167 168 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out2s.tmp" \ 169 && ! grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out2s.tmp" \ 170 && echo "Success" \ 171 || echo "Failed" 172 173 # Present the request to the resource. 174 175 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-cancel-cars-recurring.txt" \ 176 | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ 177 | tee out3r.tmp \ 178 | "$SHOWMAIL" \ 179 > out3.tmp 180 181 ! grep -q 'METHOD:REPLY' out3.tmp \ 182 && echo "Success" \ 183 || echo "Failed" 184 185 "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \ 186 > out3f.tmp 187 188 "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \ 189 > out3f2.tmp 190 191 ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out3f.tmp" \ 192 && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "out3f.tmp" \ 193 && ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out3f2.tmp" \ 194 && ! grep -q "^20141206T150000Z${TAB}20141206T160000Z" "out3f2.tmp" \ 195 && echo "Success" \ 196 || echo "Failed" 197 198 # Check the quota (event is retracted). 199 200 "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER1" \ 201 > out3e.tmp 202 203 ! grep -q "event25@example.com" "out3e.tmp" \ 204 && echo "Success" \ 205 || echo "Failed" 206 207 # Modify the event and attempt to schedule it again. 208 209 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-request-cars-recurring.txt" \ 210 | sed "s/$SENDERADDRESS1/$SENDERADDRESS2/;" \ 211 | "$OUTGOING_SCRIPT" $ARGS 2>> $ERROR 212 213 "$LIST_SCRIPT" $LIST_ARGS "$SENDER2" "freebusy" \ 214 > out3s.tmp 215 216 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out3s.tmp" \ 217 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out3s.tmp" \ 218 && echo "Success" \ 219 || echo "Failed" 220 221 # Present the request to the resource. 222 223 sed 's/FREQ=DAILY/FREQ=DAILY;COUNT=5/;' "$TEMPLATES/event-request-cars-recurring.txt" \ 224 | sed "s/$SENDERADDRESS1/$SENDERADDRESS2/;" \ 225 | "$RESOURCE_SCRIPT" $ARGS 2>> $ERROR \ 226 | tee out4r.tmp \ 227 | "$SHOWMAIL" \ 228 > out4.tmp 229 230 # Since the email module used by showmail.py cannot stop after reading a single 231 # message, the second message is obtained. 232 233 "$SHOWMAIL" 1 < out4r.tmp \ 234 >> out4.tmp 235 236 grep -q 'METHOD:REPLY' out4.tmp \ 237 && [ `grep 'ATTENDEE.*;PARTSTAT=ACCEPTED' out4.tmp | wc -l` = '2' ] \ 238 && echo "Success" \ 239 || echo "Failed" 240 241 "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \ 242 > out4f.tmp 243 244 "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \ 245 > out4f2.tmp 246 247 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out4f.tmp" \ 248 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out4f.tmp" \ 249 && grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out4f2.tmp" \ 250 && grep -q "^20141130T150000Z${TAB}20141130T160000Z" "out4f2.tmp" \ 251 && echo "Success" \ 252 || echo "Failed" 253 254 # Check the quota (event is confirmed for both resources). 255 256 "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER2" \ 257 > out4e.tmp 258 259 grep -q "event25@example.com" "out4e.tmp" \ 260 && echo "Success" \ 261 || echo "Failed"