Skip to content

Commit

Permalink
Merge pull request #39793 from owncloud/update-getPersonalSpaceIdForUser
Browse files Browse the repository at this point in the history
[tests-only] update getPersonalSpaceIdForUser to use new oc:id format
  • Loading branch information
phil-davis authored Feb 16, 2022
2 parents 20bf0ed + ee827fd commit 93d0814
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,34 @@ 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) {
$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 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 $decodedId for user $user does not have 2 parts separated by '$separator', so the personal space id cannot be discovered"
);
}
$personalSpaceId = $decodedIdParts[0];
$personalSpaceId = $ocIdParts[0];
} else {
foreach ($json->value as $spaces) {
if ($spaces->driveType === "personal") {
Expand Down

0 comments on commit 93d0814

Please sign in to comment.