Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sync errors for card creation with the same uri from different sources #32057

Merged
merged 1 commit into from
Jan 5, 2023

Conversation

miaulalala
Copy link
Contributor

When syncing the system address book,, the email address is used as the uri.

This leads to errors when two different backends are providing the same email addresses and try to create VCards for those entries separately.

Since the code should not be forced to decide which data providing backend is the source of truth, the uri should include the backend identifier to make uris more unique and dependent on their source.

@miaulalala miaulalala added bug 3. to review Waiting for reviews feature: carddav Related to CardDAV internals labels Apr 21, 2022
@miaulalala miaulalala requested a review from skjnldsv April 21, 2022 19:32
@miaulalala miaulalala self-assigned this Apr 21, 2022
@miaulalala
Copy link
Contributor Author

@skjnldsv could you check this branch out and re- test it on your setup please?

apps/dav/lib/CardDAV/Converter.php Outdated Show resolved Hide resolved
apps/dav/lib/CardDAV/Converter.php Outdated Show resolved Hide resolved
apps/dav/lib/CardDAV/SyncService.php Outdated Show resolved Hide resolved
@miaulalala miaulalala force-pushed the fix/make-UID-more-unique-for-systemaddressbook branch from 4228fc5 to 2f39ea2 Compare April 22, 2022 11:45
@miaulalala miaulalala requested a review from tcitworld April 22, 2022 14:07
@miaulalala
Copy link
Contributor Author

/rebase

@nextcloud-command nextcloud-command force-pushed the fix/make-UID-more-unique-for-systemaddressbook branch from 2f39ea2 to 2326a12 Compare November 3, 2022 09:38
apps/dav/lib/CardDAV/SyncService.php Fixed Show fixed Hide fixed
apps/dav/lib/CardDAV/SyncService.php Fixed Show fixed Hide fixed
apps/dav/lib/CardDAV/SyncService.php Fixed Show fixed Hide fixed
apps/dav/lib/CardDAV/SyncService.php Fixed Show fixed Hide fixed
@miaulalala
Copy link
Contributor Author

This integration test fails:

  Scenario: users can not be searched by id
    Given user "user0" exists
    And user "user1" exists
    And As an "admin"
    And sending "PUT" to "/cloud/users/user1" with
      | key | displayname |
      | value | Test name |
    When Logging in using web as "user0"
    And searching for contacts matching with "user"
    Then the list of searched contacts has "0" contacts

@ChristophWurst do you know how to fix this? I have never written tests like these before

@miaulalala
Copy link
Contributor Author

/rebase

@nextcloud-command nextcloud-command force-pushed the fix/make-UID-more-unique-for-systemaddressbook branch from 2326a12 to 7c5d76d Compare December 15, 2022 10:38
@miaulalala
Copy link
Contributor Author

This integration test fails:

  Scenario: users can not be searched by id
    Given user "user0" exists
    And user "user1" exists
    And As an "admin"
    And sending "PUT" to "/cloud/users/user1" with
      | key | displayname |
      | value | Test name |
    When Logging in using web as "user0"
    And searching for contacts matching with "user"
    Then the list of searched contacts has "0" contacts

The UID is matching for the backend - search term "user" and uid "users:foo-baz-bar"

Since the VCard rfc doesn't explicitly specify a format, I will md5 hash the composite uid value to obscure the backend name for the search. this doesn't need to be cryptographically safe.

@@ -274,7 +274,7 @@
$allCards = $this->backend->getCards($systemAddressBook['id']);
foreach ($allCards as $card) {
$vCard = Reader::read($card['carddata']);
$uid = $vCard->UID->getValue();
$uid = isset($vCard->{'X-NEXTCLOUD-UID'}) ? $vCard->{'X-NEXTCLOUD-UID'}->getValue() : $vCard->UID->getValue();

Check notice

Code scanning / Psalm

PossiblyNullReference

Cannot call method getValue on possibly null value
@miaulalala
Copy link
Contributor Author

/rebase

…ackends

Signed-off-by: Anna Larch <anna@nextcloud.com>
@nextcloud-command nextcloud-command force-pushed the fix/make-UID-more-unique-for-systemaddressbook branch from fa2a52f to ddcee3d Compare January 5, 2023 12:20
@miaulalala
Copy link
Contributor Author

Drone failure unrelated:

There was 1 failure:
--
655 |  
656 | 1) OCA\Settings\Tests\Controller\CheckSetupControllerTest::testCheck
657 | Failed asserting that two objects are equal.

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jan 5, 2023
@skjnldsv skjnldsv merged commit 4cda132 into master Jan 5, 2023
@skjnldsv skjnldsv deleted the fix/make-UID-more-unique-for-systemaddressbook branch January 5, 2023 14:44
@nickvergessen
Copy link
Member

Drone failure unrelated:

However this is not unrelated:

> integration-contacts-menu

--- Failed scenarios:
    /drone/src/build/integration/features/contacts-menu.feature:27

@nickvergessen
Copy link
Member

Also this is a breaking change for OCP\Contacts\ContactsMenu\IProvider that read \OCP\Contacts\ContactsMenu\IEntry::getProperty('UID')

nickvergessen added a commit that referenced this pull request Jan 12, 2023
This restores the previous behaviour from before
#32057

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen
Copy link
Member

Restored the original content (userid) of \OCP\Contacts\ContactsMenu\IEntry::getProperty('UID') via #36110

@nickvergessen
Copy link
Member

Reverted in #36131

Also the sync service assumed the UID is the user id:

// remove no longer existing
$allCards = $this->backend->getCards($systemAddressBook['id']);
foreach ($allCards as $card) {
$vCard = Reader::read($card['carddata']);
$uid = $vCard->UID->getValue();
// load backend and see if user exists
if (!$this->userManager->userExists($uid)) {
$this->deleteUser($card['uri']);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug feature: carddav Related to CardDAV internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants