Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .woodpecker.star
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ config = {
"notification": {
"suites": [
"apiNotification",
"apiGuestLink",
],
"skip": False,
"withRemotePhp": False,
Expand All @@ -265,6 +266,7 @@ config = {
"NOTIFICATIONS_SMTP_INSECURE": True,
"NOTIFICATIONS_SMTP_SENDER": "ownCloud <noreply@example.com>",
"NOTIFICATIONS_DEBUG_ADDR": "0.0.0.0:9174",
"OC_ENABLE_GUEST_LINKS": True,
},
},
"antivirus": {
Expand Down
8 changes: 7 additions & 1 deletion tests/acceptance/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,11 @@ public static function createShareInviteBody(

foreach ($shareeIds as $index => $shareeId) {
$shareType = $shareTypes[$index];
if ($shareType === "guest") {
// guest invitation via email address
$body['recipients'][] = ["email" => $shareeId];
continue;
}
$body['recipients'][] = [
"@libre.graph.recipient.type" => $shareType,
"objectId" => $shareeId
Expand All @@ -1780,7 +1785,8 @@ public static function createShareInviteBody(
$body['@libre.graph.permissions.actions'] = ['libre.graph/driveItem/' . $permissionsAction];
}

if ($expirationDateTime !== null) {
if ($expirationDateTime !== null || \in_array("guest", $shareTypes, true)) {
// guest invitations always send expirationDateTime, like the web client does
$body['expirationDateTime'] = $expirationDateTime;
}
return $body;
Expand Down
125 changes: 125 additions & 0 deletions tests/acceptance/TestHelpers/GuestLinkHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php declare(strict_types=1);
/**
* @author Viktor Scharf OpenCloud GmbH <v.scharf@opencloud.eu>
* @copyright Copyright (c) 2026 OpenCloud GmbH <v.scharf@opencloud.eu>
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace TestHelpers;

use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;

/**
* Helper for the unauthenticated guest links endpoints of the auth-guest service
*/
class GuestLinkHelper {
public const SESSION_COOKIE_NAME = '__Host-oc_guest_session';

/**
* matches the guest link token in a guest link email, e.g. "/g/v1.<share id hash>.<secret>"
*/
public const TOKEN_IN_EMAIL_REGEX = '/\/g\/(v1\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)/';

/**
* @param string $baseUrl
* @param string $action verify/token|verify/pin|renew
*
* @return string
*/
public static function getUrl(string $baseUrl, string $action): string {
return GraphHelper::getBetaFullUrl($baseUrl, "extensions/org.libregraph/guestLinks/$action");
}

/**
* @param array<string, string> $cookies cookie name => value
*
* @return array
*/
public static function getHeaders(array $cookies = []): array {
$headers = ['Content-Type' => 'application/json'];
if ($cookies !== []) {
$headers['Cookie'] = \implode(
'; ',
\array_map(fn ($name, $value) => "$name=$value", \array_keys($cookies), $cookies)
);
}
return $headers;
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $token
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function verifyToken(string $baseUrl, string $xRequestId, string $token): ResponseInterface {
return HttpRequestHelper::post(
self::getUrl($baseUrl, 'verify/token'),
$xRequestId,
null,
null,
self::getHeaders(),
\json_encode(['token' => $token])
);
}

/**
* Returns the Set-Cookie headers of the response, keyed by the cookie name
*
* @param ResponseInterface $response
*
* @return array<string, string>
*/
public static function getSetCookieHeaders(ResponseInterface $response): array {
$setCookies = [];
foreach ($response->getHeader('Set-Cookie') as $setCookie) {
$name = \trim(\explode('=', \explode(';', $setCookie, 2)[0], 2)[0]);
$setCookies[$name] = $setCookie;
}
return $setCookies;
}

/**
* Returns the value of a cookie set by the response, or null when it is not set or is cleared
*
* @param string $setCookie
*
* @return string|null
*/
public static function getCookieValue(string $setCookie): ?string {
$value = \explode('=', \explode(';', $setCookie, 2)[0], 2)[1] ?? '';
$attributes = \strtolower($setCookie);
if ($value === '' || \str_contains($attributes, 'max-age=0') || \preg_match('/max-age=-\d/', $attributes)) {
return null;
}
return $value;
}

/**
* Returns the raw Set-Cookie header of the guest session cookie, or null
*
* @param ResponseInterface $response
*
* @return string|null
*/
public static function getSessionSetCookieHeader(ResponseInterface $response): ?string {
return self::getSetCookieHeaders($response)[self::SESSION_COOKIE_NAME] ?? null;
}

}
Loading
Loading