| 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::MurderJMAP; |
| 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, @args) = @_; |
| 55 |
|
| 56 |
my $config = Cassandane::Config->default()->clone(); |
| 57 |
$config->set('conversations' => 'yes'); |
| 58 |
$config->set_bits('httpmodules', 'jmap'); |
| 59 |
|
| 60 |
my $self = $class->SUPER::new({ |
| 61 |
config => $config, |
| 62 |
httpmurder => 1, |
| 63 |
jmap => 1, |
| 64 |
adminstore => 1 |
| 65 |
}, @args); |
| 66 |
|
| 67 |
$self->needs('component', 'murder'); |
| 68 |
$self->needs('component', 'jmap'); |
| 69 |
return $self; |
| 70 |
} |
| 71 |
|
| 72 |
sub set_up |
| 73 |
{ |
| 74 |
my ($self) = @_; |
| 75 |
$self->SUPER::set_up(); |
| 76 |
} |
| 77 |
|
| 78 |
sub tear_down |
| 79 |
{ |
| 80 |
my ($self) = @_; |
| 81 |
$self->SUPER::tear_down(); |
| 82 |
} |
| 83 |
|
| 84 |
sub test_aaa_setup |
| 85 |
{ |
| 86 |
my ($self) = @_; |
| 87 |
|
| 88 |
# does everything set up and tear down cleanly? |
| 89 |
$self->assert(1); |
| 90 |
} |
| 91 |
|
| 92 |
# XXX This can't pass because we don't support multiple murder services |
| 93 |
# XXX at once, but renaming out the "bogus" and running it, and it failing, |
| 94 |
# XXX proves the infrastructure to prevent requesting both works. |
| 95 |
sub bogustest_aaa_imapjmap_setup |
| 96 |
:IMAPMurder |
| 97 |
{ |
| 98 |
my ($self) = @_; |
| 99 |
|
| 100 |
# does everything set up and tear down cleanly? |
| 101 |
$self->assert(1); |
| 102 |
} |
| 103 |
|
| 104 |
sub test_frontend_commands |
| 105 |
:min_version_3_5 |
| 106 |
{ |
| 107 |
my ($self) = @_; |
| 108 |
my $result; |
| 109 |
|
| 110 |
my $frontend_svc = $self->{frontend}->get_service("http"); |
| 111 |
my $frontend_host = $frontend_svc->host(); |
| 112 |
my $frontend_port = $frontend_svc->port(); |
| 113 |
my $proxy_re = qr{ |
| 114 |
\b |
| 115 |
( localhost | $frontend_host ) |
| 116 |
: $frontend_port |
| 117 |
\b |
| 118 |
}x; |
| 119 |
|
| 120 |
my $frontend_jmap = Mail::JMAPTalk->new( |
| 121 |
user => 'cassandane', |
| 122 |
password => 'pass', |
| 123 |
host => $frontend_host, |
| 124 |
port => $frontend_port, |
| 125 |
scheme => 'http', |
| 126 |
url => '/jmap/', |
| 127 |
); |
| 128 |
|
| 129 |
# upload a blob |
| 130 |
my ($resp, $data) = $frontend_jmap->Upload("some test", "text/plain"); |
| 131 |
|
| 132 |
# request should have been proxied |
| 133 |
$self->assert_matches($proxy_re, $resp->{headers}{via}); |
| 134 |
|
| 135 |
# download the same blob |
| 136 |
$resp = $frontend_jmap->Download({ accept => 'text/plain' }, |
| 137 |
'cassandane', $data->{blobId}); |
| 138 |
|
| 139 |
# request should have been proxied |
| 140 |
$self->assert_matches($proxy_re, $resp->{headers}{via}); |
| 141 |
|
| 142 |
# content should match |
| 143 |
$self->assert_str_equals('text/plain', $resp->{headers}{'content-type'}); |
| 144 |
$self->assert_str_equals('some test', $resp->{content}); |
| 145 |
|
| 146 |
# XXX test other commands |
| 147 |
} |
| 148 |
|
| 149 |
sub test_backend1_commands |
| 150 |
:min_version_3_5 |
| 151 |
{ |
| 152 |
my ($self) = @_; |
| 153 |
my $result; |
| 154 |
|
| 155 |
my $backend1_svc = $self->{instance}->get_service("http"); |
| 156 |
my $backend1_host = $backend1_svc->host(); |
| 157 |
my $backend1_port = $backend1_svc->port(); |
| 158 |
|
| 159 |
my $backend1_jmap = Mail::JMAPTalk->new( |
| 160 |
user => 'cassandane', |
| 161 |
password => 'pass', |
| 162 |
host => $backend1_host, |
| 163 |
port => $backend1_port, |
| 164 |
scheme => 'http', |
| 165 |
url => '/jmap/', |
| 166 |
); |
| 167 |
|
| 168 |
# upload a blob |
| 169 |
my ($resp, $data) = $backend1_jmap->Upload("some test", "text/plain"); |
| 170 |
|
| 171 |
# request should not have been proxied |
| 172 |
$self->assert_null($resp->{headers}{via}); |
| 173 |
|
| 174 |
# download the same blob |
| 175 |
$resp = $backend1_jmap->Download({ accept => 'text/plain' }, |
| 176 |
'cassandane', $data->{blobId}); |
| 177 |
|
| 178 |
# request should not have been proxied |
| 179 |
$self->assert_null($resp->{headers}{via}); |
| 180 |
|
| 181 |
# content should match |
| 182 |
$self->assert_str_equals('text/plain', $resp->{headers}{'content-type'}); |
| 183 |
$self->assert_str_equals('some test', $resp->{content}); |
| 184 |
|
| 185 |
# XXX test other commands |
| 186 |
} |
| 187 |
|
| 188 |
sub test_backend2_commands |
| 189 |
:min_version_3_5 |
| 190 |
{ |
| 191 |
my ($self) = @_; |
| 192 |
my $result; |
| 193 |
|
| 194 |
my $backend2_svc = $self->{backend2}->get_service("http"); |
| 195 |
my $backend2_host = $backend2_svc->host(); |
| 196 |
my $backend2_port = $backend2_svc->port(); |
| 197 |
|
| 198 |
my $backend2_jmap = Mail::JMAPTalk->new( |
| 199 |
user => 'cassandane', |
| 200 |
password => 'pass', |
| 201 |
host => $backend2_host, |
| 202 |
port => $backend2_port, |
| 203 |
scheme => 'http', |
| 204 |
url => '/jmap/', |
| 205 |
); |
| 206 |
|
| 207 |
# try to upload a blob |
| 208 |
my ($resp, $data) = $backend2_jmap->Upload("some test", "text/plain"); |
| 209 |
|
| 210 |
# user doesn't exist on this backend, so upload url should not exist |
| 211 |
$self->assert_num_equals(404, $resp->{status}); |
| 212 |
$self->assert_str_equals('Not Found', $resp->{reason}); |
| 213 |
|
| 214 |
$self->assert_null($data); |
| 215 |
|
| 216 |
# # XXX test other commands |
| 217 |
} |
| 218 |
|
| 219 |
1; |