From 8e9c12eed92642748111bbc2acaf4bf071526a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 20 Jul 2017 07:50:33 +0200 Subject: [PATCH 1/4] Make possible to configure the domain for the Nextcloud test server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NextcloudTestServerLocalHelper started the PHP built-in web server for the Nextcloud test server at 127.0.0.1; as the Selenium server has to access the Nextcloud test server they were forced to share the same network. Now, the domain at which the PHP built-in web server is started can be specified when the NextcloudTestServerLocalHelper is created, which removes the need of sharing the same network, as the Selenium server now can access the Nextcloud test server at an arbitrary domain. However, by default "127.0.0.1" is still used if no domain is given. Signed-off-by: Daniel Calviño Sánchez --- .../core/NextcloudTestServerLocalHelper.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/features/core/NextcloudTestServerLocalHelper.php b/tests/acceptance/features/core/NextcloudTestServerLocalHelper.php index 32b5330c61..b11a9ae821 100644 --- a/tests/acceptance/features/core/NextcloudTestServerLocalHelper.php +++ b/tests/acceptance/features/core/NextcloudTestServerLocalHelper.php @@ -35,13 +35,21 @@ * the Nextcloud server; the last commit in that Git repository must provide the * initial state for the Nextcloud server expected by the acceptance tests. * - * The Nextcloud server is available at "127.0.0.1", so it is expected to see - * "127.0.0.1" as a trusted domain (which would be the case if it was installed - * by running "occ maintenance:install"). The base URL to access the Nextcloud + * The Nextcloud server is available at "$nextcloudServerDomain", which can be + * optionally specified when the NextcloudTestServerLocalHelper is created; if + * no value is given "127.0.0.1" is used by default. In any case, the value of + * "$nextcloudServerDomain" must be seen as a trusted domain by the Nextcloud + * server (which would be the case for "127.0.0.1" if it was installed by + * running "occ maintenance:install"). The base URL to access the Nextcloud * server can be got from "getBaseUrl". */ class NextcloudTestServerLocalHelper implements NextcloudTestServerHelper { + /** + * @var string + */ + private $nextcloudServerDomain; + /** * @var string */ @@ -50,7 +58,9 @@ class NextcloudTestServerLocalHelper implements NextcloudTestServerHelper { /** * Creates a new NextcloudTestServerLocalHelper. */ - public function __construct() { + public function __construct($nextcloudServerDomain = "127.0.0.1") { + $this->nextcloudServerDomain = $nextcloudServerDomain; + $this->phpServerPid = ""; } @@ -77,7 +87,7 @@ class NextcloudTestServerLocalHelper implements NextcloudTestServerHelper { // execOrException is not used because the server is started in the // background, so the command will always succeed even if the server // itself fails. - $this->phpServerPid = exec("php -S 127.0.0.1:80 -t ../../ >/dev/null 2>&1 & echo $!"); + $this->phpServerPid = exec("php -S " . $this->nextcloudServerDomain . ":80 -t ../../ >/dev/null 2>&1 & echo $!"); $timeout = 60; if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) { @@ -100,7 +110,7 @@ class NextcloudTestServerLocalHelper implements NextcloudTestServerHelper { * @return string the base URL of the Nextcloud test server. */ public function getBaseUrl() { - return "http://127.0.0.1/index.php"; + return "http://" . $this->nextcloudServerDomain . "/index.php"; } /** From 2fe8cad710a92eed6e463d1b5b67d44ca9197f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 20 Jul 2017 07:54:39 +0200 Subject: [PATCH 2/4] Add option to acceptance test runner to set the Nextcloud server domain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default "127.0.0.1" is used, so nothing needs to be set when the Selenium server and the Nextcloud test server share the same network (like when called by "run.sh"). Besides passing the domain to the acceptance tests the Nextcloud test server configuration must be modified to see the given domain as a trusted domain; otherwise the access would be forbidden. Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/installAndConfigureServer.sh | 12 +++++++ tests/acceptance/run-local.sh | 34 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/installAndConfigureServer.sh b/tests/acceptance/installAndConfigureServer.sh index 2fbdf821f7..c61faeda23 100755 --- a/tests/acceptance/installAndConfigureServer.sh +++ b/tests/acceptance/installAndConfigureServer.sh @@ -25,6 +25,18 @@ set -o errexit +NEXTCLOUD_SERVER_DOMAIN="" +if [ "$1" = "--nextcloud-server-domain" ]; then + NEXTCLOUD_SERVER_DOMAIN=$2 + + shift 2 +fi + php occ maintenance:install --admin-pass=admin OC_PASS=123456acb php occ user:add --password-from-env user0 + +if [ "$NEXTCLOUD_SERVER_DOMAIN" != "" ]; then + # Default first trusted domain is "localhost"; replace it with given domain. + php occ config:system:set trusted_domains 0 --value="$NEXTCLOUD_SERVER_DOMAIN" +fi diff --git a/tests/acceptance/run-local.sh b/tests/acceptance/run-local.sh index 93c11e810f..1e4c322428 100755 --- a/tests/acceptance/run-local.sh +++ b/tests/acceptance/run-local.sh @@ -54,6 +54,16 @@ if [ "$1" = "--timeout-multiplier" ]; then shift 2 fi +# "--nextcloud-server-domain XXX" option can be provided to set the domain used +# by the Selenium server to access the Nextcloud server. +DEFAULT_NEXTCLOUD_SERVER_DOMAIN="127.0.0.1" +NEXTCLOUD_SERVER_DOMAIN="$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" +if [ "$1" = "--nextcloud-server-domain" ]; then + NEXTCLOUD_SERVER_DOMAIN=$2 + + shift 2 +fi + # Safety parameter to prevent executing this script by mistake and messing with # the Git repository. if [ "$1" != "allow-git-repository-modifications" ]; then @@ -80,12 +90,34 @@ if [ "$TIMEOUT_MULTIPLIER" != "" ]; then sed --in-place "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml fi +if [ "$NEXTCLOUD_SERVER_DOMAIN" != "$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" ]; then + # Although Behat documentation states that using the BEHAT_PARAMS + # environment variable "You can set any value for any option that is + # available in a behat.yml file" this is currently not true for the + # constructor parameters of contexts (see + # https://github.com/Behat/Behat/issues/983). Thus, the default "behat.yml" + # configuration file has to be adjusted to provide the appropriate + # parameters for NextcloudTestServerContext. + ORIGINAL="\ + - NextcloudTestServerContext" + REPLACEMENT="\ + - NextcloudTestServerContext:\n\ + nextcloudTestServerHelperParameters:\n\ + - $NEXTCLOUD_SERVER_DOMAIN" + sed --in-place "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml +fi + composer install cd ../../ +INSTALL_AND_CONFIGURE_SERVER_PARAMETERS="" +if [ "$NEXTCLOUD_SERVER_domain" != "$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" ]; then + INSTALL_AND_CONFIGURE_SERVER_PARAMETERS+="--nextcloud-server-domain $NEXTCLOUD_SERVER_DOMAIN" +fi + echo "Installing and configuring Nextcloud server" -tests/acceptance/installAndConfigureServer.sh +tests/acceptance/installAndConfigureServer.sh $INSTALL_AND_CONFIGURE_SERVER_PARAMETERS echo "Saving the default state so acceptance tests can reset to it" find . -name ".gitignore" -exec rm --force {} \; From c37329005e88e53533612012d5b09305ae303595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 20 Jul 2017 07:56:51 +0200 Subject: [PATCH 3/4] Add option to acceptance test runner to set the Selenium server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default "127.0.0.1:4444" is used, so nothing needs to be set when the acceptance tests and the Selenium server share the same network (like when called by "run.sh"). Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/run-local.sh | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/run-local.sh b/tests/acceptance/run-local.sh index 1e4c322428..e2270be385 100755 --- a/tests/acceptance/run-local.sh +++ b/tests/acceptance/run-local.sh @@ -64,6 +64,16 @@ if [ "$1" = "--nextcloud-server-domain" ]; then shift 2 fi +# "--selenium-server XXX" option can be provided to set the domain and port used +# by the acceptance tests to access the Selenium server. +DEFAULT_SELENIUM_SERVER="127.0.0.1:4444" +SELENIUM_SERVER="$DEFAULT_SELENIUM_SERVER" +if [ "$1" = "--selenium-server" ]; then + SELENIUM_SERVER=$2 + + shift 2 +fi + # Safety parameter to prevent executing this script by mistake and messing with # the Git repository. if [ "$1" != "allow-git-repository-modifications" ]; then @@ -107,6 +117,35 @@ if [ "$NEXTCLOUD_SERVER_DOMAIN" != "$DEFAULT_NEXTCLOUD_SERVER_DOMAIN" ]; then sed --in-place "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml fi +if [ "$SELENIUM_SERVER" != "$DEFAULT_SELENIUM_SERVER" ]; then + # Set the Selenium server to be used by Mink; this extends the default + # configuration from "config/behat.yml". + export BEHAT_PARAMS=' +{ + "extensions": { + "Behat\\MinkExtension": { + "sessions": { + "default": { + "selenium2": { + "wd_host": "http://'"$SELENIUM_SERVER"'/wd/hub" + } + }, + "John": { + "selenium2": { + "wd_host": "http://'"$SELENIUM_SERVER"'/wd/hub" + } + }, + "Jane": { + "selenium2": { + "wd_host": "http://'"$SELENIUM_SERVER"'/wd/hub" + } + } + } + } + } +}' +fi + composer install cd ../../ @@ -127,6 +166,6 @@ cd tests/acceptance # Ensure that the Selenium server is ready before running the tests. echo "Waiting for Selenium" -timeout 60s bash -c "while ! curl 127.0.0.1:4444 >/dev/null 2>&1; do sleep 1; done" +timeout 60s bash -c "while ! curl $SELENIUM_SERVER >/dev/null 2>&1; do sleep 1; done" vendor/bin/behat $SCENARIO_TO_RUN From 94144269de6d2318d7e018642a65d01872625b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 20 Jul 2017 08:08:35 +0200 Subject: [PATCH 4/4] Enable acceptance tests again on Drone 0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running the acceptance tests on Drone relied on the pod-style networking used by services (service containers were available at 127.0.0.1 from the build containers). However, in Drone 0.7 service and build containers must be accessed from each other using their domain name instead. Thus, acceptance tests had to be disabled on Drone. Now that the acceptance test system supports setting a different domain for the Selenium server and for the Nextcloud test server the acceptance tests can be enabled again on Drone. Signed-off-by: Daniel Calviño Sánchez --- .drone.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index fe86379e1b..de0c003f16 100644 --- a/.drone.yml +++ b/.drone.yml @@ -469,21 +469,21 @@ pipeline: acceptance-access-levels: image: nextcloudci/integration-php7.0:integration-php7.0-4 commands: - - tests/acceptance/run-local.sh --timeout-multiplier 10 allow-git-repository-modifications features/access-levels.feature + - tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-access-levels --selenium-server selenium:4444 allow-git-repository-modifications features/access-levels.feature when: matrix: TESTS-ACCEPTANCE: access-levels acceptance-app-files: image: nextcloudci/integration-php7.0:integration-php7.0-4 commands: - - tests/acceptance/run-local.sh --timeout-multiplier 10 allow-git-repository-modifications features/app-files.feature + - tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-app-files --selenium-server selenium:4444 allow-git-repository-modifications features/app-files.feature when: matrix: TESTS-ACCEPTANCE: app-files acceptance-login: image: nextcloudci/integration-php7.0:integration-php7.0-4 commands: - - tests/acceptance/run-local.sh --timeout-multiplier 10 allow-git-repository-modifications features/login.feature + - tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-login --selenium-server selenium:4444 allow-git-repository-modifications features/login.feature when: matrix: TESTS-ACCEPTANCE: login @@ -574,12 +574,12 @@ matrix: - TESTS: integration-transfer-ownership-features - TESTS: integration-ldap-features - TESTS: integration-trashbin -# - TESTS: acceptance -# TESTS-ACCEPTANCE: access-levels -# - TESTS: acceptance -# TESTS-ACCEPTANCE: app-files -# - TESTS: acceptance -# TESTS-ACCEPTANCE: login + - TESTS: acceptance + TESTS-ACCEPTANCE: access-levels + - TESTS: acceptance + TESTS-ACCEPTANCE: app-files + - TESTS: acceptance + TESTS-ACCEPTANCE: login - TESTS: jsunit - TESTS: syntax-php5.6 - TESTS: syntax-php7.0