Skip to content

Commit

Permalink
add basic API test for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Sep 14, 2021
1 parent ecaee10 commit e37a2da
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 41 deletions.
3 changes: 2 additions & 1 deletion tests/acceptance/config/behat.yml
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
13 changes: 13 additions & 0 deletions tests/acceptance/features/apiSpaces/ListSpaces.feature
@@ -0,0 +1,13 @@
@api
Feature: upload file
As a user
I want to be able to upload files when passwords are stored with the full hash difficulty
So that I can store and share files securely between multiple client systems

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
Then the HTTP status code should be "200"
119 changes: 119 additions & 0 deletions tests/acceptance/features/bootstrap/GraphApiContext.php
@@ -0,0 +1,119 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\HttpRequestHelper;
use TestHelpers\SetupHelper;

require_once 'bootstrap.php';

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

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

/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
* @throws Exception
*/
public function setUpScenario(BeforeScenarioScope $scope) {
// 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 \Psr\Http\Message\ResponseInterface
*/
public function listSpacesRequest(
$baseUrl,
$user,
$password,
$arguments,
$xRequestId = '',
$body = [],
$headers = []
) {
$fullUrl = $baseUrl;
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
}
$fullUrl .= "graph/v1.0/me/drives/" . $arguments;

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

/**
* Send Graph List Drives Request
*
* @param $baseUrl
* @param $user
* @param $password
* @param string $spaceName
* @param string $xRequestId
* @param array $headers
* @return \Psr\Http\Message\ResponseInterface
*/
public function sendCreateSpaceRequest(
$baseUrl,
$user,
$password,
$spaceName,
$xRequestId = '',
$headers = []
) {
$fullUrl = $baseUrl;
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
}
$fullUrl .= "drives/" . $spaceName;

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

/**
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
*
* @param $depth
*
* @return void
*/
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi($user) {
$this->featureContext->setResponse(
$this->listSpacesRequest(
$this->featureContext->getBaseUrl(),
$user,
$this->featureContext->getPasswordForUser($user),
"",
"",
[],
[]
)
);
}
}
40 changes: 0 additions & 40 deletions tests/acceptance/features/bootstrap/RevaContext.php

This file was deleted.

0 comments on commit e37a2da

Please sign in to comment.