| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Copyright (c) 2011-2017 FastMail Pty Ltd. All rights reserved. |
| 4 |
# |
| 5 |
# Redistribution and use in source and binary forms, with or without |
| 6 |
# modification, are permitted provided that the following conditions |
| 7 |
# are met: |
| 8 |
# |
| 9 |
# 1. Redistributions of source code must retain the above copyright |
| 10 |
# notice, this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
# notice, this list of conditions and the following disclaimer in |
| 14 |
# the documentation and/or other materials provided with the |
| 15 |
# distribution. |
| 16 |
# |
| 17 |
# 3. The name "Fastmail Pty Ltd" must not be used to |
| 18 |
# endorse or promote products derived from this software without |
| 19 |
# prior written permission. For permission or any legal |
| 20 |
# details, please contact |
| 21 |
# FastMail Pty Ltd |
| 22 |
# PO Box 234 |
| 23 |
# Collins St West 8007 |
| 24 |
# Victoria |
| 25 |
# Australia |
| 26 |
# |
| 27 |
# 4. Redistributions of any form whatsoever must retain the following |
| 28 |
# acknowledgment: |
| 29 |
# "This product includes software developed by Fastmail Pty. Ltd." |
| 30 |
# |
| 31 |
# FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 32 |
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 33 |
# EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT |
| 34 |
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 35 |
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 36 |
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 37 |
# OF THIS SOFTWARE. |
| 38 |
# |
| 39 |
|
| 40 |
package Cassandane::Cyrus::Bug3903; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
|
| 44 |
use lib '.'; |
| 45 |
use base qw(Cassandane::Cyrus::TestCase); |
| 46 |
use Cassandane::Util::Log; |
| 47 |
|
| 48 |
sub new |
| 49 |
{ |
| 50 |
my $class = shift; |
| 51 |
my $config = Cassandane::Config->default()->clone(); |
| 52 |
$config->set(autocreate_quota => 101200); |
| 53 |
return $class->SUPER::new({ |
| 54 |
config => $config, |
| 55 |
adminstore => 1, |
| 56 |
}, @_); |
| 57 |
} |
| 58 |
|
| 59 |
sub set_up |
| 60 |
{ |
| 61 |
my ($self) = @_; |
| 62 |
$self->SUPER::set_up(); |
| 63 |
|
| 64 |
$self->{instance}->create_user("foo", |
| 65 |
subdirs => [ 'cassandane', ['cassandane', 'sent'] ]); |
| 66 |
|
| 67 |
my $admintalk = $self->{adminstore}->get_client(); |
| 68 |
$admintalk->setacl("user.foo.cassandane.sent", "cassandane", "lrswp"); |
| 69 |
} |
| 70 |
|
| 71 |
sub tear_down |
| 72 |
{ |
| 73 |
my ($self) = @_; |
| 74 |
$self->SUPER::tear_down(); |
| 75 |
} |
| 76 |
|
| 77 |
sub test_create_under_wrong_user |
| 78 |
:NoAltNameSpace |
| 79 |
{ |
| 80 |
my ($self) = @_; |
| 81 |
|
| 82 |
my $talk = $self->{store}->get_client(); |
| 83 |
|
| 84 |
my $res = $talk->create('user.foo.cassandane.sent.Test1'); |
| 85 |
$self->assert_null($res); # means it failed |
| 86 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 87 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 88 |
|
| 89 |
$res = $talk->create('user.foo.cassandane.Test2'); |
| 90 |
$self->assert_null($res); # means it failed |
| 91 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 92 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 93 |
|
| 94 |
$res = $talk->create('user.foo.Test3'); |
| 95 |
$self->assert_null($res); # means it failed |
| 96 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 97 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 98 |
} |
| 99 |
|
| 100 |
sub test_create_under_user |
| 101 |
:NoAltNameSpace |
| 102 |
{ |
| 103 |
my ($self) = @_; |
| 104 |
|
| 105 |
my $talk = $self->{store}->get_client(); |
| 106 |
|
| 107 |
my $res = $talk->create('user.Test4'); |
| 108 |
$self->assert_null($res); # means it failed |
| 109 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 110 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
sub test_create_under_shared |
| 115 |
:NoAltNameSpace |
| 116 |
{ |
| 117 |
my ($self) = @_; |
| 118 |
|
| 119 |
my $talk = $self->{store}->get_client(); |
| 120 |
|
| 121 |
my $res = $talk->create('shared.Test5'); |
| 122 |
$self->assert_null($res); # means it failed |
| 123 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 124 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
sub test_create_at_top_level |
| 129 |
:NoAltNameSpace |
| 130 |
{ |
| 131 |
my ($self) = @_; |
| 132 |
|
| 133 |
my $talk = $self->{store}->get_client(); |
| 134 |
|
| 135 |
my $res = $talk->create('Test6'); |
| 136 |
$self->assert_null($res); # means it failed |
| 137 |
$self->assert_str_equals('no', $talk->get_last_completion_response()); |
| 138 |
$self->assert($talk->get_last_error() =~ m/permission denied/i); |
| 139 |
} |
| 140 |
|
| 141 |
1; |