forked from cyrusimap/cyrus-imapd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jmap_contact: encode vCard v4.0 blobs as data: URI
This fixes a bug where setting an avatar with JMAP Contact/set on an existing vCard 4.0 card resulted in the vCard having a b-encoded PHOTO value. But PHOTO must have a data: URI value in vCard 4.0 Signed-off-by: Robert Stepanek <rsto@fastmailteam.com>
- Loading branch information
Showing
3 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!perl | ||
use Cassandane::Tiny; | ||
|
||
sub test_contact_set_avatar_v4 | ||
:needs_component_jmap | ||
{ | ||
my ($self) = @_; | ||
my $jmap = $self->{jmap}; | ||
my $carddav = $self->{carddav}; | ||
|
||
xlog $self, "Create a v4 vCard over CardDAV"; | ||
my $id = '816ad14a-f9ef-43a8-9039-b57bf321de1f'; | ||
my $href = "Default/$id.vcf"; | ||
my $card = <<EOF; | ||
BEGIN:VCARD | ||
VERSION:4.0 | ||
PRODID:+//IDN bitfire.at//DAVx5/4.2.0.3-gplay ez-vcard/0.11.3 | ||
UID:$id | ||
FN:Foo | ||
N:;Foo;;; | ||
REV:20220504T040120Z | ||
END:VCARD | ||
EOF | ||
$card =~ s/\r?\n/\r\n/gs; | ||
|
||
$carddav->Request('PUT', $href, $card, 'Content-Type' => 'text/vcard'); | ||
|
||
xlog $self, "Get JMAP Contact"; | ||
my $res = $jmap->CallMethods([ | ||
['Contact/get', { | ||
properties => ['avatar', 'x-hasPhoto'], | ||
}, 'R1'] | ||
]); | ||
my $contactId = $res->[0][1]{list}[0]{id}; | ||
$self->assert_not_null($contactId); | ||
$self->assert_null($res->[0][1]{list}[0]{avatar}); | ||
|
||
xlog $self, "Set avatar on contact"; | ||
my $binary = slurp_file(abs_path('data/logo.gif')); | ||
my $data = $jmap->Upload($binary, "image/gif"); | ||
$res = $jmap->CallMethods([ | ||
['Contact/set', { | ||
update => { | ||
$contactId => { | ||
avatar => { | ||
blobId => $data->{blobId}, | ||
type => "image/gif", | ||
} | ||
} | ||
} | ||
}, 'R1'] | ||
]); | ||
my $avatarBlobId = $res->[0][1]{updated}{$contactId}{avatar}{blobId}; | ||
$self->assert_not_null($avatarBlobId); | ||
|
||
xlog $self, "Get vCard over CardDAV as version 4.0"; | ||
$res = $carddav->Request('GET', $href, undef, | ||
"Accept" => "text/vcard; version=4.0"); | ||
my $vcard = Net::CardDAVTalk::VCard->new_fromstring($res->{content}); | ||
my $photo = $vcard->{properties}->{photo}->[0] // undef; | ||
$self->assert(not $photo->{binary}); | ||
$self->assert_equals("data:image/gif;base64,", substr($photo->{value}, 0, 22)); | ||
|
||
xlog $self, "Assert avatar blob contents"; | ||
$data = $jmap->Download('cassandane', $avatarBlobId); | ||
$self->assert($binary eq $data->{content}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters