Skip to content

Commit

Permalink
Shared: test subscribe to shared mailboxes
Browse files Browse the repository at this point in the history
(with/without one user being a prefix of the other)
  • Loading branch information
elliefm committed Dec 3, 2024
1 parent b644b18 commit 137ab46
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions cassandane/Cassandane/Cyrus/Shared.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,132 @@ sub tear_down
$self->SUPER::tear_down();
}

sub shared_subscribe_common
{
my ($self, $other_user) = @_;

my @cass_mailboxes = sort map { random_word() } 1..3;
my $cass_talk = $self->{store}->get_client();

foreach my $mb (@cass_mailboxes) {
$cass_talk->create($mb);
$cass_talk->subscribe($mb);
$cass_talk->setacl($mb, $other_user, 'lrs');
}

my @other_mailboxes = sort map { random_word() } 1..3;
$self->{instance}->create_user($other_user,
subdirs => \@other_mailboxes);

my $service = $self->{instance}->get_service('imap');
my $other_store = $service->create_store(username => $other_user);
my $other_talk = $other_store->get_client();

foreach my $mb (@other_mailboxes) {
$other_talk->subscribe($mb);
$other_talk->setacl($mb, 'cassandane', 'lrs');
}

xlog("subscribe as cassandane to $other_user\'s shared mb's");
foreach my $mb (@other_mailboxes) {
$cass_talk->subscribe("Other Users.$other_user.$mb");
$self->assert_equals('ok', $cass_talk->get_last_completion_response());
}

xlog("but not their inbox");
$cass_talk->subscribe("Other Users.$other_user");
$self->assert_equals('no', $cass_talk->get_last_completion_response());

xlog("make sure cassandane has the right subscriptions");
my $cass_subs = $cass_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($cass_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @cass_mailboxes),
(map {(
"Other Users.$other_user.$_" => [
'\\Subscribed',
'\\HasNoChildren',
]
)} @other_mailboxes),
});

xlog("unsub as cassandane from $other_user\'s folders");
foreach my $mb (@other_mailboxes) {
$cass_talk->unsubscribe("Other Users.$other_user.$mb");
$self->assert_equals('ok', $cass_talk->get_last_completion_response());
}

xlog("make sure cassandane has the right subscriptions");
$cass_subs = $cass_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($cass_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @cass_mailboxes),
});

xlog("subscribe as $other_user to cassandane's shared mb's");
foreach my $mb (@cass_mailboxes) {
$other_talk->subscribe("Other Users.cassandane.$mb");
$self->assert_equals('ok',
$other_talk->get_last_completion_response());
}

xlog("but not their inbox");
$other_talk->subscribe("Other Users.cassandane");
$self->assert_equals('no', $other_talk->get_last_completion_response());

xlog("make sure $other_user has the right subscriptions");
my $other_subs = $other_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($other_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @other_mailboxes),
(map {(
"Other Users.cassandane.$_" => [
'\\Subscribed',
'\\HasNoChildren',
]
)} @cass_mailboxes),
});

xlog("unsub as $other_user from cassandane's folders");
foreach my $mb (@cass_mailboxes) {
$other_talk->unsubscribe("Other Users.cassandane.$mb");
$self->assert_equals('ok',
$other_talk->get_last_completion_response());
}

xlog("make sure $other_user has the right subscriptions");
$other_subs = $other_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($other_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @other_mailboxes),
});
}

sub test_subscribe
{
my ($self) = @_;

$self->shared_subscribe_common('otheruser');
}

sub test_subscribe_prefix
{
my ($self) = @_;

# 'cassandane' is a prefix of otheruser!
$self->shared_subscribe_common('cassandane123');
}

1;

0 comments on commit 137ab46

Please sign in to comment.