| 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::Specialuse; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
|
| 44 |
use lib '.'; |
| 45 |
use base qw(Cassandane::Cyrus::TestCase); |
| 46 |
use Cassandane::Util::Log; |
| 47 |
use Cassandane::Instance; |
| 48 |
|
| 49 |
sub new |
| 50 |
{ |
| 51 |
my $class = shift; |
| 52 |
return $class->SUPER::new({ adminstore => 1 }, @_); |
| 53 |
} |
| 54 |
|
| 55 |
sub set_up |
| 56 |
{ |
| 57 |
my ($self) = @_; |
| 58 |
$self->SUPER::set_up(); |
| 59 |
} |
| 60 |
|
| 61 |
sub tear_down |
| 62 |
{ |
| 63 |
my ($self) = @_; |
| 64 |
$self->SUPER::tear_down(); |
| 65 |
} |
| 66 |
|
| 67 |
# Test that you can rename a special use folder |
| 68 |
sub test_rename_toplevel |
| 69 |
:NoAltNameSpace |
| 70 |
{ |
| 71 |
my ($self) = @_; |
| 72 |
|
| 73 |
my $imaptalk = $self->{store}->get_client(); |
| 74 |
|
| 75 |
$imaptalk->create("INBOX.Junk", "(USE (\\Junk))"); |
| 76 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 77 |
|
| 78 |
$imaptalk->rename("INBOX.Junk", "INBOX.Other"); |
| 79 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 80 |
} |
| 81 |
|
| 82 |
sub test_rename_tosub |
| 83 |
:NoAltNameSpace |
| 84 |
{ |
| 85 |
my ($self) = @_; |
| 86 |
|
| 87 |
my $imaptalk = $self->{store}->get_client(); |
| 88 |
|
| 89 |
$imaptalk->create("INBOX.Junk", "(USE (\\Junk))"); |
| 90 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 91 |
|
| 92 |
$imaptalk->create("INBOX.Trash"); |
| 93 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 94 |
|
| 95 |
# can't rename to a deep folder |
| 96 |
$imaptalk->rename("INBOX.Junk", "INBOX.Trash.Junk"); |
| 97 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 98 |
} |
| 99 |
|
| 100 |
sub test_create_multiple |
| 101 |
:NoAltNameSpace |
| 102 |
{ |
| 103 |
my ($self) = @_; |
| 104 |
|
| 105 |
my $imaptalk = $self->{store}->get_client(); |
| 106 |
|
| 107 |
$imaptalk->create("INBOX.Rubbish", "(USE (\\Junk \\Trash \\Sent))"); |
| 108 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 109 |
} |
| 110 |
|
| 111 |
sub test_create_dupe |
| 112 |
:NoAltNameSpace |
| 113 |
{ |
| 114 |
my ($self) = @_; |
| 115 |
|
| 116 |
my $imaptalk = $self->{store}->get_client(); |
| 117 |
|
| 118 |
$imaptalk->create("INBOX.Rubbish", "(USE (\\Trash))"); |
| 119 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 120 |
|
| 121 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 122 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 123 |
} |
| 124 |
|
| 125 |
sub test_annot |
| 126 |
{ |
| 127 |
my ($self) = @_; |
| 128 |
|
| 129 |
my $imaptalk = $self->{store}->get_client(); |
| 130 |
|
| 131 |
$imaptalk->create("INBOX.Trash"); |
| 132 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 133 |
|
| 134 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", "\\Trash"); |
| 135 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 136 |
} |
| 137 |
|
| 138 |
sub test_annot_dupe |
| 139 |
:NoAltNameSpace |
| 140 |
{ |
| 141 |
my ($self) = @_; |
| 142 |
|
| 143 |
my $imaptalk = $self->{store}->get_client(); |
| 144 |
|
| 145 |
$imaptalk->create("INBOX.Rubbish", "(USE (\\Trash))"); |
| 146 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 147 |
|
| 148 |
$imaptalk->create("INBOX.Trash"); |
| 149 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 150 |
|
| 151 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", "\\Trash"); |
| 152 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 153 |
} |
| 154 |
|
| 155 |
sub test_delete_imm |
| 156 |
:ImmediateDelete :NoAltNameSpace |
| 157 |
{ |
| 158 |
my ($self) = @_; |
| 159 |
|
| 160 |
my $imaptalk = $self->{store}->get_client(); |
| 161 |
|
| 162 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 163 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 164 |
|
| 165 |
$imaptalk->delete("INBOX.Trash"); |
| 166 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 167 |
} |
| 168 |
|
| 169 |
sub test_delete_delay |
| 170 |
:DelayedDelete :NoAltNameSpace |
| 171 |
{ |
| 172 |
my ($self) = @_; |
| 173 |
|
| 174 |
my $imaptalk = $self->{store}->get_client(); |
| 175 |
|
| 176 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 177 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 178 |
|
| 179 |
$imaptalk->delete("INBOX.Trash"); |
| 180 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 181 |
} |
| 182 |
|
| 183 |
sub test_delete_removed_imm |
| 184 |
:ImmediateDelete :NoAltNameSpace |
| 185 |
{ |
| 186 |
my ($self) = @_; |
| 187 |
|
| 188 |
my $imaptalk = $self->{store}->get_client(); |
| 189 |
|
| 190 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 191 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 192 |
|
| 193 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", undef); |
| 194 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 195 |
|
| 196 |
$imaptalk->delete("INBOX.Trash"); |
| 197 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 198 |
} |
| 199 |
|
| 200 |
sub test_delete_removed_delay |
| 201 |
:DelayedDelete :NoAltNameSpace |
| 202 |
{ |
| 203 |
my ($self) = @_; |
| 204 |
|
| 205 |
my $imaptalk = $self->{store}->get_client(); |
| 206 |
|
| 207 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 208 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 209 |
|
| 210 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", undef); |
| 211 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 212 |
|
| 213 |
$imaptalk->delete("INBOX.Trash"); |
| 214 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 215 |
} |
| 216 |
|
| 217 |
sub test_important |
| 218 |
:min_version_3_1 :NoAltNameSpace |
| 219 |
{ |
| 220 |
my ($self) = @_; |
| 221 |
|
| 222 |
my $imaptalk = $self->{store}->get_client(); |
| 223 |
|
| 224 |
$imaptalk->create("INBOX.Important", "(USE (\\Important))"); |
| 225 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 226 |
|
| 227 |
$imaptalk->delete("INBOX.Important"); |
| 228 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 229 |
} |
| 230 |
|
| 231 |
sub test_nochildren |
| 232 |
:min_version_3_7 :NoStartInstances :NoAltNamespace |
| 233 |
{ |
| 234 |
my ($self) = @_; |
| 235 |
|
| 236 |
$self->{instance}->{config}->set('specialuse_nochildren' => '\\Trash'); |
| 237 |
$self->_start_instances(); |
| 238 |
|
| 239 |
my $imaptalk = $self->{store}->get_client(); |
| 240 |
|
| 241 |
$imaptalk->create("INBOX.Trash", "(USE (\\Trash))"); |
| 242 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 243 |
|
| 244 |
# should not be able to create a child |
| 245 |
$imaptalk->create("INBOX.Trash.child"); |
| 246 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 247 |
|
| 248 |
# should not be able to create a grandchild either |
| 249 |
$imaptalk->create("INBOX.Trash.child.grandchild"); |
| 250 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 251 |
|
| 252 |
# better not have accidentally created anything |
| 253 |
$imaptalk->select("INBOX.Trash.child"); |
| 254 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 255 |
|
| 256 |
$imaptalk->select("INBOX.Trash.child.grandchild"); |
| 257 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 258 |
|
| 259 |
# what if we remove the annotation |
| 260 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", undef); |
| 261 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 262 |
|
| 263 |
# should be able to create a child |
| 264 |
$imaptalk->create("INBOX.Trash.child"); |
| 265 |
$self->assert_equals('ok', $imaptalk->get_last_completion_response()); |
| 266 |
|
| 267 |
# should not be able to add the annotation back |
| 268 |
$imaptalk->setmetadata("INBOX.Trash", "/private/specialuse", '\\Trash'); |
| 269 |
$self->assert_equals('no', $imaptalk->get_last_completion_response()); |
| 270 |
} |
| 271 |
|
| 272 |
# compile |
| 273 |
1; |