Debian Codegraph @

cassandane/Cassandane/Cyrus/SyncProto.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2022 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::SyncProto;
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 use Data::Dumper;
49 use Cyrus::SyncProto;
50 use Cyrus::AccountSync;
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_syncproto_dump_restore
71 {
72 my ($self) = @_;
73
74 xlog $self, "Create folders";
75 my $imaptalk = $self->{store}->get_client();
76 $imaptalk->create("subfolder");
77 $imaptalk->subscribe("subfolder");
78 $imaptalk->create("Sent");
79 $imaptalk->setmetadata("Sent", "/private/specialuse", "\\Sent");
80
81 xlog $self, "Create messages";
82 $self->make_message("Message A");
83 $self->{store}->set_folder("INBOX.subfolder");
84 $self->make_message("Message B");
85 $self->make_message("Message C");
86
87 $imaptalk->select("INBOX");
88 $imaptalk->store("1", "+flags", "\\Seen");
89 $imaptalk->store("1", "+flags", "aflag");
90
91 my $adminstore = $self->{adminstore};
92 my $admintalk = $adminstore->get_client();
93 my $sp = Cyrus::SyncProto->new($admintalk);
94 my $as = Cyrus::AccountSync->new($sp);
95 my $data = $as->dump_user(username => 'cassandane');
96 $self->assert_null($as->dump_user(username => 'newuser'));
97 $as->undump_user(username => 'newuser', data => $data);
98 my $newdata = $as->dump_user(username => 'newuser');
99 $self->assert_deep_equals($data, $newdata);
100 $as->delete_user(username => 'newuser');
101 $self->assert_null($as->dump_user(username => 'newuser'));
102 }
103
104 1;