Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cass: test that autocreate doesn't replace legacy mailboxes #4540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions cassandane/Cassandane/Cyrus/Autocreate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
package Cassandane::Cyrus::Autocreate;
use strict;
use warnings;
use Cwd qw(getcwd);
use Data::Dumper;
use File::Temp qw(tempdir);

use lib '.';
use base qw(Cassandane::Cyrus::TestCase);
Expand Down Expand Up @@ -165,4 +167,55 @@ sub test_autocreate_acl
}
}

sub test_legacymb_already_exists
:NoStartInstances :NoAltNamespace
{
my ($self) = @_;

# want a separate IMAP service with separate config containing
# the defaults (no autocreate!) plus mailbox_legacy_dirs: yes
my $leg_conf = Cassandane::Config->default()->clone();
$leg_conf->set(mailbox_legacy_dirs => 'yes');

my $leg_svc = $self->{instance}->add_service(
name => 'imaplegacymb',
config => $leg_conf,
);

# now actually start everything
$self->_start_instances();

# create some mailboxes for user foo under legacy storage
my $leg_store = $leg_svc->create_store(username => 'admin',
type => 'imap');
my $leg_talk = $leg_store->get_client();

$leg_talk->create('user.foo') or die;
$leg_talk->setacl('user.foo', foo => 'lrswipkxtecdn') or die;
$leg_talk->create('user.foo.bar') or die;
$leg_talk->setacl('user.foo.bar', foo => 'lrswipkxtecdn') or die;

$leg_talk->logout();

# those mailboxes had better be under legacy storage
foreach my $mailbox (qw(user.foo user.foo.bar)) {
my $mbpath = $self->{instance}->run_mbpath($mailbox);
$self->assert_does_not_match(qr{/uuid/}, $mbpath->{data});
}

# now log in as user foo -- better not get the default
# autocreate set!

my $svc = $self->{instance}->get_service('imap');
my $store = $svc->create_store(username => 'foo');
my $talk = $store->get_client();

my $data = $talk->list("", "*");

$self->assert_mailbox_structure($data, '.', {
'INBOX' => '\\HasChildren',
'INBOX.bar' => '\\HasNoChildren',
});
}

1;
63 changes: 40 additions & 23 deletions cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,8 @@ sub add_service
}
}

my $srv = Cassandane::ServiceFactory->create(%params);
my $srv = Cassandane::ServiceFactory->create(instance => $self, %params);
$self->{services}->{$name} = $srv;
$srv->set_config($self->{config});
return $srv;
}

Expand Down Expand Up @@ -490,9 +489,10 @@ sub add_generic_listener
die "Already have a generic listener named \"$name\""
if defined $self->{generic_listeners}->{$name};

$params{config} //= $self->{config};

my $listener = Cassandane::GenericListener->new(
name => $name,
config => $self->{config},
%params
);

Expand All @@ -505,8 +505,6 @@ sub set_config
my ($self, $conf) = @_;

$self->{config} = $conf;
map { $_->set_config($conf); } (values %{$self->{services}},
values %{$self->{generic_listeners}});
}

sub _find_binary
Expand Down Expand Up @@ -594,9 +592,11 @@ sub _binary

sub _imapd_conf
{
my ($self) = @_;
my ($self, $prefix) = @_;

my $fname = $prefix ? "$prefix-imapd.conf" : 'imapd.conf';

return $self->{basedir} . '/conf/imapd.conf';
return $self->{basedir} . "/conf/$fname";
}

sub _master_conf
Expand Down Expand Up @@ -680,47 +680,46 @@ sub _build_skeleton

