From 490bea0eba424e2c41b2ca61b5ac9037899426ad Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Tue, 14 Sep 2021 17:38:08 +0200 Subject: [PATCH 1/8] add basic API test for spaces --- .drone.star | 1 + tests/acceptance/config/behat.yml | 3 +- .../features/apiSpaces/ListSpaces.feature | 15 ++ .../features/bootstrap/GraphApiContext.php | 211 ++++++++++++++++++ .../features/bootstrap/RevaContext.php | 40 ---- 5 files changed, 229 insertions(+), 41 deletions(-) create mode 100644 tests/acceptance/features/apiSpaces/ListSpaces.feature create mode 100644 tests/acceptance/features/bootstrap/GraphApiContext.php delete mode 100644 tests/acceptance/features/bootstrap/RevaContext.php diff --git a/.drone.star b/.drone.star index d0623e667..4941f0d1f 100644 --- a/.drone.star +++ b/.drone.star @@ -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", diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 131a0d0af..9eb1c5c94 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -6,6 +6,7 @@ default: apiAccountsHashDifficulty: paths: - '%paths.base%/../features/apiAccountsHashDifficulty' + - '%paths.base%/../features/apiSpaces' context: &common_ldap_suite_context parameters: ldapAdminPassword: admin @@ -13,7 +14,7 @@ default: ldapGroupsOU: TestGroups ldapInitialUserFilePath: /../../config/ldap-users.ldif contexts: - - RevaContext: + - GraphApiContext: - OccContext: - FeatureContext: &common_feature_context_params baseUrl: http://localhost:8080 diff --git a/tests/acceptance/features/apiSpaces/ListSpaces.feature b/tests/acceptance/features/apiSpaces/ListSpaces.feature new file mode 100644 index 000000000..6bee71614 --- /dev/null +++ b/tests/acceptance/features/apiSpaces/ListSpaces.feature @@ -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 + 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 + And the HTTP status code should be "207" diff --git a/tests/acceptance/features/bootstrap/GraphApiContext.php b/tests/acceptance/features/bootstrap/GraphApiContext.php new file mode 100644 index 000000000..a7429b606 --- /dev/null +++ b/tests/acceptance/features/bootstrap/GraphApiContext.php @@ -0,0 +1,211 @@ +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); + } + + /** + * 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( + $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" + ); + } + } + } + + /** + * @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(), + $user, + $this->featureContext->getPasswordForUser($user), + "", + [], + [], + [] + ) + ); + } +} diff --git a/tests/acceptance/features/bootstrap/RevaContext.php b/tests/acceptance/features/bootstrap/RevaContext.php deleted file mode 100644 index 2a4122202..000000000 --- a/tests/acceptance/features/bootstrap/RevaContext.php +++ /dev/null @@ -1,40 +0,0 @@ -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() - ); - } -} From edbc5e1ffa7a556cbafe88a94de91877a86825e6 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 14:55:14 +0200 Subject: [PATCH 2/8] Update tests/acceptance/features/apiSpaces/ListSpaces.feature Co-authored-by: Artur Neumann --- tests/acceptance/features/apiSpaces/ListSpaces.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/apiSpaces/ListSpaces.feature b/tests/acceptance/features/apiSpaces/ListSpaces.feature index 6bee71614..e01f20ee6 100644 --- a/tests/acceptance/features/apiSpaces/ListSpaces.feature +++ b/tests/acceptance/features/apiSpaces/ListSpaces.feature @@ -8,7 +8,7 @@ Feature: List and create spaces 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 + When user "Alice" lists all available spaces via the GraphApi 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 From 59a1ef88943080acdc2089800dc4af8acf55b56c Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 14:55:23 +0200 Subject: [PATCH 3/8] Update tests/acceptance/features/apiSpaces/ListSpaces.feature Co-authored-by: Artur Neumann --- tests/acceptance/features/apiSpaces/ListSpaces.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/apiSpaces/ListSpaces.feature b/tests/acceptance/features/apiSpaces/ListSpaces.feature index e01f20ee6..f3fd8583e 100644 --- a/tests/acceptance/features/apiSpaces/ListSpaces.feature +++ b/tests/acceptance/features/apiSpaces/ListSpaces.feature @@ -11,5 +11,5 @@ Feature: List and create spaces When user "Alice" lists all available spaces via the GraphApi 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 + When user "Alice" lists the content of the personal space root using the WebDav Api And the HTTP status code should be "207" From 462937b6df1c97d9acda696bab06d9cc0ad36e7b Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 14:55:30 +0200 Subject: [PATCH 4/8] Update tests/acceptance/features/apiSpaces/ListSpaces.feature Co-authored-by: Artur Neumann --- tests/acceptance/features/apiSpaces/ListSpaces.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/apiSpaces/ListSpaces.feature b/tests/acceptance/features/apiSpaces/ListSpaces.feature index f3fd8583e..66c2c6657 100644 --- a/tests/acceptance/features/apiSpaces/ListSpaces.feature +++ b/tests/acceptance/features/apiSpaces/ListSpaces.feature @@ -12,4 +12,4 @@ Feature: List and create spaces Then the HTTP status code should be "200" And the webDavUrl of the personal space has been found When user "Alice" lists the content of the personal space root using the WebDav Api - And the HTTP status code should be "207" + Then the HTTP status code should be "207" From 75e6c46e6657e6b818419890e4211e484524bd62 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 15:18:18 +0200 Subject: [PATCH 5/8] register apiSpaces suite --- tests/acceptance/config/behat.yml | 21 +++++++++++++++++-- .../features/apiSpaces/ListSpaces.feature | 7 +++---- .../features/bootstrap/GraphApiContext.php | 6 ++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 9eb1c5c94..d036656b4 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -6,7 +6,6 @@ default: apiAccountsHashDifficulty: paths: - '%paths.base%/../features/apiAccountsHashDifficulty' - - '%paths.base%/../features/apiSpaces' context: &common_ldap_suite_context parameters: ldapAdminPassword: admin @@ -14,7 +13,6 @@ default: ldapGroupsOU: TestGroups ldapInitialUserFilePath: /../../config/ldap-users.ldif contexts: - - GraphApiContext: - OccContext: - FeatureContext: &common_feature_context_params baseUrl: http://localhost:8080 @@ -29,6 +27,25 @@ default: - PublicWebDavContext: - TrashbinContext: - WebDavPropertiesContext: + apiSpaces: + paths: + - '%paths.base%/../features/apiSpaces' + contexts: + - GraphApiContext: + - OccContext: + - FeatureContext: &common_feature_context_params + baseUrl: http://localhost:8080 + adminUsername: admin + adminPassword: admin + regularUserPassword: 123456 + ocPath: apps/testing/api/v1/occ + - CapabilitiesContext: + - ChecksumContext: + - FavoritesContext: + - FilesVersionsContext: + - PublicWebDavContext: + - TrashbinContext: + - WebDavPropertiesContext: extensions: jarnaiz\JUnitFormatter\JUnitFormatterExtension: diff --git a/tests/acceptance/features/apiSpaces/ListSpaces.feature b/tests/acceptance/features/apiSpaces/ListSpaces.feature index 66c2c6657..d4dbdeb8f 100644 --- a/tests/acceptance/features/apiSpaces/ListSpaces.feature +++ b/tests/acceptance/features/apiSpaces/ListSpaces.feature @@ -8,8 +8,7 @@ Feature: List and create spaces Scenario: list own spaces Given user "Alice" has been created with default attributes and without skeleton files - When user "Alice" lists all available spaces via the GraphApi + And user "Alice" lists all available spaces via the GraphApi Then the HTTP status code should be "200" - And the webDavUrl of the personal space has been found - When user "Alice" lists the content of the personal space root using the WebDav Api - Then the HTTP status code should be "207" + And user "Alice" lists the content of the personal space root using the WebDav Api + And the HTTP status code should be "207" diff --git a/tests/acceptance/features/bootstrap/GraphApiContext.php b/tests/acceptance/features/bootstrap/GraphApiContext.php index a7429b606..a5b099aa3 100644 --- a/tests/acceptance/features/bootstrap/GraphApiContext.php +++ b/tests/acceptance/features/bootstrap/GraphApiContext.php @@ -161,7 +161,7 @@ class GraphApiContext implements Context { } /** - * @Then the webDavUrl of the personal space has been found + * Get the webDavUrl of the personal space has been found * * @return void */ @@ -194,8 +194,10 @@ class GraphApiContext implements Context { * * @return void */ - public function theUserListsTheContentOfASpaceRootUsingTheWebDAvApi($user): void + public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi($user): void { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $this->theWebDavUrlOfThePersonalSpaceHasBeenFound(); $this->featureContext->setResponse( $this->sendPropfindRequestToUrl( $this->getPersonalDriveWebDavUrl(), From df4f70917c18ff6a5e4d6352a53461df077b1c08 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 15:23:53 +0200 Subject: [PATCH 6/8] add to drone.star --- .drone.star | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.star b/.drone.star index eeb2b9dff..63091bf15 100644 --- a/.drone.star +++ b/.drone.star @@ -240,6 +240,7 @@ def testPipelines(ctx): if "skip" not in config["localApiTests"] or not config["localApiTests"]["skip"]: pipelines = [ localApiTests(ctx, "ocis", "apiAccountsHashDifficulty", "default"), + localApiTests(ctx, "ocis", "apiSpaces", "default"), ] if "skip" not in config["apiTests"] or not config["apiTests"]["skip"]: From 95112ee26646f451a582fac2b907a775f4d82b63 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 15:29:43 +0200 Subject: [PATCH 7/8] use HTTP::get --- tests/acceptance/features/bootstrap/GraphApiContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/bootstrap/GraphApiContext.php b/tests/acceptance/features/bootstrap/GraphApiContext.php index a5b099aa3..dcff78a26 100644 --- a/tests/acceptance/features/bootstrap/GraphApiContext.php +++ b/tests/acceptance/features/bootstrap/GraphApiContext.php @@ -88,7 +88,7 @@ class GraphApiContext implements Context { } $fullUrl .= "graph/v1.0/me/drives/" . $arguments; - return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'GET', $user, $password, $headers, $body); + return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body); } /** From 72cb487b75095033f0f8d917890769ae67b790c6 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Mon, 18 Oct 2021 15:59:35 +0200 Subject: [PATCH 8/8] add formerly removed RevaContext --- tests/acceptance/config/behat.yml | 1 + .../features/bootstrap/RevaContext.php | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/acceptance/features/bootstrap/RevaContext.php diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index d036656b4..645583040 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -13,6 +13,7 @@ default: ldapGroupsOU: TestGroups ldapInitialUserFilePath: /../../config/ldap-users.ldif contexts: + - RevaContext: - OccContext: - FeatureContext: &common_feature_context_params baseUrl: http://localhost:8080 diff --git a/tests/acceptance/features/bootstrap/RevaContext.php b/tests/acceptance/features/bootstrap/RevaContext.php new file mode 100644 index 000000000..2a4122202 --- /dev/null +++ b/tests/acceptance/features/bootstrap/RevaContext.php @@ -0,0 +1,40 @@ +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() + ); + } +}