Debian Codegraph @

cassandane/Cassandane/Cyrus/JMAPQuota.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2024 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::JMAPQuota;
41 use strict;
42 use warnings;
43 use JSON;
44 use JSON::XS;
45 use Mail::JMAPTalk 0.13;
46 use Data::Dumper;
47
48 use lib '.';
49 use base qw(Cassandane::Cyrus::TestCase);
50 use Cassandane::Util::Log;
51
52 use charnames ':full';
53
54 sub new
55 {
56 my ($class, @args) = @_;
57
58 my $config = Cassandane::Config->default()->clone();
59
60 $config->set(caldav_realm => 'Cassandane',
61 conversations => 'yes',
62 httpmodules => 'jmap caldav carddav',
63 httpallowcompress => 'no');
64
65 return $class->SUPER::new({
66 config => $config,
67 jmap => 1,
68 deliver => 1,
69 adminstore => 1,
70 services => [ 'imap', 'sieve', 'http' ]
71 }, @args);
72 }
73
74 sub set_up
75 {
76 my ($self) = @_;
77 $self->SUPER::set_up();
78 $self->{jmap}->DefaultUsing([
79 'urn:ietf:params:jmap:core',
80 'urn:ietf:params:jmap:quota',
81 'urn:ietf:params:jmap:mail',
82 'urn:ietf:params:jmap:calendars',
83 'urn:ietf:params:jmap:sieve',
84 ]);
85 }
86
87 sub _set_quotaroot
88 {
89 my ($self, $quotaroot) = @_;
90 $self->{quotaroot} = $quotaroot;
91 }
92
93 # Utility function to set quota limits and check that it stuck
94 sub _set_limits
95 {
96 my ($self, %resources) = @_;
97 my $admintalk = $self->{adminstore}->get_client();
98
99 my $quotaroot = delete $resources{quotaroot} || $self->{quotaroot};
100 my @quotalist;
101 foreach my $resource (keys %resources)
102 {
103 my $limit = $resources{$resource}
104 or die "No limit specified for $resource";
105 push(@quotalist, uc($resource), $limit);
106 }
107 $self->{limits}->{$quotaroot} = { @quotalist };
108 $admintalk->setquota($quotaroot, \@quotalist);
109 $self->assert_str_equals('ok', $admintalk->get_last_completion_response());
110 }
111
112 sub tear_down
113 {
114 my ($self) = @_;
115 $self->SUPER::tear_down();
116 }
117
118 use Cassandane::Tiny::Loader 'tiny-tests/JMAPQuota';
119
120 1;