Debian Codegraph @

cassandane/Cassandane/Cyrus/Create.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2019 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::Create;
41 use strict;
42 use warnings;
43 use Data::Dumper;
44
45 use lib '.';
46 use base qw(Cassandane::Cyrus::TestCase);
47 use Cassandane::Util::Log;
48 use Cassandane::Instance;
49
50 $Data::Dumper::Sortkeys = 1;
51
52 sub new
53 {
54 my $class = shift;
55 return $class->SUPER::new({ adminstore => 1 }, @_);
56 }
57
58 sub set_up
59 {
60 my ($self) = @_;
61 $self->SUPER::set_up();
62 }
63
64 sub tear_down
65 {
66 my ($self) = @_;
67 $self->SUPER::tear_down();
68 }
69
70 sub test_bad_userids
71 {
72 my ($self) = @_;
73
74 my $admintalk = $self->{adminstore}->get_client();
75
76 my @bad_userids = (
77 'user',
78 'user.anyone',
79 'user.anonymous',
80 'user.%SHARED',
81 #'user..foo', # silently fixed by namespace conversion
82 );
83
84 foreach my $u (@bad_userids) {
85 $admintalk->create($u);
86 $self->assert_str_equals('no',
87 $admintalk->get_last_completion_response());
88 }
89 }
90
91 sub test_bad_userids_unixhs
92 :UnixHierarchySep
93 {
94 my ($self) = @_;
95
96 my $admintalk = $self->{adminstore}->get_client();
97
98 my @bad_userids = (
99 'user',
100 'user/anyone',
101 'user/anonymous',
102 'user/%SHARED',
103 #'user//foo', # silently fixed by namespace conversion
104 );
105
106 foreach my $u (@bad_userids) {
107 $admintalk->create($u);
108 $self->assert_str_equals('no',
109 $admintalk->get_last_completion_response());
110 }
111 }
112
113 sub test_good_userids
114 {
115 my ($self) = @_;
116
117 my $admintalk = $self->{adminstore}->get_client();
118
119 my @good_userids = (
120 'user.$RACL',
121 );
122
123 foreach my $u (@good_userids) {
124 $admintalk->create($u);
125 $self->assert_str_equals('ok',
126 $admintalk->get_last_completion_response());
127 }
128 }
129
130 sub test_good_userids_unixhs
131 :UnixHierarchySep
132 {
133 my ($self) = @_;
134
135 my $admintalk = $self->{adminstore}->get_client();
136
137 my @good_userids = (
138 'user/$RACL',
139 'user/.foo', # with unixhs, this is not a double-sep!
140 );
141
142 foreach my $u (@good_userids) {
143 $admintalk->create($u);
144 $self->assert_str_equals('ok',
145 $admintalk->get_last_completion_response());
146 }
147 }
148
149 sub test_bad_mailboxes
150 {
151 my ($self) = @_;
152
153 my $admintalk = $self->{adminstore}->get_client();
154
155 my @bad_mailboxes = (
156 '$RACL',
157 '$RACL$U$anyone$user.foo',
158 'domain.com!user.foo', # virtdomains=off
159 #'user.cassandane..blah', # silently fixed by namespace conversion
160 );
161
162 foreach my $m (@bad_mailboxes) {
163 $admintalk->create($m);
164 $self->assert_str_equals('no',
165 $admintalk->get_last_completion_response());
166 }
167 }
168
169 sub test_good_mailboxes_unixhs
170 :UnixHierarchySep
171 {
172 my ($self) = @_;
173
174 my $admintalk = $self->{adminstore}->get_client();
175
176 my @good_mailboxes = (
177 'user/cassandane/$RACL',
178 'user/cassandane/.foo', # with unixhs, this is not a double-sep!
179 'user/foo.',
180 'user/foo./bar', # with unixhs, this is not a double-sep!
181 );
182
183 foreach my $m (@good_mailboxes) {
184 $admintalk->create($m);
185 $self->assert_str_equals('ok',
186 $admintalk->get_last_completion_response());
187 }
188 }
189
190 sub test_good_mailboxes_virtdomains
191 :VirtDomains
192 {
193 my ($self) = @_;
194
195 my $admintalk = $self->{adminstore}->get_client();
196
197 my @good_mailboxes = (
198 'user.cassandane.$RACL',
199 '[email protected]',
200 );
201
202 foreach my $m (@good_mailboxes) {
203 $admintalk->create($m);
204 $self->assert_str_equals('ok',
205 $admintalk->get_last_completion_response());
206 }
207 }
208
209 1;