diff --git a/.drone.yml b/.drone.yml index ec3228829208..0d3956b0aea8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -350,6 +350,19 @@ pipeline: matrix: TEST_SUITE: api + cli-acceptance-tests: + image: owncloudci/php:${PHP_VERSION} + pull: true + environment: + - TEST_SERVER_URL=https://server + commands: + - touch /drone/saved-settings.sh + - . /drone/saved-settings.sh + - make test-acceptance-cli TESTING_REMOTE_SYSTEM=true + when: + matrix: + TEST_SUITE: cli + webui-acceptance-tests: image: owncloudci/php:${PHP_VERSION} pull: true @@ -791,6 +804,16 @@ matrix: CHOWN_SERVER: true OWNCLOUD_LOG: true + # CLI Acceptance tests + - PHP_VERSION: 7.1 + TEST_SUITE: cli + BEHAT_SUITE: cliProvisioning + DB_TYPE: mariadb + USE_SERVER: true + INSTALL_SERVER: true + CHOWN_SERVER: true + OWNCLOUD_LOG: true + # UI Acceptance tests - PHP_VERSION: 7.1 TEST_SUITE: selenium diff --git a/Makefile b/Makefile index 202220c5d345..c9d72c5901fe 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,7 @@ help: @echo -e "make test-js\t\t\trun Javascript tests" @echo -e "make test-js-debug\t\trun Javascript tests in debug mode (continuous)" @echo -e "make test-acceptance-api\trun API acceptance tests" + @echo -e "make test-acceptance-cli\trun CLI acceptance tests" @echo -e "make test-acceptance-webui\trun webUI acceptance tests" @echo -e "make clean-test\t\t\tclean test results" @echo @@ -185,6 +186,10 @@ test-js-debug: $(nodejs_deps) test-acceptance-api: $(composer_dev_deps) ./tests/acceptance/run.sh --type api +.PHONY: test-acceptance-cli +test-acceptance-cli: $(composer_dev_deps) + ./tests/acceptance/run.sh --type cli + .PHONY: test-acceptance-webui test-acceptance-webui: $(composer_dev_deps) ./tests/acceptance/run.sh --type webUI @@ -208,7 +213,7 @@ test-php-phan: $(PHAN_BIN) php $(PHAN_BIN) --config-file .phan/config.php --require-config-exists -p .PHONY: test -test: test-php-lint test-php-style test-php test-js test-acceptance-api test-acceptance-webui +test: test-php-lint test-php-style test-php test-js test-acceptance-api test-acceptance-cli test-acceptance-webui .PHONY: clean-test-acceptance clean-test-acceptance: diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 291513574afa..e8d90e488bf9 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -95,6 +95,13 @@ default: - FeatureContext: *common_feature_context_params - LoggingContext: + cliProvisioning: + paths: + - %paths.base%/../features/cliProvisioning + contexts: + - FeatureContext: *common_feature_context_params + - OccContext: + webUIAdminSettings: paths: - %paths.base%/../features/webUIAdminSettings diff --git a/tests/acceptance/features/bootstrap/CommandLine.php b/tests/acceptance/features/bootstrap/CommandLine.php index 48477b74c1f9..fba47d0c3d56 100644 --- a/tests/acceptance/features/bootstrap/CommandLine.php +++ b/tests/acceptance/features/bootstrap/CommandLine.php @@ -277,13 +277,13 @@ public function theCommandOutputContainsTheText($text) { // end of the captured string, so trim them. $text = \trim($text, $text[0]); $lines = $this->findLines($this->lastStdOut, $text); - if (empty($lines)) { - throw new \Exception( - "The command output did not contain the expected text on stdout '$text'\n" . - "The command output on stdout was:\n" . - $this->lastStdOut - ); - } + PHPUnit_Framework_Assert::assertGreaterThanOrEqual( + 1, + \count($lines), + "The command output did not contain the expected text on stdout '$text'\n" . + "The command output on stdout was:\n" . + $this->lastStdOut + ); } /** @@ -299,13 +299,13 @@ public function theCommandErrorOutputContainsTheText($text) { // end of the captured string, so trim them. $text = \trim($text, $text[0]); $lines = $this->findLines($this->lastStdErr, $text); - if (empty($lines)) { - throw new \Exception( - "The command output did not contain the expected text on stderr '$text'\n" . - "The command output on stderr was:\n" . - $this->lastStdOut - ); - } + PHPUnit_Framework_Assert::assertGreaterThanOrEqual( + 1, + \count($lines), + "The command output did not contain the expected text on stderr '$text'\n" . + "The command output on stderr was:\n" . + $this->lastStdErr + ); } private $lastTransferPath; diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index ddf145c171c7..7d7d709d59fa 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -525,6 +525,19 @@ public function userUsingPasswordShouldNotBeAbleToDownloadFile( ); } + /** + * @Then /^user "([^"]*)" should be able to access a skeleton file$/ + * + * @param string $user + * + * @return void + */ + public function userShouldBeAbleToAccessASkeletonFile($user) { + $this->contentOfFileForUserShouldBePlusEndOfLine( + "textfile0.txt", $user, "ownCloud test text file 0" + ); + } + /** * @Then /^the downloaded content should be "([^"]*)"$/ * diff --git a/tests/acceptance/features/cliProvisioning/addUser.feature b/tests/acceptance/features/cliProvisioning/addUser.feature new file mode 100644 index 000000000000..d900ac99989f --- /dev/null +++ b/tests/acceptance/features/cliProvisioning/addUser.feature @@ -0,0 +1,31 @@ +@cli @skipOnLDAP +Feature: add a user using the using the occ command + + As an administrator + I want to be able to add users via the command line + So that I can give people controlled individual access to resources on the ownCloud server and + So that I can write scripts to add users + + Scenario: admin creates an ordinary user using the occ command + When the administrator creates this user using the occ command: + | username | + | justauser | + Then the command should have been successful + And the command output should contain the text 'The user "justauser" was created successfully' + And user "justauser" should exist + And user "justauser" should be able to access a skeleton file + + Scenario: admin creates an ordinary user sspecifying attributes using the occ command + When the administrator creates this user using the occ command: + | username | displayname | email | + | justauser | Just A User | justauser@example.com | + Then the command should have been successful + And the command output should contain the text 'The user "justauser" was created successfully' + And the command output should contain the text 'Display name set to "Just A User"' + And the command output should contain the text 'Email address set to "justauser@example.com"' + And user "justauser" should exist + And user "justauser" should be able to access a skeleton file + When the administrator retrieves the information of user "justauser" using the provisioning API + Then the user attributes returned by the API should include + | displayname | Just A User | + | email | justauser@example.com | diff --git a/tests/acceptance/run.sh b/tests/acceptance/run.sh index 72e98cc6494c..c615112c7bb0 100755 --- a/tests/acceptance/run.sh +++ b/tests/acceptance/run.sh @@ -66,7 +66,7 @@ fi # -c or --config - specify a behat.yml to use # --feature - specify a single feature to run # --suite - specify a single suite to run -# --type - api or webui - if no individual feature or suite is specified, then +# --type - api, cli or webui - if no individual feature or suite is specified, then # specify the type of acceptance tests to run. Default api. # --tags - specify tags for scenarios to run (or not) # --browser - for webUI tests, which browser to use. "chrome", "firefox", @@ -103,7 +103,7 @@ do shift ;; --type) - # Lowercase the parameter value, so the user can provide "API", "webUI" etc + # Lowercase the parameter value, so the user can provide "API", "CLI", "webUI" etc ACCEPTANCE_TEST_TYPE="${2,,}" shift ;; @@ -552,15 +552,24 @@ then TEST_TYPE_TAG="@webUI" TEST_TYPE_TEXT="webUI" RUNNING_API_TESTS=false + RUNNING_CLI_TESTS=false RUNNING_WEBUI_TESTS=true +elif [[ "${BEHAT_SUITE}" == cli* ]] || [ "${ACCEPTANCE_TEST_TYPE}" = "cli" ] +then + TEST_TYPE_TAG="@cli" + TEST_TYPE_TEXT="cli" + RUNNING_API_TESTS=false + RUNNING_CLI_TESTS=true + RUNNING_WEBUI_TESTS=false else TEST_TYPE_TAG="@api" TEST_TYPE_TEXT="API" RUNNING_API_TESTS=true + RUNNING_CLI_TESTS=false RUNNING_WEBUI_TESTS=false fi -# Always have one of "@api" or "@webUI" filter tags +# Always have one of "@api", "@cli" or "@webUI" filter tags if [ -z "${BEHAT_FILTER_TAGS}" ] then BEHAT_FILTER_TAGS="${TEST_TYPE_TAG}" @@ -634,6 +643,11 @@ fi if [ "${RUNNING_API_TESTS}" = true ] then export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/apiSkeleton" +elif [ "${RUNNING_CLI_TESTS}" = true ] +then + # CLI tests use the apiSkeleton so that API-based "then" steps can be used + # to check the state of users after CLI commands + export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/apiSkeleton" else export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/webUISkeleton" fi @@ -795,6 +809,10 @@ else fi if [ "${RUNNING_API_TESTS}" = true ] +then + EXTRA_CAPABILITIES="" + BROWSER_TEXT="" +elif [ "${RUNNING_CLI_TESTS}" = true ] then EXTRA_CAPABILITIES="" BROWSER_TEXT=""