Debian Codegraph @

cassandane/Cassandane/Cyrus/DBLookup.pm

raw
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::DBLookup;
41 use strict;
42 use warnings;
43 use DateTime;
44 use JSON::XS;
45 use Net::DAVTalk 0.14;
46 use Net::CardDAVTalk 0.05;
47 use Net::CardDAVTalk::VCard;
48 use Data::Dumper;
49 use XML::Spice;
50
51 use lib '.';
52 use base qw(Cassandane::Cyrus::TestCase);
53 use Cassandane::Util::Log;
54
55 sub new
56 {
57 my $class = shift;
58
59 my $config = Cassandane::Config->default()->clone();
60 $config->set(caldav_realm => 'Cassandane');
61 $config->set(httpmodules => 'carddav caldav');
62 $config->set(httpallowcompress => 'no');
63 return $class->SUPER::new({
64 adminstore => 1,
65 config => $config,
66 services => ['imap', 'http'],
67 }, @_);
68 }
69
70 sub set_up
71 {
72 my ($self) = @_;
73 $self->SUPER::set_up();
74 my $service = $self->{instance}->get_service("http");
75 $ENV{DEBUGDAV} = 1;
76 $self->{carddav} = Net::CardDAVTalk->new(
77 user => 'cassandane',
78 password => 'pass',
79 host => $service->host(),
80 port => $service->port(),
81 scheme => 'http',
82 url => '/',
83 expandurl => 1,
84 );
85 }
86
87 sub tear_down
88 {
89 my ($self) = @_;
90 $self->SUPER::tear_down();
91 }
92
93 sub test_email2uids
94 :needs_component_httpd
95 {
96 my ($self) = @_;
97
98 my $CardDAV = $self->{carddav};
99 my $Id = $CardDAV->NewAddressBook('foo');
100 $self->assert_not_null($Id);
101 $self->assert_str_equals($Id, 'foo');
102
103 my $Str = <<EOF;
104 BEGIN:VCARD
105 VERSION:3.0
106 N:Gump;Forrest;;Mr.
107 FN:Forrest Gump
108 ORG:Bubba Gump Shrimp Co.
109 TITLE:Shrimp Man
110 EMAIL;TYPE=INTERNET:user\@example.com
111 REV:2008-04-24T19:52:43Z
112 END:VCARD
113 EOF
114
115 my $VCard = Net::CardDAVTalk::VCard->new_fromstring($Str);
116
117 my $uid = $CardDAV->NewContact($Id, $VCard);
118
119 my $res = $CardDAV->Request('GET', '/dblookup/email2uids', '',
120 User => 'cassandane',
121 Key => "user\@example.com",
122 Mailbox => 'foo',
123 );
124
125 # XXX: actually compare to the UID
126 }
127
128 sub test_email2details
129 :min_version_3_1 :needs_component_httpd
130 {
131 my ($self) = @_;
132
133 my $CardDAV = $self->{carddav};
134 my $Id = $CardDAV->NewAddressBook('foo');
135 $self->assert_not_null($Id);
136 $self->assert_str_equals($Id, 'foo');
137
138 my $Str = <<EOF;
139 BEGIN:VCARD
140 VERSION:3.0
141 N:Gump;Forrest;;Mr.
142 FN:Forrest Gump
143 ORG:Bubba Gump Shrimp Co.
144 TITLE:Shrimp Man
145 EMAIL;TYPE=INTERNET:user\@example.com
146 REV:2008-04-24T19:52:43Z
147 END:VCARD
148 EOF
149
150 my $VCard = Net::CardDAVTalk::VCard->new_fromstring($Str);
151
152 my $uid = $CardDAV->NewContact($Id, $VCard);
153
154 my $res = $CardDAV->Request('GET', '/dblookup/email2details', '',
155 User => 'cassandane',
156 Key => "user\@example.com",
157 Mailbox => 'foo',
158 );
159
160 # XXX: actually compare to the UID
161 }
162
163 1;