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 6, 2024
1 parent dc35805 commit 97339e4
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions cassandane/Cassandane/Cyrus/Shared.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,136 @@ sub tear_down
$self->SUPER::tear_down();
}

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

my $service = $self->{instance}->get_service('imap');

my @user1_mailboxes = random_words(3);
$self->{instance}->create_user($user1,
subdirs => \@user1_mailboxes);

my $user1_store = $service->create_store(username => $user1);
my $user1_talk = $user1_store->get_client();

foreach my $mb (@user1_mailboxes) {
$user1_talk->subscribe($mb);
$user1_talk->setacl($mb, $user2, 'lrs');
}

my @user2_mailboxes = random_words(3);
$self->{instance}->create_user($user2,
subdirs => \@user2_mailboxes);

my $user2_store = $service->create_store(username => $user2);
my $user2_talk = $user2_store->get_client();

foreach my $mb (@user2_mailboxes) {
$user2_talk->subscribe($mb);
$user2_talk->setacl($mb, $user1, 'lrs');
}

xlog("subscribe as $user1 to $user2\'s shared mb's");
foreach my $mb (@user2_mailboxes) {
$user1_talk->subscribe("Other Users.$user2.$mb");
$self->assert_equals('ok', $user1_talk->get_last_completion_response());
}

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

xlog("make sure $user1 has the right subscriptions");
my $user1_subs = $user1_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($user1_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @user1_mailboxes),
(map {(
"Other Users.$user2.$_" => [
'\\Subscribed',
'\\HasNoChildren',
]
)} @user2_mailboxes),
});

xlog("unsub as $user1 from $user2\'s folders");
foreach my $mb (@user2_mailboxes) {
$user1_talk->unsubscribe("Other Users.$user2.$mb");
$self->assert_equals('ok', $user1_talk->get_last_completion_response());
}

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

xlog("subscribe as $user2 to $user1\'s shared mb's");
foreach my $mb (@user1_mailboxes) {
$user2_talk->subscribe("Other Users.$user1.$mb");
$self->assert_equals('ok',
$user2_talk->get_last_completion_response());
}

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

xlog("make sure $user2 has the right subscriptions");
my $user2_subs = $user2_talk->list([qw(SUBSCRIBED)],
'', '*',
'RETURN', [qw(CHILDREN)]);
$self->assert_mailbox_structure($user2_subs, '.', {
(map {(
$_ => [ '\\Subscribed', '\\HasNoChildren' ]
)} @user2_mailboxes),
(map {(
"Other Users.$user1.$_" => [
'\\Subscribed',
'\\HasNoChildren',
]
)} @user1_mailboxes),
});

xlog("unsub as $user2 from $user1\'s folders");
foreach my $mb (@user1_mailboxes) {
$user2_talk->unsubscribe("Other Users.$user1.$mb");
$self->assert_equals('ok',
$user2_talk->get_last_completion_response());
}

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

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

$self->shared_subscribe_common('firstuser', 'seconduser');
}

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

# one user is a prefix of the other!
$self->shared_subscribe_common('chris', 'christopher');
}

1;

0 comments on commit 97339e4

Please sign in to comment.