Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove /ocs/ from end of acceptance tests baseUrl #30943

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ pipeline:
image: owncloudci/php:${PHP_VERSION}
pull: true
environment:
- TEST_SERVER_URL=http://server/ocs/
- TEST_SERVER_FED_URL=http://federated/ocs/
- TEST_SERVER_URL=http://server
- TEST_SERVER_FED_URL=http://federated
commands:
- ./tests/drone/test-api-acceptance.sh
when:
Expand Down
4 changes: 1 addition & 3 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ default:
- %paths.base%/../features/apiMain
contexts:
- FeatureContext: &common_feature_context_params
baseUrl: http://localhost:8080/ocs/
baseUrl: http://localhost:8080
adminUsername: admin
adminPassword: admin
regularUserPassword: 123456
mailhogUrl: http://127.0.0.1:8025/api/v2/messages
ocPath: ../../
- CardDavContext:
baseUrl: http://localhost:8080
- CalDavContext:
baseUrl: http://localhost:8080
- AppManagementContext:

apiCapabilities:
Expand Down
18 changes: 3 additions & 15 deletions tests/acceptance/features/bootstrap/AppConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function wasCapabilitySet($capabilitiesApp, $capabilitiesParameter) {
*/
public function setCapabilities($capabilitiesArray) {
$savedCapabilitiesChanges = AppConfigHelper::setCapabilities(
$this->baseUrlWithoutOCSAppendix(),
$this->getBaseUrl(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$capabilitiesArray,
Expand All @@ -234,7 +234,7 @@ public function setCapabilities($capabilitiesArray) {
*/
protected function modifyServerConfig($app, $parameter, $value) {
AppConfigHelper::modifyServerConfig(
$this->baseUrlWithoutOCSAppendix(),
$this->getBaseUrl(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$app,
Expand All @@ -251,7 +251,7 @@ protected function modifyServerConfig($app, $parameter, $value) {
*/
protected function modifyServerConfigs($appParameterValues) {
AppConfigHelper::modifyServerConfigs(
$this->baseUrlWithoutOCSAppendix(),
$this->getBaseUrl(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$appParameterValues,
Expand Down Expand Up @@ -302,18 +302,6 @@ abstract protected function resetAppConfigs();
* @return void
*/
public function prepareParametersBeforeScenario(BeforeScenarioScope $scope) {
// If we are running a webUI scenario, then make sure to use the base URL
// that the webUI has configured.
// Because the order of BeforeScenario method execution is not guaranteed,
// we need to be sure this happens here, before calling resetAppConfigs(),
// which will need to access the server API.
if ($scope->getScenario()->hasTag("webUI") || $scope->getFeature()->hasTag("webUI")) {
$environment = $scope->getEnvironment();
$this->webUIGeneralContext = $environment->getContext('WebUIGeneralContext');
$baseUrl = $this->webUIGeneralContext->getBaseUrlInWebUITestFormat();
$this->overrideBaseUrlWithWebUIValue($baseUrl);
}

$user = $this->currentUser;
$this->currentUser = $this->getAdminUsername();
$this->resetAppConfigs();
Expand Down
6 changes: 3 additions & 3 deletions tests/acceptance/features/bootstrap/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function userRequestsURLWith($url, $method) {
private function sendRequest(
$url, $method, $authHeader = null, $useCookies = false
) {
$fullUrl = substr($this->baseUrl, 0, -5) . $url;
$fullUrl = $this->getBaseUrl() . $url;
try {
if ($useCookies) {
$request = $this->client->createRequest(
Expand Down Expand Up @@ -98,7 +98,7 @@ private function sendRequest(
public function aNewClientTokenHasBeenGenerated($user) {
$client = new Client();
$resp = $client->post(
substr($this->baseUrl, 0, -5) . '/token/generate', [
$this->getBaseUrl() . '/token/generate', [
'json' => [
'user' => $user,
'password' => $this->getPasswordForUser($user),
Expand Down Expand Up @@ -175,7 +175,7 @@ public function userRequestsURLWithBrowserSession($url, $method) {
* @return void
*/
public function aNewBrowserSessionForHasBeenStarted($user) {
$loginUrl = substr($this->baseUrl, 0, -5) . '/login';
$loginUrl = $this->getBaseUrl() . '/login';
// Request a new session and extract CSRF token
$client = new Client();
$response = $client->get(
Expand Down
79 changes: 40 additions & 39 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ trait BasicStructure {
private $currentServer = '';

/**
* @var string
* The base URL of the current server under test,
* without any terminating slash
* e.g. http://localhost:8080
*
* @var string
*/
private $baseUrl = '';

/**
* The base URL of the local server under test,
* without any terminating slash
* e.g. http://localhost:8080
*
* @var string
*/
private $localBaseUrl = '';

/**
* The base URL of the remote (federated) server under test,
* without any terminating slash
* e.g. http://localhost:8180
*
* @var string
*/
private $remoteBaseUrl = '';
Expand Down Expand Up @@ -122,7 +134,7 @@ public function __construct(
) {

// Initialize your context here
$this->baseUrl = $baseUrl;
$this->baseUrl = rtrim($baseUrl, '/');
Copy link
Contributor Author

@phil-davis phil-davis Mar 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rtrim() are here for the benefit of future users. If they pass in the baseURL parameter with a / on the end, then we will cope with that.

$this->adminUsername = $adminUsername;
$this->adminPassword = $adminPassword;
$this->regularUserPassword = $regularUserPassword;
Expand All @@ -136,48 +148,42 @@ public function __construct(
// in case of CI deployment we take the server url from the environment
$testServerUrl = getenv('TEST_SERVER_URL');
if ($testServerUrl !== false) {
$this->baseUrl = $testServerUrl;
$this->localBaseUrl = $testServerUrl;
$this->baseUrl = rtrim($testServerUrl, '/');
$this->localBaseUrl = $this->baseUrl;
}

// federated server url from the environment
$testRemoteServerUrl = getenv('TEST_SERVER_FED_URL');
if ($testRemoteServerUrl !== false) {
$this->remoteBaseUrl = $testRemoteServerUrl;
$this->remoteBaseUrl = rtrim($testRemoteServerUrl, '/');
}
}

/**
* Override the baseUrl that came via the behat.yml and context constructor.
* Use this when running in an environment that passes the baseUrl from some
* external script. For example, the webUI acceptance tests build up the
* baseUrl from environment variables and the script passes the value in as
* a Mink parameter.
* returns the base URL (which is without a slash at the end)
*
* @param string $newBaseUrl in the format that the webUI tests use
*
* @return void
* @return string
*/
public function overrideBaseUrlWithWebUIValue($newBaseUrl) {
// baseUrl in the API tests FeatureContext uses a form with '/ocs/'
// on the end so add that.
if (substr($newBaseUrl, -1) !== '/') {
$newBaseUrl .= '/';
}
public function getBaseUrl() {
return $this->baseUrl;
}

$newBaseUrl .= 'ocs/';
$this->baseUrl = $newBaseUrl;
$this->localBaseUrl = $this->baseUrl;
$this->remoteBaseUrl = $this->baseUrl;
/**
* returns the local base URL (which is without a slash at the end)
*
* @return string
*/
public function getLocalBaseUrl() {
return $this->localBaseUrl;
}

/**
* returns the base URL without the /ocs part
* returns the remote base URL (which is without a slash at the end)
*
* @return string
*/
public function baseUrlWithoutOCSAppendix() {
return substr($this->baseUrl, 0, -4);
public function getRemoteBaseUrl() {
return $this->remoteBaseUrl;
}

/**
Expand Down Expand Up @@ -395,7 +401,7 @@ public function userSendsHTTPMethodToAPIEndpointWithBody(
}

$this->response = OcsApiHelper::sendRequest(
$this->baseUrlWithoutOCSAppendix(),
$this->getBaseUrl(),
$user, $password, $verb, $url, $bodyArray, $this->apiVersion
);

Expand Down Expand Up @@ -424,7 +430,7 @@ public function userSendsHTTPMethodToUrl($user, $verb, $url) {
* @return void
*/
public function sendingToWithDirectUrl($user, $verb, $url, $body) {
$fullUrl = substr($this->baseUrl, 0, -5) . $url;
$fullUrl = $this->getBaseUrl() . $url;
$client = new Client();
$options = [];
$options['auth'] = $this->getAuthOptionForUser($user);
Expand Down Expand Up @@ -455,8 +461,7 @@ public function sendingToWithDirectUrl($user, $verb, $url, $body) {
* @return bool
*/
public function isAPublicLinkUrl($url) {
$baseUrlChopped = $this->baseUrlWithoutOCSAppendix();
$urlEnding = substr($url, strlen($baseUrlChopped));
$urlEnding = substr($url, strlen($this->getBaseUrl() . '/'));
return preg_match("%^(index.php/)?s/([a-zA-Z0-9]{15})$%", $urlEnding);
}

Expand Down Expand Up @@ -566,7 +571,7 @@ private function extracRequestTokenFromResponse(ResponseInterface $response) {
* @return void
*/
public function userHasLoggedInToAWebStyleSessionUsingTheAPI($user) {
$loginUrl = substr($this->baseUrl, 0, -5) . '/login';
$loginUrl = $this->getBaseUrl() . '/login';
// Request a new session and extract CSRF token
$client = new Client();
$response = $client->get(
Expand Down Expand Up @@ -604,12 +609,10 @@ public function userHasLoggedInToAWebStyleSessionUsingTheAPI($user) {
* @return void
*/
public function sendingAToWithRequesttoken($method, $url) {
$baseUrl = substr($this->baseUrl, 0, -5);

$client = new Client();
$request = $client->createRequest(
$method,
$baseUrl . $url,
$this->getBaseUrl() . $url,
[
'cookies' => $this->cookieJar,
]
Expand All @@ -632,12 +635,10 @@ public function sendingAToWithRequesttoken($method, $url) {
* @return void
*/
public function sendingAToWithoutRequesttoken($method, $url) {
$baseUrl = substr($this->baseUrl, 0, -5);

$client = new Client();
$request = $client->createRequest(
$method,
$baseUrl . $url,
$this->getBaseUrl() . $url,
[
'cookies' => $this->cookieJar,
]
Expand Down Expand Up @@ -793,7 +794,7 @@ public function getAuthOptionForAdmin() {
* @return void
*/
public function getStatusPhp() {
$fullUrl = $this->baseUrlWithoutOCSAppendix() . "status.php";
$fullUrl = $this->getBaseUrl() . "/status.php";
$client = new Client();
$options = [];
$options['auth'] = $this->getAuthOptionForUser('admin');
Expand Down Expand Up @@ -886,7 +887,7 @@ public static function useBigFileIDs(BeforeSuiteScope $scope) {
if (substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
}
$fullUrl .= "v1.php/apps/testing/api/v1/increasefileid";
$fullUrl .= "ocs/v1.php/apps/testing/api/v1/increasefileid";
$client = new Client();
$options = [];
$suiteSettingsContexts = $scope->getSuite()->getSettings()['contexts'];
Expand Down
25 changes: 3 additions & 22 deletions tests/acceptance/features/bootstrap/CalDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
* CalDav functions
*/
class CalDavContext implements \Behat\Behat\Context\Context {
/**
* @var string
*/
private $baseUrl;
/**
* @var Client
*/
Expand All @@ -52,21 +48,6 @@ class CalDavContext implements \Behat\Behat\Context\Context {
*/
private $featureContext;

/**
* @param string $baseUrl
*
* @return void
*/
public function __construct($baseUrl) {
$this->baseUrl = $baseUrl;

// in case of ci deployment we take the server url from the environment
$testServerUrl = getenv('TEST_SERVER_URL');
if ($testServerUrl !== false) {
$this->baseUrl = substr($testServerUrl, 0, -5);
}
}

/**
* @BeforeScenario @caldav
*
Expand All @@ -89,7 +70,7 @@ public function setUpScenario(BeforeScenarioScope $scope) {
* @return void
*/
public function afterScenario() {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/admin/MyCalendar';
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/admin/MyCalendar';
try {
$this->client->delete(
$davUrl,
Expand All @@ -110,7 +91,7 @@ public function afterScenario() {
* @return void
*/
public function userRequestsCalendarUsingTheAPI($user, $calendar) {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/' . $calendar;
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/' . $calendar;

try {
$this->response = $this->client->get(
Expand Down Expand Up @@ -204,7 +185,7 @@ public function theCalDavErrorMessageShouldBe($message) {
* @return void
*/
public function userHasCreatedACalendarNamed($user, $name) {
$davUrl = $this->baseUrl . '/remote.php/dav/calendars/' . $user . '/' . $name;
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/' . $user . '/' . $name;

$request = $this->client->createRequest(
'MKCALENDAR',
Expand Down
Loading