imip-agent

tests/test_resource_invitation_constraints_quota.sh

1261:1aa985ba6e76
2017-09-13 Paul Boddie Moved period removal logic into the data module.
     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 QUOTA=cars     9 OTHER_QUOTA=rooms    10     11 # Test quota enforcement where no limits apply, with resources first attempting    12 # to schedule reservations before checking a quota applying to both resources.    13     14 # The result should be a scheduling attempt with the first resource succeeding,    15 # but another with the second resource being declined due to a lack of quota.    16 # An adjustment to the quota then permits the successful reservation of the    17 # second resource. The first reservation is then cancelled.    18     19 # Quota-wide free/busy validation is then enabled, and the reservation of the    20 # second resource is replayed to allow the journal to maintain the free/busy    21 # details of the organiser. Now, when an attempt is made to reserve the first    22 # resource at the same time once again, this fails because the journal now knows    23 # that the organiser is occupied during the period in question. Moving the    24 # reservation of the first resource leads to a successful booking.    25     26 # Meanwhile, raising the quota once again and attempting to reserve both    27 # resources using a separate event leads to only one resource being booked due    28 # to a lack of quota.    29     30 mkdir -p "$PREFS/$USER1"    31 echo 'Europe/Oslo' > "$PREFS/$USER1/TZID"    32 echo 'share' > "$PREFS/$USER1/freebusy_sharing"    33 cat > "$PREFS/$USER1/scheduling_function" <<EOF    34 schedule_in_freebusy    35 check_quota $QUOTA    36 EOF    37     38 mkdir -p "$PREFS/$USER2"    39 echo 'Europe/Oslo' > "$PREFS/$USER2/TZID"    40 echo 'share' > "$PREFS/$USER2/freebusy_sharing"    41 cat > "$PREFS/$USER2/scheduling_function" <<EOF    42 schedule_in_freebusy    43 check_quota $QUOTA    44 EOF    45     46 cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS    47 * PT1H    48 EOF    49 cat <<EOF | "$SET_QUOTA_LIMITS" "$OTHER_QUOTA" $SET_QUOTA_LIMITS_ARGS    50 * PT1H    51 EOF    52     53   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/fb-request-car.txt" 2>> $ERROR \    54 | "$SHOWMAIL" \    55 > out0.tmp    56     57    grep -q 'METHOD:REPLY' out0.tmp \    58 && ! grep -q '^FREEBUSY' out0.tmp \    59 && echo "Success" \    60 || echo "Failed"    61     62 # Attempt to schedule an event.    63     64 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR    65     66    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \    67 |  tee out0s.tmp \    68 |  grep -q "^20141126T150000Z${TAB}20141126T160000Z" \    69 && echo "Success" \    70 || echo "Failed"    71     72 # Present the request to the resource.    73     74   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \    75 | tee out1r.tmp \    76 | "$SHOWMAIL" \    77 > out1.tmp    78     79    grep -q 'METHOD:REPLY' out1.tmp \    80 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out1.tmp \    81 && echo "Success" \    82 || echo "Failed"    83     84    "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \    85 |  tee out1f.tmp \    86 |  grep -q "^20141126T150000Z${TAB}20141126T160000Z" \    87 && echo "Success" \    88 || echo "Failed"    89     90 # Check the quota (event is confirmed).    91     92    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \    93 |  tee out1e.tmp \    94 |  grep -q "event21@example.com" \    95 && echo "Success" \    96 || echo "Failed"    97     98 # Attempt to schedule another event.    99    100 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR   101    102    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   103 |  tee out1s.tmp \   104 |  grep -q "^20141126T153000Z${TAB}20141126T163000Z" \   105 && echo "Success" \   106 || echo "Failed"   107    108 # Present the request to the resource.   109    110   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \   111 | tee out2r.tmp \   112 | "$SHOWMAIL" \   113 > out2.tmp   114    115    grep -q 'METHOD:REPLY' out2.tmp \   116 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out2.tmp \   117 && echo "Success" \   118 || echo "Failed"   119    120    "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \   121 >  out2f.tmp   122    123    ! grep -q "^20141126T153000Z${TAB}20141126T163000Z" "out2f.tmp" \   124 && echo "Success" \   125 || echo "Failed"   126    127 # Check the quota (event is not confirmed).   128    129    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   130 >  out2e.tmp   131    132    grep -q "event21@example.com" "out2e.tmp" \   133 && ! grep -q "event22@example.com" "out2e.tmp" \   134 && echo "Success" \   135 || echo "Failed"   136    137 # Increase the quota.   138    139 cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS   140 * PT2H   141 EOF   142    143 # Attempt to schedule the event again.   144    145 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR   146    147    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   148 |  tee out2s.tmp \   149 |  grep -q "^20141126T153000Z${TAB}20141126T163000Z" \   150 && echo "Success" \   151 || echo "Failed"   152    153 # Present the request to the resource.   154    155   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \   156 | tee out3r.tmp \   157 | "$SHOWMAIL" \   158 > out3.tmp   159    160    grep -q 'METHOD:REPLY' out3.tmp \   161 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out3.tmp \   162 && echo "Success" \   163 || echo "Failed"   164    165    "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \   166 |  tee out3f.tmp \   167 |  grep -q "^20141126T153000Z${TAB}20141126T163000Z" \   168 && echo "Success" \   169 || echo "Failed"   170    171 # Check the quota (event is confirmed).   172    173    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   174 >  out3e.tmp   175    176    grep -q "event21@example.com" "out3e.tmp" \   177 && grep -q "event22@example.com" "out3e.tmp" \   178 && echo "Success" \   179 || echo "Failed"   180    181 # Cancel the first event.   182    183 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR   184    185    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   186 >  out3s.tmp   187    188    ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out3s.tmp" \   189 && echo "Success" \   190 || echo "Failed"   191    192 # Present the request to the resource.   193    194   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-cancel-car.txt" 2>> $ERROR \   195 | tee out4r.tmp \   196 | "$SHOWMAIL" \   197 > out4.tmp   198    199    ! grep -q 'METHOD:REPLY' out4.tmp \   200 && echo "Success" \   201 || echo "Failed"   202    203    "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \   204 >  out4f.tmp   205    206    ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out4f.tmp" \   207 && echo "Success" \   208 || echo "Failed"   209    210 # Check the quota (event is retracted).   211    212    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   213 >  out4e.tmp   214    215    ! grep -q "event21@example.com" "out4e.tmp" \   216 && grep -q "event22@example.com" "out4e.tmp" \   217 && echo "Success" \   218 || echo "Failed"   219    220 # Add collective scheduling tests.   221    222 cat > "$PREFS/$USER1/scheduling_function" <<EOF   223 schedule_in_freebusy   224 schedule_across_quota $QUOTA   225 check_quota $QUOTA   226 EOF   227    228 cat > "$PREFS/$USER2/scheduling_function" <<EOF   229 schedule_in_freebusy   230 schedule_across_quota $QUOTA   231 check_quota $QUOTA   232 EOF   233    234 # Remind the resource about the second event.   235    236   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-conflict.txt" 2>> $ERROR \   237 | tee out5r.tmp \   238 | "$SHOWMAIL" \   239 > out5.tmp   240    241    grep -q 'METHOD:REPLY' out5.tmp \   242 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out5.tmp \   243 && echo "Success" \   244 || echo "Failed"   245    246    "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \   247 |  tee out5f.tmp \   248 |  grep -q "^20141126T153000Z${TAB}20141126T163000Z" \   249 && echo "Success" \   250 || echo "Failed"   251    252 # Check the quota (event is still confirmed).   253    254    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   255 >  out5e.tmp   256    257    ! grep -q "event21@example.com" "out5e.tmp" \   258 && grep -q "event22@example.com" "out5e.tmp" \   259 && echo "Success" \   260 || echo "Failed"   261    262 # Attempt to schedule the first event.   263    264 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR   265    266    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   267 |  tee out5s.tmp \   268 |  grep -q "^20141126T150000Z${TAB}20141126T160000Z" \   269 && echo "Success" \   270 || echo "Failed"   271    272 # Present the request to the resource.   273    274   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car.txt" 2>> $ERROR \   275 | tee out6r.tmp \   276 | "$SHOWMAIL" \   277 > out6.tmp   278    279    grep -q 'METHOD:REPLY' out6.tmp \   280 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out6.tmp \   281 && echo "Success" \   282 || echo "Failed"   283    284    "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \   285 >  out6f.tmp   286    287    ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out6f.tmp" \   288 && echo "Success" \   289 || echo "Failed"   290    291 # Check the quota (event is still retracted and not newly confirmed).   292    293    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   294 >  out6e.tmp   295    296    ! grep -q "event21@example.com" "out6e.tmp" \   297 && grep -q "event22@example.com" "out6e.tmp" \   298 && echo "Success" \   299 || echo "Failed"   300    301 # Attempt to schedule the first event moved earlier.   302    303 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR   304    305    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   306 >  out6s.tmp   307    308    ! grep -q "^20141126T150000Z${TAB}20141126T160000Z" "out6s.tmp" \   309 && grep -q "^20141126T143000Z${TAB}20141126T153000Z" "out6s.tmp" \   310 && echo "Success" \   311 || echo "Failed"   312    313 # Present the request to the resource.   314    315   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-car-moved.txt" 2>> $ERROR \   316 | tee out7r.tmp \   317 | "$SHOWMAIL" \   318 > out7.tmp   319    320    grep -q 'METHOD:REPLY' out7.tmp \   321 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out7.tmp \   322 && echo "Success" \   323 || echo "Failed"   324    325    "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \   326 |  tee out7f.tmp \   327 |  grep -q "^20141126T143000Z${TAB}20141126T153000Z" \   328 && echo "Success" \   329 || echo "Failed"   330    331 # Check the quota (event is newly confirmed).   332    333    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   334 >  out7e.tmp   335    336    grep -q "event21@example.com" "out7e.tmp" \   337 && grep -q "event22@example.com" "out7e.tmp" \   338 && echo "Success" \   339 || echo "Failed"   340    341 # Increase the quota.   342    343 cat <<EOF | "$SET_QUOTA_LIMITS" "$QUOTA" $SET_QUOTA_LIMITS_ARGS   344 * PT3H   345 EOF   346    347 # Attempt to schedule an event involving both resources.   348    349 "$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR   350    351    "$LIST_SCRIPT" $LIST_ARGS "$SENDER" "freebusy" \   352 |  tee out7s.tmp \   353 |  grep -q "^20141127T150000Z${TAB}20141127T160000Z" \   354 && echo "Success" \   355 || echo "Failed"   356    357 # Present the request to both resources.   358    359   "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-cars.txt" 2>> $ERROR \   360 | tee out8r.tmp \   361 | "$SHOWMAIL" \   362 > out8.tmp   363    364 # Since the email module used by showmail.py cannot stop after reading a single   365 # message, the second message is obtained.   366    367   "$SHOWMAIL" 1 < out8r.tmp \   368 >> out8.tmp   369    370    grep -q 'METHOD:REPLY' out8.tmp \   371 && grep -q 'ATTENDEE.*;PARTSTAT=ACCEPTED' out8.tmp \   372 && grep -q 'ATTENDEE.*;PARTSTAT=DECLINED' out8.tmp \   373 && echo "Success" \   374 || echo "Failed"   375    376    "$LIST_SCRIPT" $LIST_ARGS "$USER1" "freebusy" \   377 >  out8f.tmp   378    379    "$LIST_SCRIPT" $LIST_ARGS "$USER2" "freebusy" \   380 >  out8f2.tmp   381    382    ( grep -q "^20141127T150000Z${TAB}20141127T160000Z" "out8f.tmp" \   383      && ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "out8f2.tmp" ) \   384 || ( ! grep -q "^20141127T150000Z${TAB}20141127T160000Z" "out8f.tmp" \   385      && grep -q "^20141127T150000Z${TAB}20141127T160000Z" "out8f2.tmp" ) \   386 && echo "Success" \   387 || echo "Failed"   388    389 # Check the quota (event is confirmed, but only for one resource).   390    391    "$LIST_SCRIPT" $LIST_ARGS "$QUOTA" "entries" "$SENDER" \   392 |  tee out8e.tmp \   393 |  grep -q "event23@example.com" \   394 && echo "Success" \   395 || echo "Failed"