sub _generate_imapd_conf
{
my ($self) = @_;
my ($self, $config, $prefix) = @_;

if (defined $self->{services}->{http}) {
my $davhost = $self->{services}->{http}->host;
if (defined $self->{services}->{http}->port) {
$davhost .= ':' . $self->{services}->{http}->port;
}
$self->{config}->set(
$config->set(
webdav_attachments_baseurl => "http://$davhost"
);
}

my ($cyrus_major_version, $cyrus_minor_version) =
Cassandane::Instance->get_version($self->{installation});

$self->{config}->set_variables(
$config->set_variables(
name => $self->{name},
basedir => $self->{basedir},
cyrus_prefix => $self->{cyrus_prefix},
prefix => getcwd(),
);
$self->{config}->set(
$config->set(
sasl_pwcheck_method => 'saslauthd',
sasl_saslauthd_path => "$self->{basedir}/run/mux",
notifysocket => "dlist:$self->{basedir}/run/notify",
event_notifier => 'pusher',
);
if ($cyrus_major_version >= 3) {
$self->{config}->set(imipnotifier => 'imip');
$self->{config}->set_bits('event_groups',
'mailbox message flags calendar');
$config->set(imipnotifier => 'imip');
$config->set_bits('event_groups', 'mailbox message flags calendar');

if ($cyrus_major_version > 3 || $cyrus_minor_version >= 1) {
$self->{config}->set(
$config->set(
smtp_backend => 'host',
smtp_host => $self->{smtphost},
);
}
}
else {
$self->{config}->set_bits('event_groups', 'mailbox message flags');
$config->set_bits('event_groups', 'mailbox message flags');
}
if ($self->{buildinfo}->get('search', 'xapian')) {
my %xapian_defaults = (
Expand All @@ -733,12 +732,13 @@ sub _generate_imapd_conf
't3searchpartition-default' => "$self->{basedir}/search3",
);
while (my ($k, $v) = each %xapian_defaults) {
if (not defined $self->{config}->get($k)) {
$self->{config}->set($k => $v);
if (not defined $config->get($k)) {
$config->set($k => $v);
}
}
}
$self->{config}->generate($self->_imapd_conf());

$config->generate($self->_imapd_conf($prefix));
}

sub _emit_master_entry
Expand All @@ -747,6 +747,10 @@ sub _emit_master_entry

my $params = $entry->master_params();
my $name = delete $params->{name};
my $config = delete $params->{config};

# if this master entry has its own confix, it will have a prefixed name
my $imapd_conf = $self->_imapd_conf($config ? $name : undef);

# Convert ->{argv} to ->{cmd}
my $argv = delete $params->{argv};
Expand All @@ -757,7 +761,7 @@ sub _emit_master_entry
my $bin = shift @args;
$params->{cmd} = join(' ',
$self->_binary($bin),
'-C', $self->_imapd_conf(),
'-C', $imapd_conf,
@args
);

Expand All @@ -776,7 +780,6 @@ sub _generate_master_conf
my ($self) = @_;

my $filename = $self->_master_conf();
my $conf = $self->_imapd_conf();
open MASTER,'>',$filename
or die "Cannot open $filename for writing: $!";

Expand Down Expand Up @@ -873,7 +876,7 @@ sub _add_services_from_cyrus_conf
}
if ($in eq 'SERVICES')
{
$self->add_service(name => $name, %params);
$self->add_service(instance => $self, name => $name, %params);
}
}

Expand Down Expand Up @@ -1236,7 +1239,21 @@ sub start
# TODO: system("echo 1 >/proc/sys/fs/suid_dumpable");
$self->{buildinfo} = Cassandane::BuildInfo->new($self->{cyrus_destdir},
$self->{cyrus_prefix});
$self->_generate_imapd_conf();

# the main imapd.conf
$self->_generate_imapd_conf($self->{config});

# individual prefix-imapd.conf for master entries that want one
foreach my $me (values %{$self->{services}},
values %{$self->{daemons}},
@{$self->{starts}},
@{$self->{events}})
{
if ($me->{config}) {
$self->_generate_imapd_conf($me->{config}, $me->{name});
}
}

$self->_generate_master_conf();
$self->install_certificates() if $self->{install_certificates};
$self->_fix_ownership();
Expand Down
4 changes: 2 additions & 2 deletions cassandane/Cassandane/MasterEntry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ sub master_params
{
my ($self) = @_;
my $params = {};
foreach my $a ('name', 'argv', $self->_otherparams())
foreach my $a ('name', 'argv', 'config', $self->_otherparams())
{
$params->{$a} = $self->{$a}
if defined $self->{$a};
Expand All @@ -99,7 +99,7 @@ sub set_master_param
{
my ($self, $param, $value) = @_;

foreach my $a ('name', 'argv', $self->_otherparams())
foreach my $a ('name', 'argv', 'config', $self->_otherparams())
{
$self->{$a} = $value
if ($a eq $param);
Expand Down
8 changes: 7 additions & 1 deletion cassandane/Cassandane/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ sub new
if (exists $params{host});
my $port = delete $params{port};
my $type = delete $params{type} || 'unknown';
my $instance = delete $params{instance};

my $self = $class->SUPER::new(%params);

# GenericListener is a bit different from MasterEntry et al, and must
# always have a config specified, so pass through the default explicitly
my $listener_config = $params{config} || $instance->{config};

$self->{_listener} = Cassandane::GenericListener->new(
name => $params{name},
host => $host,
port => $port);
port => $port,
config => $listener_config);
$self->{type} = $type;

return $self;
Expand Down