Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic API test for spaces #2500

Merged
merged 9 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []):
environment = {
#'OCIS_LOG_LEVEL': 'debug',
"OCIS_URL": "https://ocis-server:9200",
"GRAPH_SPACES_WEBDAV_BASE": "https://ocis-server:9200/dav/spaces/",
"STORAGE_HOME_DRIVER": "%s" % (storage),
"STORAGE_USERS_DRIVER": "%s" % (storage),
"STORAGE_DRIVER_OCIS_ROOT": "/srv/app/tmp/ocis/storage/users",
Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ default:
apiAccountsHashDifficulty:
paths:
- '%paths.base%/../features/apiAccountsHashDifficulty'
- '%paths.base%/../features/apiSpaces'
context: &common_ldap_suite_context
parameters:
ldapAdminPassword: admin
ldapUsersOU: TestUsers
ldapGroupsOU: TestGroups
ldapInitialUserFilePath: /../../config/ldap-users.ldif
contexts:
- RevaContext:
- GraphApiContext:
- OccContext:
- FeatureContext: &common_feature_context_params
baseUrl: http://localhost:8080
Expand Down
15 changes: 15 additions & 0 deletions tests/acceptance/features/apiSpaces/ListSpaces.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@api @skipOnOcV10
Feature: List and create spaces
As a user
I want to be able to work with personal and project spaces to collaborate with individuals and teams

Note - this feature is run in CI with ACCOUNTS_HASH_DIFFICULTY set to the default for production
See https://github.com/owncloud/ocis/issues/1542 and https://github.com/owncloud/ocis/pull/839

Scenario: list own spaces
Given user "Alice" has been created with default attributes and without skeleton files
And user "Alice" lists all available spaces via the GraphApi
micbar marked this conversation as resolved.
Show resolved Hide resolved
Then the HTTP status code should be "200"
And the webDavUrl of the personal space has been found
And user "Alice" lists the content of the personal space root using the WebDav Api
micbar marked this conversation as resolved.
Show resolved Hide resolved
And the HTTP status code should be "207"
micbar marked this conversation as resolved.
Show resolved Hide resolved
211 changes: 211 additions & 0 deletions tests/acceptance/features/bootstrap/GraphApiContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SetupHelper;
use PHPUnit\Framework\Assert;

require_once 'bootstrap.php';

/**
* Context for GraphApi specific steps
*/
class GraphApiContext implements Context {

/**
* @var FeatureContext
*/
private FeatureContext $featureContext;

/**
* @var string
*/
private string $personalDriveWebDavUrl;

/**
* @return string
*/
public function getPersonalDriveWebDavUrl(): string
{
return $this->personalDriveWebDavUrl;
}

/**
* @param string $personalDriveWebDavUrl
*/
public function setPersonalDriveWebDavUrl(string $personalDriveWebDavUrl): void
{
$this->personalDriveWebDavUrl = $personalDriveWebDavUrl;
}
/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
* @throws Exception
*/
public function setUpScenario(BeforeScenarioScope $scope): void
{
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
SetupHelper::init(
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getBaseUrl(),
$this->featureContext->getOcPath()
);
}

/**
* Send Graph List Drives Request
*
* @param $baseUrl
* @param $user
* @param $password
* @param $arguments
* @param string $xRequestId
* @param array $body
* @param array $headers
* @return ResponseInterface
*/
public function listSpacesRequest(
$baseUrl,
$user,
$password,
$arguments,
string $xRequestId = '',
array $body = [],
array $headers = []
) {
$fullUrl = $baseUrl;
if (!str_ends_with($fullUrl, '/')) {
$fullUrl .= '/';
}
$fullUrl .= "graph/v1.0/me/drives/" . $arguments;

return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'GET', $user, $password, $headers, $body);
micbar marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Send Graph List Drives Request
*
* @param $baseUrl
* @param $user
* @param $password
* @param string $spaceName
* @param string $xRequestId
* @param array $headers
* @return ResponseInterface
*/
public function sendCreateSpaceRequest(
micbar marked this conversation as resolved.
Show resolved Hide resolved
$baseUrl,
$user,
$password,
string $spaceName,
string $xRequestId = '',
array $headers = []
): ResponseInterface
{
$fullUrl = $baseUrl;
if (!str_ends_with($fullUrl, '/')) {
$fullUrl .= '/';
}
$fullUrl .= "drives/" . $spaceName;

return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'POST', $user, $password, $headers);
}

/**
* Send Propfind Request to Url
*
* @param $fullUrl
* @param $user
* @param $password
* @param string $xRequestId
* @param array $headers
* @return ResponseInterface
*/
public function sendPropfindRequestToUrl(
$fullUrl,
$user,
$password,
string $xRequestId = '',
array $headers = []
): ResponseInterface
{
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPFIND', $user, $password, $headers);
}

/**
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
*
* @param $user
* @return void
*/
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi($user): void
{
$this->featureContext->setResponse(
$this->listSpacesRequest(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
"",
""
)
);
}

/**
* @Then the webDavUrl of the personal space has been found
*
* @return void
*/
public function theWebDavUrlOfThePersonalSpaceHasBeenFound(): void
{
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
$drives = [];
if (isset(\json_decode($rawBody, true)["value"])) {
$drives = \json_decode($rawBody, true)["value"];
}

Assert::assertArrayHasKey(0, $drives, "No drives were found on that endpoint");

foreach($drives as $drive) {
if (isset($drive["driveType"]) && $drive["driveType"] === "personal") {
$this->setPersonalDriveWebDavUrl($drive["root"]["webDavUrl"]);

Assert::assertNotEmpty(
$drive["root"]["webDavUrl"],
"The personal space attributes contain no webDavUrl"
);
}
micbar marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* @When /^user "([^"]*)" lists the content of the personal space root using the WebDav Api$/
*
* @param $user
*
* @return void
*/
public function theUserListsTheContentOfASpaceRootUsingTheWebDAvApi($user): void
{
$this->featureContext->setResponse(
$this->sendPropfindRequestToUrl(
$this->getPersonalDriveWebDavUrl(),
micbar marked this conversation as resolved.
Show resolved Hide resolved
$user,
$this->featureContext->getPasswordForUser($user),
"",
[],
[],
[]
)
);
}
}
40 changes: 0 additions & 40 deletions tests/acceptance/features/bootstrap/RevaContext.php

This file was deleted.