From 10f3f9aaf4bdd80e408b055e467a167f1cb86228 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 15 Feb 2022 15:58:43 +0545 Subject: [PATCH 1/2] update getPersonalSpaceIdForUser to use new oc:id format --- tests/TestHelpers/WebDavHelper.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index b6871ddd898d..46da91ac1a24 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -433,19 +433,16 @@ public static function getPersonalSpaceIdForUser(string $baseUrl, string $user, __METHOD__ . " oc:id not found in webdav propfind for user $user - so the personal space id cannot be discovered" ); } - // oc:id should be some base64 encoded string like: - // "NzQ2NGNhZjYtMTc5OS0xMDNjLTkwNDYtYzdiNzRkZWI1ZjYzOjc0NjRjYWY2LTE3OTktMTAzYy05MDQ2LWM3Yjc0ZGViNWY2Mw==" - $idBase64 = $xmlPart[0]->__toString(); - // That should decode to something like: - // "7464caf6-1799-103c-9046-c7b74deb5f63:7464caf6-1799-103c-9046-c7b74deb5f63" - $decodedId = base64_decode($idBase64); - $decodedIdParts = \explode(":", $decodedId); - if (\count($decodedIdParts) !== 2) { + // oc:id should be something like: + // "7464caf6-1799-103c-9046-c7b74deb5f63!7464caf6-1799-103c-9046-c7b74deb5f63" + $ocId = $xmlPart[0]->__toString(); + $ocIdParts = \explode("!", $ocId); + if (\count($ocIdParts) !== 2) { throw new Exception( - __METHOD__ . " the decoded oc:id $decodedId for user $user does not have 2 parts separated by a colon, so the personal space id cannot be discovered" + __METHOD__ . " the oc:id $ocId for user $user does not have 2 parts separated by an exclamation mark, so the personal space id cannot be discovered" ); } - $personalSpaceId = $decodedIdParts[0]; + $personalSpaceId = $ocIdParts[0]; } else { foreach ($json->value as $spaces) { if ($spaces->driveType === "personal") { From ee827fd3affbcf52f24a3109a26f5db57af3e3bc Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 16 Feb 2022 20:24:40 +0545 Subject: [PATCH 2/2] Make getPersonalSpaceIdForUser more flexible --- tests/TestHelpers/WebDavHelper.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 46da91ac1a24..cf4da977bc99 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -433,13 +433,31 @@ public static function getPersonalSpaceIdForUser(string $baseUrl, string $user, __METHOD__ . " oc:id not found in webdav propfind for user $user - so the personal space id cannot be discovered" ); } - // oc:id should be something like: - // "7464caf6-1799-103c-9046-c7b74deb5f63!7464caf6-1799-103c-9046-c7b74deb5f63" - $ocId = $xmlPart[0]->__toString(); - $ocIdParts = \explode("!", $ocId); + $ocIdRawString = $xmlPart[0]->__toString(); + $separator = "!"; + if (\strpos($ocIdRawString, $separator) !== false) { + // The string is not base64-encoded, because the exclamation mark is not in the base64 alphabet. + // We expect to have a string with 2 parts separated by the exclamation mark. + // This is the format introduced in 2022-02 + // oc:id should be something like: + // "7464caf6-1799-103c-9046-c7b74deb5f63!7464caf6-1799-103c-9046-c7b74deb5f63" + // There is no encoding to decode. + $decodedId = $ocIdRawString; + } else { + // fall-back to assuming that the oc:id is base64-encoded + // That is the format used before and up to 2022-02 + // This can be removed after both the edge and master branches of cs3org/reva are using the new format. + // oc:id should be some base64 encoded string like: + // "NzQ2NGNhZjYtMTc5OS0xMDNjLTkwNDYtYzdiNzRkZWI1ZjYzOjc0NjRjYWY2LTE3OTktMTAzYy05MDQ2LWM3Yjc0ZGViNWY2Mw==" + // That should decode to something like: + // "7464caf6-1799-103c-9046-c7b74deb5f63:7464caf6-1799-103c-9046-c7b74deb5f63" + $decodedId = base64_decode($ocIdRawString); + $separator = ":"; + } + $ocIdParts = \explode($separator, $decodedId); if (\count($ocIdParts) !== 2) { throw new Exception( - __METHOD__ . " the oc:id $ocId for user $user does not have 2 parts separated by an exclamation mark, so the personal space id cannot be discovered" + __METHOD__ . " the oc:id $decodedId for user $user does not have 2 parts separated by '$separator', so the personal space id cannot be discovered" ); } $personalSpaceId = $ocIdParts[0];