#!perl
use Cassandane::Tiny;

sub test_imap_admins ($self)
{
    # test whether the imap_admins setting works correctly

    my $admintalk = $self->{adminstore}->get_client();
    my $imapadmintalk = $self->{imapadminstore}->get_client();
    my $talk = $self->{store}->get_client();

    # we should be able to reconstruct as 'admin', because although
    # imap_admins overrides admins, we have 'admin' in imap_admins too
    # (it MUST be there for Cassandane itself to work)
    my $res = $admintalk->_imap_cmd("reconstruct" , 0, {}, "user.cassandane");
    $self->assert_str_equals('ok', $admintalk->get_last_completion_response());

    # we should not be able to reconstruct as 'cassandane', because
    # reconstruct is an admin-only command
    $res = $talk->_imap_cmd("reconstruct", 0, {}, "user.cassandane");
    $self->assert_str_equals('no', $talk->get_last_completion_response());
    $self->assert_matches(qr/permission denied/i, $talk->get_last_error());

    # we should be able to reconstruct as 'imapadmin', because this user
    # is in imap_admins
    $res = $imapadmintalk->_imap_cmd("reconstruct", 0, {}, "user.cassandane");
    $self->assert_str_equals('ok', $imapadmintalk->get_last_completion_response());
}
