Files

192 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2024-06-19 16:15:38 +02:00
<?php declare(strict_types=1);
/**
* ownCloud
*
* @author Viktor Scharf <scharf.vi@gmail.com>
* @copyright Copyright (c) 2024 Viktor Scharf <scharf.vi@gmail.com>
*
* 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/>
*
2024-06-19 16:15:38 +02:00
*/
namespace TestHelpers;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
/**
* A helper class for managing federation server requests
*/
class OcmHelper {
/**
* @return string[]
*/
private static function getRequestHeaders(): array {
return [
'Content-Type' => 'application/json',
];
}
2024-06-19 16:15:38 +02:00
/**
* @param string $baseUrl
* @param string $path
*
* @return string
*/
public static function getFullUrl(string $baseUrl, string $path): string {
$fullUrl = $baseUrl;
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
}
$fullUrl .= 'sciencemesh/' . $path;
return $fullUrl;
}
/**
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string|null $email
* @param string|null $description
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function createInvitation(
string $baseUrl,
string $user,
string $password,
?string $email = null,
?string $description = null,
2024-06-19 16:15:38 +02:00
): ResponseInterface {
2024-09-12 10:08:43 +02:00
$body = [
2025-06-19 10:34:17 +05:45
"description" => $description,
2025-06-19 10:46:56 +05:45
"recipient" => $email,
2024-06-19 16:15:38 +02:00
];
$url = self::getFullUrl($baseUrl, 'generate-invite');
return HttpRequestHelper::post(
$url,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body),
2024-06-19 16:15:38 +02:00
);
}
/**
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $token
2024-07-03 22:24:14 +02:00
* @param string $providerDomain
2024-06-19 16:15:38 +02:00
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function acceptInvitation(
string $baseUrl,
string $user,
string $password,
2024-07-03 22:24:14 +02:00
string $token,
string $providerDomain,
2024-06-19 16:15:38 +02:00
): ResponseInterface {
$body = [
2025-06-19 10:34:17 +05:45
"token" => $token,
2025-06-19 10:46:56 +05:45
"providerDomain" => $providerDomain,
2024-06-19 16:15:38 +02:00
];
$url = self::getFullUrl($baseUrl, 'accept-invite');
return HttpRequestHelper::post(
$url,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body),
2024-06-19 16:15:38 +02:00
);
}
2024-07-08 15:16:21 +02:00
/**
* @param string $baseUrl
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function findAcceptedUsers(
string $baseUrl,
string $user,
string $password,
2024-07-08 15:16:21 +02:00
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'find-accepted-users');
return HttpRequestHelper::get(
$url,
$user,
$password,
self::getRequestHeaders(),
2024-07-08 15:16:21 +02:00
);
}
2024-07-12 14:41:16 +02:00
/**
* @param string $baseUrl
* @param string $user
* @param string $password
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function listInvite(
string $baseUrl,
string $user,
string $password,
2024-07-12 14:41:16 +02:00
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'list-invite');
return HttpRequestHelper::get(
$url,
$user,
$password,
self::getRequestHeaders(),
2024-07-12 14:41:16 +02:00
);
}
2024-10-02 17:45:26 +02:00
/**
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $userId
* @param string $idp
*
* @return ResponseInterface
* @throws GuzzleException
*/
public static function deleteConnection(
string $baseUrl,
string $user,
string $password,
string $userId,
string $idp,
2024-10-02 17:45:26 +02:00
): ResponseInterface {
$url = self::getFullUrl($baseUrl, 'delete-accepted-user');
$body = [
"idp" => $idp,
2025-06-19 10:46:56 +05:45
"user_id" => $userId,
2024-10-02 17:45:26 +02:00
];
return HttpRequestHelper::delete(
$url,
$user,
$password,
self::getRequestHeaders(),
\json_encode($body),
2024-10-02 17:45:26 +02:00
);
}
2024-06-19 16:15:38 +02:00
}