| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Copyright (c) 2011-2020 FastMail Pty Ltd. All rights reserved. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions |
| 7 |
# are met: |
| 8 |
# |
| 9 |
# 1. Redistributions of source code must retain the above copyright |
| 10 |
# notice, this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
# notice, this list of conditions and the following disclaimer in |
| 14 |
# the documentation and/or other materials provided with the |
| 15 |
# distribution. |
| 16 |
# |
| 17 |
# 3. The name "Fastmail Pty Ltd" must not be used to |
| 18 |
# endorse or promote products derived from this software without |
| 19 |
# prior written permission. For permission or any legal |
| 20 |
# details, please contact |
| 21 |
# FastMail Pty Ltd |
| 22 |
# PO Box 234 |
| 23 |
# Collins St West 8007 |
| 24 |
# Victoria |
| 25 |
# Australia |
| 26 |
# |
| 27 |
# 4. Redistributions of any form whatsoever must retain the following |
| 28 |
# acknowledgment: |
| 29 |
# "This product includes software developed by Fastmail Pty. Ltd." |
| 30 |
# |
| 31 |
# FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 32 |
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 33 |
# EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT |
| 34 |
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 35 |
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 36 |
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 37 |
# OF THIS SOFTWARE. |
| 38 |
# |
| 39 |
|
| 40 |
package Cassandane::Cyrus::MboxEvent; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
use Data::Dumper; |
| 44 |
use JSON; |
| 45 |
|
| 46 |
use lib '.'; |
| 47 |
use base qw(Cassandane::Cyrus::TestCase); |
| 48 |
use Cassandane::Util::Log; |
| 49 |
use Cassandane::Generator; |
| 50 |
use Cassandane::MessageStoreFactory; |
| 51 |
use Cassandane::Instance; |
| 52 |
|
| 53 |
sub new |
| 54 |
{ |
| 55 |
my ($class, @args) = @_; |
| 56 |
|
| 57 |
# all of them! |
| 58 |
my @event_groups = qw( |
| 59 |
message |
| 60 |
quota |
| 61 |
flags |
| 62 |
access |
| 63 |
mailbox |
| 64 |
subscription |
| 65 |
calendar |
| 66 |
applepushservice |
| 67 |
); |
| 68 |
|
| 69 |
my $config = Cassandane::Config->default()->clone(); |
| 70 |
$config->set(event_groups => join(' ', @event_groups)); |
| 71 |
|
| 72 |
return $class->SUPER::new({ |
| 73 |
config => $config, |
| 74 |
}, @args); |
| 75 |
} |
| 76 |
|
| 77 |
sub set_up |
| 78 |
{ |
| 79 |
my ($self) = @_; |
| 80 |
$self->SUPER::set_up(); |
| 81 |
} |
| 82 |
|
| 83 |
sub tear_down |
| 84 |
{ |
| 85 |
my ($self) = @_; |
| 86 |
$self->SUPER::tear_down(); |
| 87 |
} |
| 88 |
|
| 89 |
sub test_tls_login_event |
| 90 |
:TLS :min_version_3_0 |
| 91 |
{ |
| 92 |
my ($self) = @_; |
| 93 |
|
| 94 |
my $instance = $self->{instance}; |
| 95 |
|
| 96 |
my $svc = $instance->get_service('imaps'); |
| 97 |
$self->assert_not_null($svc); |
| 98 |
|
| 99 |
my $store = $svc->create_store(); |
| 100 |
$self->assert_not_null($store); |
| 101 |
|
| 102 |
# discard unwanted events from setup_mailbox |
| 103 |
$self->{instance}->getnotify(); |
| 104 |
|
| 105 |
# we're just gonna log in, but not do anything else |
| 106 |
my $client = $store->get_client(); |
| 107 |
|
| 108 |
my $events = $self->{instance}->getnotify(); |
| 109 |
my %event_counts; |
| 110 |
|
| 111 |
foreach my $e (@{$events}) { |
| 112 |
my $message = decode_json($e->{MESSAGE}); |
| 113 |
$event_counts{$message->{event}}++; |
| 114 |
} |
| 115 |
|
| 116 |
# client should still be connected |
| 117 |
# XXX on an ssl socket (which must be blocking), is_open blocks! |
| 118 |
# XXX prefer to do this: |
| 119 |
# my $still_connected = $client->is_open(); |
| 120 |
# $self->assert_not_null($still_connected, "connection dropped"); |
| 121 |
# XXX but instead, check if a select succeeds |
| 122 |
$client->select('INBOX'); |
| 123 |
$self->assert_str_equals('ok', $client->get_last_completion_response()); |
| 124 |
|
| 125 |
# we should have gotten one Login event and no others |
| 126 |
$self->assert_equals(1, $event_counts{'Login'}); |
| 127 |
|
| 128 |
# XXX more correct, but may race against setup_mailbox finishing up |
| 129 |
#$self->assert_deep_equals({ Login => 1 }, \%event_counts); |
| 130 |
|
| 131 |
# XXX explicitly log out to work around Mail::IMAPTalk destructor |
| 132 |
# XXX calling is_open() |
| 133 |
$client->logout(); |
| 134 |
} |
| 135 |
|
| 136 |
1; |