From b36390e0177f5fc61ee160837f1372d5cb47b36d Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 31 Jul 2020 12:24:01 +0545 Subject: [PATCH] Add local API acceptance tests --- .codacy.yml | 1 + .drone.star | 46 ++++++- .gitignore | 9 +- Makefile | 18 +++ composer.json | 18 +++ tests/acceptance/config/behat.yml | 30 +++++ .../apiOcisSpecific/ocsDELETEAuth.feature | 27 +++++ .../apiOcisSpecific/ocsGETAuth.feature | 112 ++++++++++++++++++ .../apiOcisSpecific/ocsPOSTAuth.feature | 35 ++++++ .../apiOcisSpecific/ocsPUTAuth.feature | 18 +++ .../features/bootstrap/RevaContext.php | 40 +++++++ .../features/bootstrap/bootstrap.php | 14 +++ vendor-bin/behat/composer.json | 22 ++++ 13 files changed, 387 insertions(+), 3 deletions(-) create mode 100644 composer.json create mode 100644 tests/acceptance/config/behat.yml create mode 100644 tests/acceptance/features/apiOcisSpecific/ocsDELETEAuth.feature create mode 100644 tests/acceptance/features/apiOcisSpecific/ocsGETAuth.feature create mode 100644 tests/acceptance/features/apiOcisSpecific/ocsPOSTAuth.feature create mode 100644 tests/acceptance/features/apiOcisSpecific/ocsPUTAuth.feature create mode 100644 tests/acceptance/features/bootstrap/RevaContext.php create mode 100644 tests/acceptance/features/bootstrap/bootstrap.php create mode 100644 vendor-bin/behat/composer.json diff --git a/.codacy.yml b/.codacy.yml index 855b4f298b..02e0cf2ebe 100644 --- a/.codacy.yml +++ b/.codacy.yml @@ -4,5 +4,6 @@ exclude_paths: - changelog/** - docs/** - pkg/proto/** + - tests/acceptance/features/bootstrap/* ... diff --git a/.drone.star b/.drone.star index aa6c9cd1aa..e78a4fda24 100644 --- a/.drone.star +++ b/.drone.star @@ -194,7 +194,7 @@ def apiTests(ctx, coreBranch = 'master', coreCommit = ''): build() + ocisServer() + [ { - 'name': 'oC10APIAcceptanceTests', + 'name': 'clone-test-repos', 'image': 'owncloudci/php:7.2', 'pull': 'always', 'environment' : { @@ -213,7 +213,49 @@ def apiTests(ctx, coreBranch = 'master', coreCommit = ''): 'cd /srv/app/testrunner', ] + ([ 'git checkout %s' % (coreCommit) - ] if coreCommit != '' else []) + [ + ] if coreCommit != '' else []), + 'volumes': [{ + 'name': 'gopath', + 'path': '/srv/app', + }] + }, + { + 'name': 'LocalAcceptanceTests', + 'image': 'owncloudci/php:7.2', + 'pull': 'always', + 'environment' : { + 'TEST_SERVER_URL': 'http://ocis-server:9140', + 'OCIS_REVA_DATA_ROOT': '/srv/app/tmp/reva/', + 'SKELETON_DIR': '/srv/app/tmp/testing/data/apiSkeleton', + 'TEST_EXTERNAL_USER_BACKENDS':'true', + 'REVA_LDAP_HOSTNAME':'ldap', + 'TEST_OCIS':'true', + 'PATH_TO_CORE': '/srv/app/testrunner' + }, + 'commands': [ + 'make test-acceptance-api', + ], + 'volumes': [{ + 'name': 'gopath', + 'path': '/srv/app', + }] + }, + { + 'name': 'oC10APIAcceptanceTests', + 'image': 'owncloudci/php:7.2', + 'pull': 'always', + 'environment' : { + 'TEST_SERVER_URL': 'http://ocis-server:9140', + 'OCIS_REVA_DATA_ROOT': '/srv/app/tmp/reva/', + 'SKELETON_DIR': '/srv/app/tmp/testing/data/apiSkeleton', + 'TEST_EXTERNAL_USER_BACKENDS':'true', + 'REVA_LDAP_HOSTNAME':'ldap', + 'TEST_OCIS':'true', + 'BEHAT_FILTER_TAGS': '~@notToImplementOnOCIS&&~@toImplementOnOCIS', + 'EXPECTED_FAILURES_FILE': '/drone/src/tests/acceptance/expected-failures.txt' + }, + 'commands': [ + 'cd /srv/app/testrunner', 'make test-acceptance-api', ], 'volumes': [{ diff --git a/.gitignore b/.gitignore index 90d38351b0..9f9a19066b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,11 @@ coverage.out *.key *crt -/eos-docker \ No newline at end of file +/eos-docker + +# API acceptance tests +composer.lock +/vendor +vendor-bin/**/vendor +vendor-bin/**/composer.lock +tests/acceptance/output diff --git a/Makefile b/Makefile index 9543e5089e..e7147b028d 100644 --- a/Makefile +++ b/Makefile @@ -312,3 +312,21 @@ eos-install-go: docker exec -i eos-cli1 curl https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz -O docker exec -i eos-cli1 tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz # export PATH=$PATH:/usr/local/go/bin + +BEHAT_BIN=vendor-bin/behat/vendor/bin/behat + +.PHONY: test-acceptance-api +test-acceptance-api: vendor-bin/behat/vendor + BEHAT_BIN=$(BEHAT_BIN) $(PATH_TO_CORE)/tests/acceptance/run.sh --remote --type api + +vendor/bamarni/composer-bin-plugin: composer.lock + composer install + +vendor-bin/behat/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/behat/composer.lock + composer bin behat install --no-progress + +vendor-bin/behat/composer.lock: vendor-bin/behat/composer.json + @echo behat composer.lock is not up to date. + +composer.lock: composer.json + @echo composer.lock is not up to date. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000..aace507a05 --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "owncloud/ocis", + "config" : { + "platform": { + "php": "7.2" + } + }, + "require": { + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4" + }, + "extra": { + "bamarni-bin": { + "bin-links": false + } + } +} diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml new file mode 100644 index 0000000000..b74d189ad5 --- /dev/null +++ b/tests/acceptance/config/behat.yml @@ -0,0 +1,30 @@ +default: + autoload: + '': '%paths.base%/../features/bootstrap' + + suites: + apiOcisSpecific: + paths: + - '%paths.base%/../features/apiOcisSpecific' + context: &common_ldap_suite_context + parameters: + ldapAdminPassword: admin + ldapUsersOU: TestUsers + ldapGroupsOU: TestGroups + ldapInitialUserFilePath: /../../config/ldap-users.ldif + contexts: + - RevaContext: + - OccContext: + - FeatureContext: &common_feature_context_params + baseUrl: http://localhost:8080 + adminUsername: admin + adminPassword: admin + regularUserPassword: 123456 + ocPath: apps/testing/api/v1/occ + - FavoritesContext: + - WebDavPropertiesContext: + + extensions: + jarnaiz\JUnitFormatter\JUnitFormatterExtension: + filename: report.xml + outputDir: '%paths.base%/../output/' diff --git a/tests/acceptance/features/apiOcisSpecific/ocsDELETEAuth.feature b/tests/acceptance/features/apiOcisSpecific/ocsDELETEAuth.feature new file mode 100644 index 0000000000..8be10830f8 --- /dev/null +++ b/tests/acceptance/features/apiOcisSpecific/ocsDELETEAuth.feature @@ -0,0 +1,27 @@ +@api +Feature: auth + + @issue-ocis-reva-30 @issue-ocis-reva-65 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: send DELETE requests to OCS endpoints as admin with wrong password + When the administrator requests these endpoints with "DELETE" using password "invalid" about user "Alice" + | endpoint | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123 | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/shares/123 | + | /ocs/v1.php/apps/files_sharing/api/v1/shares/pending/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123 | + | /ocs/v1.php/cloud/apps/testing | + | /ocs/v2.php/cloud/apps/testing | + | /ocs/v1.php/cloud/groups/group1 | + | /ocs/v2.php/cloud/groups/group1 | + | /ocs/v1.php/cloud/users/%username% | + | /ocs/v2.php/cloud/users/%username% | + | /ocs/v1.php/cloud/users/%username%/groups | + | /ocs/v2.php/cloud/users/%username%/groups | + | /ocs/v1.php/cloud/users/%username%/subadmins | + | /ocs/v2.php/cloud/users/%username%/subadmins | + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "notset" diff --git a/tests/acceptance/features/apiOcisSpecific/ocsGETAuth.feature b/tests/acceptance/features/apiOcisSpecific/ocsGETAuth.feature new file mode 100644 index 0000000000..d48ec88c0d --- /dev/null +++ b/tests/acceptance/features/apiOcisSpecific/ocsGETAuth.feature @@ -0,0 +1,112 @@ +@api +Feature: auth + + Background: + Given user "Alice" has been created with default attributes and skeleton files + + @issue-ocis-reva-29 + @issue-ocis-reva-30 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: using OCS anonymously + When a user requests these endpoints with "GET" and no authentication + | endpoint | + | /ocs/v1.php/apps/files_external/api/v1/mounts | + | /ocs/v2.php/apps/files_external/api/v1/mounts | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending | + | /ocs/v1.php/apps/files_sharing/api/v1/shares | + | /ocs/v2.php/apps/files_sharing/api/v1/shares | + | /ocs/v1.php/cloud/apps | + | /ocs/v2.php/cloud/apps | + | /ocs/v1.php/cloud/groups | + | /ocs/v2.php/cloud/groups | + | /ocs/v1.php/cloud/users | + | /ocs/v2.php/cloud/users | + | /ocs/v1.php/config | + | /ocs/v2.php/config | + | /ocs/v1.php/privatedata/getattribute | + | /ocs/v2.php/privatedata/getattribute | + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "notset" + + @issue-ocis-reva-11 + @issue-ocis-reva-30 + @issue-ocis-reva-31 + @issue-ocis-reva-32 + @issue-ocis-reva-33 + @issue-ocis-reva-34 + @issue-ocis-reva-35 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: using OCS with non-admin basic auth + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v1.php/apps/files_external/api/v1/mounts | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending | + | /ocs/v1.php/privatedata/getattribute | + | /ocs/v1.php/cloud/groups | + | /ocs/v1.php/cloud/apps | + Then the HTTP status code of responses on all endpoints should be "200" + And the OCS status code of responses on all endpoints should be "998" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v1.php/config | + Then the HTTP status code of responses on all endpoints should be "200" + And the OCS status code of responses on all endpoints should be "100" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v2.php/apps/files_external/api/v1/mounts | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending | + # | /ocs/v1.php/apps/files_sharing/api/v1/shares | 100 | 200 | + # | /ocs/v2.php/apps/files_sharing/api/v1/shares | 100 | 200 | + + | /ocs/v2.php/cloud/apps | + | /ocs/v2.php/cloud/groups | + | /ocs/v2.php/privatedata/getattribute | + Then the HTTP status code of responses on all endpoints should be "404" + And the OCS status code of responses on all endpoints should be "998" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v1.php/cloud/users | + Then the HTTP status code of responses on all endpoints should be "200" + And the OCS status code of responses on all endpoints should be "403" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v2.php/cloud/users | + Then the HTTP status code of responses on all endpoints should be "403" + And the OCS status code of responses on all endpoints should be "403" + When the user "Alice" requests these endpoints with "GET" with basic auth + | endpoint | + | /ocs/v2.php/config | + Then the HTTP status code of responses on all endpoints should be "200" + And the OCS status code of responses on all endpoints should be "200" + + @issue-ocis-reva-29 + @issue-ocis-reva-30 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: using OCS as normal user with wrong password + When user "Alice" requests these endpoints with "GET" using password "invalid" + | endpoint | + | /ocs/v1.php/apps/files_external/api/v1/mounts | + | /ocs/v2.php/apps/files_external/api/v1/mounts | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending | + | /ocs/v1.php/apps/files_sharing/api/v1/shares | + | /ocs/v2.php/apps/files_sharing/api/v1/shares | + | /ocs/v1.php/cloud/apps | + | /ocs/v2.php/cloud/apps | + | /ocs/v1.php/cloud/groups | + | /ocs/v2.php/cloud/groups | + | /ocs/v1.php/cloud/users | + | /ocs/v2.php/cloud/users | + | /ocs/v1.php/config | + | /ocs/v2.php/config | + | /ocs/v1.php/privatedata/getattribute | + | /ocs/v2.php/privatedata/getattribute | + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "notset" diff --git a/tests/acceptance/features/apiOcisSpecific/ocsPOSTAuth.feature b/tests/acceptance/features/apiOcisSpecific/ocsPOSTAuth.feature new file mode 100644 index 0000000000..3b3927e6e4 --- /dev/null +++ b/tests/acceptance/features/apiOcisSpecific/ocsPOSTAuth.feature @@ -0,0 +1,35 @@ +@api +Feature: auth + + Background: + Given user "Alice" has been created with default attributes and skeleton files + + @issue-ocis-reva-30 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: send POST requests to OCS endpoints as normal user with wrong password + When user "Alice" requests these endpoints with "POST" including body "doesnotmatter" using password "invalid" about user "Alice" + | endpoint | + | /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123 | + | /ocs/v1.php/apps/files_sharing/api/v1/shares | + | /ocs/v2.php/apps/files_sharing/api/v1/shares | + | /ocs/v1.php/apps/files_sharing/api/v1/shares/pending/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123 | + | /ocs/v1.php/cloud/apps/testing | + | /ocs/v2.php/cloud/apps/testing | + | /ocs/v1.php/cloud/groups | + | /ocs/v2.php/cloud/groups | + | /ocs/v1.php/cloud/users | + | /ocs/v2.php/cloud/users | + | /ocs/v1.php/cloud/users/%username%/groups | + | /ocs/v2.php/cloud/users/%username%/groups | + | /ocs/v1.php/cloud/users/%username%/subadmins | + | /ocs/v2.php/cloud/users/%username%/subadmins | + | /ocs/v1.php/person/check | + | /ocs/v2.php/person/check | + | /ocs/v1.php/privatedata/deleteattribute/testing/test | + | /ocs/v2.php/privatedata/deleteattribute/testing/test | + | /ocs/v1.php/privatedata/setattribute/testing/test | + | /ocs/v2.php/privatedata/setattribute/testing/test | + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "notset" diff --git a/tests/acceptance/features/apiOcisSpecific/ocsPUTAuth.feature b/tests/acceptance/features/apiOcisSpecific/ocsPUTAuth.feature new file mode 100644 index 0000000000..b8e54da9a7 --- /dev/null +++ b/tests/acceptance/features/apiOcisSpecific/ocsPUTAuth.feature @@ -0,0 +1,18 @@ +@api +Feature: auth + + @issue-ocis-reva-30 + # after fixing all issues delete this Scenario and use the one from oC10 core + Scenario: send PUT request to OCS endpoints as admin with wrong password + When the administrator requests these endpoints with "PUT" with body "doesnotmatter" using password "invalid" about user "Alice" + | endpoint | + | /ocs/v1.php/cloud/users/%username% | + | /ocs/v2.php/cloud/users/%username% | + | /ocs/v1.php/cloud/users/%username%/disable | + | /ocs/v2.php/cloud/users/%username%/disable | + | /ocs/v1.php/cloud/users/%username%/enable | + | /ocs/v2.php/cloud/users/%username%/enable | + | /ocs/v1.php/apps/files_sharing/api/v1/shares/123 | + | /ocs/v2.php/apps/files_sharing/api/v1/shares/123 | + Then the HTTP status code of responses on all endpoints should be "401" + And the OCS status code of responses on all endpoints should be "notset" diff --git a/tests/acceptance/features/bootstrap/RevaContext.php b/tests/acceptance/features/bootstrap/RevaContext.php new file mode 100644 index 0000000000..2a41222029 --- /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() + ); + } +} diff --git a/tests/acceptance/features/bootstrap/bootstrap.php b/tests/acceptance/features/bootstrap/bootstrap.php new file mode 100644 index 0000000000..1e2175b1ba --- /dev/null +++ b/tests/acceptance/features/bootstrap/bootstrap.php @@ -0,0 +1,14 @@ +addPsr4( + "", $pathToCore . "/tests/acceptance/features/bootstrap", true +); + +$classLoader->register(); diff --git a/vendor-bin/behat/composer.json b/vendor-bin/behat/composer.json new file mode 100644 index 0000000000..aa22f60040 --- /dev/null +++ b/vendor-bin/behat/composer.json @@ -0,0 +1,22 @@ +{ + "config" : { + "platform": { + "php": "7.2" + } + }, + "require": { + "behat/behat": "^3.7", + "behat/mink": "1.7.1", + "behat/mink-extension": "^2.3", + "behat/mink-goutte-driver": "^1.2", + "behat/mink-selenium2-driver": "^1.4", + "jarnaiz/behat-junit-formatter": "^1.3", + "rdx/behat-variables": "^1.2", + "sensiolabs/behat-page-object-extension": "^2.3", + "symfony/translation": "^4.4", + "sabre/xml": "^2.2", + "guzzlehttp/guzzle": "^6.5", + "phpunit/phpunit": "^8.5", + "laminas/laminas-ldap": "^2.10" + } +}