first api test for ocm
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @author Viktor Scharf <scharf.vi@gmail.com>
|
||||
* @copyright Copyright (c) 2024 Viktor Scharf <scharf.vi@gmail.com>
|
||||
*/
|
||||
|
||||
namespace TestHelpers;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
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',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 $xRequestId
|
||||
* @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 $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
?string $email = null,
|
||||
?string $description = null
|
||||
): ResponseInterface {
|
||||
$body['params'] = [
|
||||
"description" => $description,
|
||||
"recipient" => $email
|
||||
];
|
||||
$url = self::getFullUrl($baseUrl, 'generate-invite');
|
||||
return HttpRequestHelper::post(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders(),
|
||||
\json_encode($body)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $token
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function acceptInvitation(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $user,
|
||||
string $password,
|
||||
string $token
|
||||
): ResponseInterface {
|
||||
$body = [
|
||||
"token" => $token,
|
||||
"providerDomain" => 'ocis-server'
|
||||
];
|
||||
$url = self::getFullUrl($baseUrl, 'accept-invite');
|
||||
return HttpRequestHelper::post(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
self::getRequestHeaders(),
|
||||
\json_encode($body)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -357,6 +357,14 @@ default:
|
||||
- PublicWebDavContext:
|
||||
- OcisConfigContext:
|
||||
|
||||
apiOcm:
|
||||
paths:
|
||||
- "%paths.base%/../features/apiOcm"
|
||||
context: *common_ldap_suite_context
|
||||
contexts:
|
||||
- FeatureContext: *common_feature_context_params
|
||||
- OcmContext:
|
||||
|
||||
extensions:
|
||||
rdx\behatvars\BehatVariablesExtension: ~
|
||||
|
||||
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
Feature: an user shares resources usin ScienceMesh application
|
||||
As a user
|
||||
I want to share resources between different ocis instances
|
||||
|
||||
Background:
|
||||
Given these users have been created with default attributes and without skeleton files:
|
||||
| username |
|
||||
| Alice |
|
||||
And using server "REMOTE"
|
||||
And user "Brian" has been created with default attributes and without skeleton files
|
||||
|
||||
|
||||
Scenario: user generates invitation
|
||||
Given using server "LOCAL"
|
||||
When "Alice" generates invitation
|
||||
Then the HTTP status code should be "200"
|
||||
When using server "REMOTE"
|
||||
And "Brian" accepts invitation
|
||||
Then the HTTP status code should be "200"
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* @author Viktor Scharf <scharf.vi@gmail.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2024, ownCloud GmbH
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use TestHelpers\OcisHelper;
|
||||
use TestHelpers\OcmHelper;
|
||||
|
||||
/**
|
||||
* Acceptance test steps related to testing sharing ng features
|
||||
*/
|
||||
class OcmContext implements Context {
|
||||
private FeatureContext $featureContext;
|
||||
private string $invitationToken;
|
||||
|
||||
/**
|
||||
* This will run before EVERY scenario.
|
||||
* It will set the properties for this object.
|
||||
*
|
||||
* @BeforeScenario
|
||||
*
|
||||
* @param BeforeScenarioScope $scope
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(BeforeScenarioScope $scope): void {
|
||||
if (OcisHelper::isTestingOnReva()) {
|
||||
return;
|
||||
}
|
||||
// Get the environment
|
||||
$environment = $scope->getEnvironment();
|
||||
// Get all the contexts you need in this context from here
|
||||
$this->featureContext = $environment->getContext('FeatureContext');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When :user generates invitation
|
||||
* @When :user generates invitation with email :email and description :description
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $email
|
||||
* @param string $description
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userGeneratesInvitation(string $user, $email = null, $description = null): void {
|
||||
$response = OcmHelper::createInvitation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$email,
|
||||
$description
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->invitationToken = $this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())['token'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @When :user accepts invitation
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userAcceptsInvitation(string $user): void {
|
||||
$response = OcmHelper::acceptInvitation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$this->invitationToken
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
[
|
||||
{
|
||||
"name": "ocis-server:9200",
|
||||
"full_name": "first-ocis-instance",
|
||||
"organization": "Owncloud",
|
||||
"domain": "ocis-server",
|
||||
"homepage": "https://owncloud.com",
|
||||
"services": [
|
||||
{
|
||||
"endpoint": {
|
||||
"type": {
|
||||
"name": "OCM",
|
||||
"description": "CERNBox Open Cloud Mesh API"
|
||||
},
|
||||
"name": "CERNBox - OCM API",
|
||||
"path": "https://ocis-server:9200/ocm/",
|
||||
"is_monitored": true
|
||||
},
|
||||
"api_version": "0.0.1",
|
||||
"host": "ocis-server:9200"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "federation-ocis-server:9200",
|
||||
"full_name": "Federation ocis",
|
||||
"organization": "Owncloud",
|
||||
"domain": "federation-ocis-server",
|
||||
"homepage": "https://owncloud.com",
|
||||
"services": [
|
||||
{
|
||||
"endpoint": {
|
||||
"type": {
|
||||
"name": "OCM",
|
||||
"description": "CERNBox Open Cloud Mesh API"
|
||||
},
|
||||
"name": "CERNBox - OCM API",
|
||||
"path": "https:federation-ocis-server:9200/ocm/",
|
||||
"is_monitored": true
|
||||
},
|
||||
"api_version": "0.0.1",
|
||||
"host": "federation-ocis-server:9200"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user