imip-agent

tests/test_resource_invitation_constraints_quota.sh

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