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