Skip to content

Commit

Permalink
jmap_contact.c: base64url encode vCard UIDs as JMAP ids
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Dec 13, 2024
1 parent b31c5d8 commit ed6f4cc
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ END:VCARD
EOF

my $VCard = Net::CardDAVTalk::VCard->new_fromstring($card);
my $cardId = basename($carddav->NewContact($abookId, $VCard), '.vcf');
$carddav->NewContact($abookId, $VCard);

my $res = $jmap->CallMethods([['Contact/get', {}, "R1"]]);
my $cardId = $res->[0][1]{list}[0]{id};

xlog "Destroy addressbook (with and without onDestroyRemoveContents)";
my $res = $jmap->CallMethods([
$res = $jmap->CallMethods([
['AddressBook/set', {
destroy => [$abookId],
}, 'R1'],
# XXX Change to ContactCard/get once implemented
['Contact/get', {
['ContactCard/get', {
ids => [$cardId],
properties => ['id'],
}, 'R2'],
['AddressBook/set', {
destroy => [$abookId],
onDestroyRemoveContents => JSON::true,
}, 'R3'],
['Contact/get', {
['ContactCard/get', {
ids => [$cardId],
properties => ['id'],
}, 'R2'],
Expand Down
8 changes: 4 additions & 4 deletions cassandane/tiny-tests/JMAPContacts/card_get_localizations
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ sub test_card_get_localizations
# Sample card from RFC 6350
# Second N suffix removed due to vparse bug
# PROP-IDs added so we can easily compare the results
my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'urn:uuid:ae2640cc-234a-4dd9-95cc-3106258445b9';
my $href = "Default/test.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:4.0
UID:$id
UID:$uid
LANGUAGE:es
FN:Gabriel García Márquez
FN;LANGUAGE=jp:ガブリエル・ガルシア・マルケス
Expand Down Expand Up @@ -62,8 +62,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
kind => 'individual',
language => 'es',
vCardProps => [
Expand Down Expand Up @@ -127,6 +126,7 @@ EOF
my $have_jscard = $res->[0][1]{list}[0];

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{'cyrusimap.org:blobId'};
delete $have_jscard->{'cyrusimap.org:size'};
Expand Down
10 changes: 4 additions & 6 deletions cassandane/tiny-tests/JMAPContacts/card_get_ordered_phonetics
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ sub test_card_get_ordered_phonetics
expandurl => 1,
);

my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'urn:uuid:ae2640cc-234a-4dd9-95cc-3106258445b9';
my $href = "Default/test.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:4.0
UID:$id
UID:$uid
N;ALTID=n1;PHONETIC=IPA:/smɪθ/;/d͡ʒɑn/;;;;;
N;JSCOMPS=";1;0";ALTID=n1:Smith;John;;;;;
FN;DERIVED=TRUE:John Smith
Expand All @@ -46,8 +46,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
created => '2023-08-24T14:36:19Z',
vCardProps => [
[ 'version', {}, 'text', '4.0' ]
Expand All @@ -65,6 +64,7 @@ EOF
my $have_jscard = $res->[0][1]{list}[0];

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{'cyrusimap.org:blobId'};
delete $have_jscard->{'cyrusimap.org:size'};
Expand All @@ -73,7 +73,5 @@ EOF
normalize_jscard($want_jscard);
normalize_jscard($have_jscard);

warn Dumper($want_jscard);
warn Dumper($have_jscard);
$self->assert_deep_equals($want_jscard, $have_jscard);
}
8 changes: 4 additions & 4 deletions cassandane/tiny-tests/JMAPContacts/card_get_phonetics
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ sub test_card_get_phonetics
expandurl => 1,
);

my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'urn:uuid:ae2640cc-234a-4dd9-95cc-3106258445b9';
my $href = "Default/test.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:4.0
UID:$id
UID:$uid
LANGUAGE:zho-Hant
FN:孫中山文逸仙
N;ALTID=1;LANGUAGE=zho-Hant:孫;中山;文,逸仙;;
Expand All @@ -47,8 +47,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
language => 'zho-Hant',
vCardProps => [
[ 'version', {}, 'text', '4.0' ]
Expand Down Expand Up @@ -77,6 +76,7 @@ EOF
my $have_jscard = $res->[0][1]{list}[0];

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{'cyrusimap.org:blobId'};
delete $have_jscard->{'cyrusimap.org:size'};
Expand Down
8 changes: 4 additions & 4 deletions cassandane/tiny-tests/JMAPContacts/card_get_v3
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ sub test_card_get_v3
);

# PROP-IDs added so we can easily compare the results
my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $href = "Default/test.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:3.0
UID:$id
UID:$uid
BDAY;PROP-ID=A1:1944-06-07
N:Gump;Forrest;;Mr.
FN:Forrest Gump
Expand All @@ -52,8 +52,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
updated => '2008-04-24T19:52:43Z',
vCardProps => [
[ 'version', {}, 'text', '3.0' ]
Expand Down Expand Up @@ -115,6 +114,7 @@ EOF
$self->assert_not_null($blobid);

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{media}{P1}{blobId};
delete $have_jscard->{'cyrusimap.org:blobId'};
Expand Down
8 changes: 4 additions & 4 deletions cassandane/tiny-tests/JMAPContacts/card_get_v4
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ sub test_card_get_v4
# Sample card from RFC 6350
# Second N suffix removed due to vparse bug
# PROP-IDs added so we can easily compare the results
my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $href = "Default/test.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:4.0
UID;VALUE=TEXT:$id
UID;VALUE=TEXT:$uid
KIND:individual
FN:Simon Perreault
N:Perreault;Simon;;;ing. jr
Expand Down Expand Up @@ -74,8 +74,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
kind => 'individual',
updated => '2023-04-22T19:46:39Z',
vCardProps => [
Expand Down Expand Up @@ -214,6 +213,7 @@ EOF
$self->assert_not_null($s_blobid);

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{media}{P1}{blobId};
delete $have_jscard->{media}{S1}{blobId};
Expand Down
10 changes: 7 additions & 3 deletions cassandane/tiny-tests/JMAPContacts/card_query
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,24 @@ sub test_card_query
my $id2 = $res->[0][1]{created}{"2"}{id};
my $id3 = $res->[0][1]{created}{"3"}{id};
my $id4 = $res->[0][1]{created}{"4"}{id};
my $uid1 = $res->[0][1]{created}{"1"}{uid};
my $uid2 = $res->[0][1]{created}{"2"}{uid};
my $uid3 = $res->[0][1]{created}{"3"}{uid};
my $uid4 = $res->[0][1]{created}{"4"}{uid};

xlog $self, "create card groups";
$res = $jmap->CallMethods([['ContactCard/set', {create => {
"1" => { kind => 'group',
name => { full => "group1" },
members => { $id1 => JSON::true, $id2 => JSON::true }
members => { $uid1 => JSON::true, $uid2 => JSON::true }
},
"2" => { kind => 'group',
name => { full => "group2" },
members => { $id3 => JSON::true }
members => { $uid3 => JSON::true }
},
"3" => { kind => 'group',
name => { full => "group3" },
members => { $id4 => JSON::true }
members => { $uid4 => JSON::true }
}
}}, "R1"]]);

Expand Down
10 changes: 7 additions & 3 deletions cassandane/tiny-tests/JMAPContacts/card_query_shared
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ sub test_card_query_shared
my $id2 = $res->[0][1]{created}{"card2"}{id};
my $id3 = $res->[0][1]{created}{"card3"}{id};
my $id4 = $res->[0][1]{created}{"card4"}{id};
my $uid1 = $res->[0][1]{created}{"card1"}{uid};
my $uid2 = $res->[0][1]{created}{"card2"}{uid};
my $uid3 = $res->[0][1]{created}{"card3"}{uid};
my $uid4 = $res->[0][1]{created}{"card4"}{uid};

xlog $self, "create card groups";
$res = $jmap->CallMethods([ [
Expand All @@ -209,17 +213,17 @@ sub test_card_query_shared
group1 => {
kind => 'group',
name => { full => "group1" },
members => { $id1 => JSON::true, $id2 => JSON::true }
members => { $uid1 => JSON::true, $uid2 => JSON::true }
},
group2 => {
kind => 'group',
name => { full => "group2" },
members => { $id3 => JSON::true }
members => { $uid3 => JSON::true }
},
group3 => {
kind => 'group',
name => { full => "group3" },
members => { $id4 => JSON::true }
members => { $uid4 => JSON::true }
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions cassandane/tiny-tests/JMAPContacts/card_set_state
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ sub test_card_set_state

xlog $self, "create contact";
my $name = 'Mr. John Q. Public, Esq.';
my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';

my $res = $jmap->CallMethods([
['ContactCard/set', {
create => {
"1" => {
'@type' => 'Card',
version => '1.0',
uid => $id,
uid => $uid,
name => { full => $name }
}
}
Expand All @@ -27,7 +27,7 @@ sub test_card_set_state
$self->assert_not_null($res);
$self->assert_str_equals('ContactCard/set', $res->[0][0]);
$self->assert_str_equals('R1', $res->[0][2]);
$id = $res->[0][1]{created}{"1"}{id};
my $id = $res->[0][1]{created}{"1"}{id};
my $state = $res->[0][1]{newState};

xlog $self, "get contact $id";
Expand Down
9 changes: 5 additions & 4 deletions cassandane/tiny-tests/JMAPContacts/card_set_update
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ sub test_card_set_update
expandurl => 1,
);

my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';

my $res = $jmap->CallMethods([
['ContactCard/set', {
create => {
"1" => {
'@type' => 'Card',
version => '1.0',
uid => $id,
uid => $uid,
name => { full => 'John Doe' },
nicknames => {
k391 => {
Expand All @@ -41,6 +41,7 @@ sub test_card_set_update
]);

$self->assert_not_null($res->[0][1]{created}{1});
my $id = $res->[0][1]{created}{1}{id};
my $href = $res->[0][1]{created}{1}{'cyrusimap.org:href'};

$res = $jmap->CallMethods([
Expand Down Expand Up @@ -134,7 +135,7 @@ sub test_card_set_update
]);

my $abookid = $res->[0][1]{created}{"1"}{id};
$href = "$abookid/$id.vcf";
$href = "$abookid/$uid.vcf";

$res = $jmap->CallMethods([
['ContactCard/set', {
Expand All @@ -155,7 +156,7 @@ sub test_card_set_update
$card = $res->{content};
$card =~ s/\r?\n[ \t]+//gs; # unfold long properties

$self->assert_matches(qr/UID:$id/, $card);
$self->assert_matches(qr/UID:$uid/, $card);
$self->assert_matches(qr/NICKNAME;PROP-ID=foo:Doey/, $card);
$self->assert_matches(qr/CATEGORIES:foo/, $card);
$self->assert_matches(qr/REV:/, $card);
Expand Down
5 changes: 3 additions & 2 deletions cassandane/tiny-tests/JMAPContacts/card_set_update_media_blob
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ sub test_card_set_update_media_blob
expandurl => 1,
);

my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';

my $res = $jmap->CallMethods([
['ContactCard/set', {
create => {
"1" => {
'@type' => 'Card',
version => '1.0',
uid => $id,
uid => $uid,
name => { full => 'Jane Doe' },
media => {
res1 => {
Expand All @@ -42,6 +42,7 @@ sub test_card_set_update_media_blob
]);

$self->assert_not_null($res->[0][1]{created}{1});
my $id = $res->[0][1]{created}{1}{id};
my $href = $res->[0][1]{created}{1}{'cyrusimap.org:href'};

$res = $carddav->Request('GET', $href, '',
Expand Down
10 changes: 5 additions & 5 deletions cassandane/tiny-tests/JMAPContacts/cardgroup_get_v3
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ sub test_cardgroup_get_v3
expandurl => 1,
);

my $id = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $uid = 'ae2640cc-234a-4dd9-95cc-3106258445b9';
my $member1 = 'urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af';
my $member2 = 'urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519';
my $href = "Default/$id.vcf";
my $href = "Default/$uid.vcf";
my $card = <<EOF;
BEGIN:VCARD
VERSION:3.0
X-ADDRESSBOOKSERVER-KIND:group
UID:$id
UID:$uid
FN:The Doe Family
N:;;;;
X-ADDRESSBOOKSERVER-MEMBER:$member1
Expand All @@ -48,8 +48,7 @@ EOF
version => '1.0',
addressBookId => 'Default',
'cyrusimap.org:href' => $carddav->fullpath() . $href,
id => $id,
uid => $id,
uid => $uid,
kind => 'group',
vCardProps => [
[ 'version', {}, 'text', '3.0' ]
Expand All @@ -67,6 +66,7 @@ EOF
my $have_jscard = $res->[0][1]{list}[0];

# Delete generated fields
delete $have_jscard->{id};
delete $have_jscard->{blobId};
delete $have_jscard->{'cyrusimap.org:blobId'};
delete $have_jscard->{'cyrusimap.org:size'};
Expand Down
Loading

0 comments on commit ed6f4cc

Please sign in to comment.