From 9ae5781e7629122974a757b6b61ed57678662173 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 4 Dec 2024 11:17:41 +1100 Subject: [PATCH] WIP Shared subscribe with virtdomains --- cassandane/Cassandane/Cyrus/Shared.pm | 86 ++++++++++++++++++++------- 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/cassandane/Cassandane/Cyrus/Shared.pm b/cassandane/Cassandane/Cyrus/Shared.pm index 3a44b759cd..4d82b757d3 100644 --- a/cassandane/Cassandane/Cyrus/Shared.pm +++ b/cassandane/Cassandane/Cyrus/Shared.pm @@ -46,6 +46,7 @@ use Data::Dumper; use lib '.'; use base qw(Cassandane::Cyrus::TestCase); use Cassandane::Instance; +use Cassandane::Mboxname; use Cassandane::Util::Log; use Cassandane::Util::Words; @@ -79,8 +80,15 @@ sub shared_subscribe_common my ($self, $user1, $user2) = @_; my $service = $self->{instance}->get_service('imap'); + my $config = $self->{instance}->{config}; + my $sep = $config->get_bool('unixhierarchysep', 'on') ? '/' : '.'; - my @user1_mailboxes = random_words(3); + my $user1_inbox = Cassandane::Mboxname->new(config => $config); + $user1_inbox->from_username($user1); + + my @user1_mailboxes = map { + $user1_inbox->make_child($_); + } random_words(3); $self->{instance}->create_user($user1, subdirs => \@user1_mailboxes); @@ -88,11 +96,16 @@ sub shared_subscribe_common my $user1_talk = $user1_store->get_client(); foreach my $mb (@user1_mailboxes) { - $user1_talk->subscribe($mb); - $user1_talk->setacl($mb, $user2, 'lrs'); + $user1_talk->subscribe($mb->to_external('owner')); + $user1_talk->setacl($mb->to_external('owner'), $user2, 'lrs'); } - my @user2_mailboxes = random_words(3); + my $user2_inbox = Cassandane::Mboxname->new(config => $config); + $user2_inbox->from_username($user2); + + my @user2_mailboxes = map { + $user2_inbox->make_child($_); + } random_words(3); $self->{instance}->create_user($user2, subdirs => \@user2_mailboxes); @@ -100,30 +113,32 @@ sub shared_subscribe_common my $user2_talk = $user2_store->get_client(); foreach my $mb (@user2_mailboxes) { - $user2_talk->subscribe($mb); - $user2_talk->setacl($mb, $user1, 'lrs'); + $user2_talk->subscribe($mb->to_external('owner')); + $user2_talk->setacl($mb->to_external('owner'), $user1, 'lrs'); } + $user1_talk->list('', '*'); + xlog("subscribe as $user1 to $user2\'s shared mb's"); foreach my $mb (@user2_mailboxes) { - $user1_talk->subscribe("Other Users.$user2.$mb"); + $user1_talk->subscribe($mb->to_external('other')); $self->assert_equals('ok', $user1_talk->get_last_completion_response()); } xlog("but not their inbox"); - $user1_talk->subscribe("Other Users.$user2"); + $user1_talk->subscribe($user2_inbox->to_external('other')); $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, '.', { + $self->assert_mailbox_structure($user1_subs, $sep, { (map {( - $_ => [ '\\Subscribed', '\\HasNoChildren' ] + $_->to_external('owner') => [ '\\Subscribed', '\\HasNoChildren' ] )} @user1_mailboxes), (map {( - "Other Users.$user2.$_" => [ + $_->to_external('other') => [ '\\Subscribed', '\\HasNoChildren', ] @@ -132,7 +147,7 @@ sub shared_subscribe_common xlog("unsub as $user1 from $user2\'s folders"); foreach my $mb (@user2_mailboxes) { - $user1_talk->unsubscribe("Other Users.$user2.$mb"); + $user1_talk->unsubscribe($mb->to_external('other')); $self->assert_equals('ok', $user1_talk->get_last_completion_response()); } @@ -140,33 +155,33 @@ sub shared_subscribe_common $user1_subs = $user1_talk->list([qw(SUBSCRIBED)], '', '*', 'RETURN', [qw(CHILDREN)]); - $self->assert_mailbox_structure($user1_subs, '.', { + $self->assert_mailbox_structure($user1_subs, $sep, { (map {( - $_ => [ '\\Subscribed', '\\HasNoChildren' ] + $_->to_external('owner') => [ '\\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"); + $user2_talk->subscribe($mb->to_external('other')); $self->assert_equals('ok', $user2_talk->get_last_completion_response()); } xlog("but not their inbox"); - $user2_talk->subscribe("Other Users.$user1"); + $user2_talk->subscribe($user1_inbox->to_external('other')); $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, '.', { + $self->assert_mailbox_structure($user2_subs, $sep, { (map {( - $_ => [ '\\Subscribed', '\\HasNoChildren' ] + $_->to_external('owner') => [ '\\Subscribed', '\\HasNoChildren' ] )} @user2_mailboxes), (map {( - "Other Users.$user1.$_" => [ + $_->to_external('other') => [ '\\Subscribed', '\\HasNoChildren', ] @@ -175,7 +190,7 @@ sub shared_subscribe_common xlog("unsub as $user2 from $user1\'s folders"); foreach my $mb (@user1_mailboxes) { - $user2_talk->unsubscribe("Other Users.$user1.$mb"); + $user2_talk->unsubscribe($mb->to_external('other')); $self->assert_equals('ok', $user2_talk->get_last_completion_response()); } @@ -184,9 +199,9 @@ sub shared_subscribe_common $user2_subs = $user2_talk->list([qw(SUBSCRIBED)], '', '*', 'RETURN', [qw(CHILDREN)]); - $self->assert_mailbox_structure($user2_subs, '.', { + $self->assert_mailbox_structure($user2_subs, $sep, { (map {( - $_ => [ '\\Subscribed', '\\HasNoChildren' ] + $_->to_external('owner') => [ '\\Subscribed', '\\HasNoChildren' ] )} @user2_mailboxes), }); } @@ -206,4 +221,31 @@ sub test_subscribe_prefix $self->shared_subscribe_common('chris', 'christopher'); } +sub test_subscribe_vd + :VirtDomains :CrossDomains +{ + my ($self) = @_; + + $self->shared_subscribe_common('firstuser@example.com', + 'seconduser@example.com'); +} + +sub test_subscribe_vd_prefix + :VirtDomains :CrossDomains +{ + my ($self) = @_; + + $self->shared_subscribe_common('matt@example.com', + 'matthew@example.com'); +} + +sub test_subscribe_vd_prefix2 + :VirtDomains :CrossDomains +{ + my ($self) = @_; + + $self->shared_subscribe_common('jim@example.com', + 'jim@example.coma.info'); +} + 1;