Skip to content

Commit

Permalink
tests: update ocm setup and docs
Browse files Browse the repository at this point in the history
docs: separate provider config

tests: substitution for local and remote server urls

tests: create local configs

tests: fix vscode debugger config

tests: separate federation share steps
  • Loading branch information
saw-jan committed Nov 11, 2024
1 parent 22d8025 commit c3b4424
Show file tree
Hide file tree
Showing 18 changed files with 576 additions and 420 deletions.
417 changes: 207 additions & 210 deletions .vscode/launch.json

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions docs/ocis/development/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ docker run -d -p 3310:3310 -v /your/local/filesystem/path/to/clamav/:/var/lib/cl
As `antivirus` service is not enabled by default we need to enable the service while running oCIS server. We also need to enable `async upload` and as virus scan is performed in post-processing step, we need to set it as well. Documentation for environment variables related to antivirus is available [here](https://owncloud.dev/services/antivirus/#environment-variables)

```bash
# init oCIS
IDM_ADMIN_PASSWORD=admin \
ocis/bin/ocis init --insecure true

# run oCIS
PROXY_ENABLE_BASIC_AUTH=true \
ANTIVIRUS_SCANNER_TYPE="clamav" \
Expand Down Expand Up @@ -504,47 +508,47 @@ make test-acceptance-api

Test suites that are tagged with `@ocm` require running two different ocis instances. More detailed information and configuration related to it can be found [here](https://doc.owncloud.com/ocis/5.0/deployment/services/s-list/ocm.html).

Put
### Setup First oCIS Instance

```bash
127.0.0.1 ocis-server
127.0.0.1 federation-ocis-server
```

in the `/etc/hosts` file

### Setup first ocis instance
# init oCIS
IDM_ADMIN_PASSWORD=admin \
ocis/bin/ocis init --insecure true

```bash
# run oCIS
OCIS_URL="https://ocis-server:9200" \
OCIS_URL="https://localhost:9200" \
PROXY_ENABLE_BASIC_AUTH=true \
OCIS_ENABLE_OCM=true \
OCM_OCM_PROVIDER_AUTHORIZER_PROVIDERS_FILE="${workspaceFolder}/tests/config/drone/providers.json" \
OCM_OCM_PROVIDER_AUTHORIZER_PROVIDERS_FILE="tests/config/local/providers.json" \
OCIS_ADD_RUN_SERVICES="ocm" \
OCM_OCM_INVITE_MANAGER_INSECURE=true \
OCM_OCM_SHARE_PROVIDER_INSECURE=true \
OCM_OCM_STORAGE_PROVIDER_INSECURE=true \
WEB_UI_CONFIG_FILE="tests/config/local/ocis-web.json" \
ocis/bin/ocis server
```

The first oCIS instance should be available at: https://ocis-server:9200/
The first oCIS instance should be available at: https://localhost:9200/

### Setup second ocis instance
### Setup Second oCIS Instance

#### Using .vscode/launch.json
You can run the second oCIS instance in two ways:

#### Using .env file
#### Using `.vscode/launch.json`

From the `Run and Debug` panel of VSCode, select `Fed oCIS Server` and start the debugger.

#### Using env file

```bash
# init oCIS
source tests/config/drone/.env-federation && ocis/bin/ocis init
source tests/config/local/.env-federation && ocis/bin/ocis init

# run oCIS
ocis/bin/ocis server
```

The second oCIS instance should be available at: https://federation-ocis-server:10200/
The second oCIS instance should be available at: https://localhost:10200/

{{< hint info >}}
To enable ocm in the web interface, you need to set the following envs:
Expand All @@ -557,8 +561,8 @@ To enable ocm in the web interface, you need to set the following envs:
Run the acceptance test with the following command:

```bash
TEST_SERVER_URL="https://ocis-server:9200" \
TEST_SERVER_FED_URL="https://federation-ocis-server:10200" \
TEST_SERVER_URL="https://localhost:9200" \
TEST_SERVER_FED_URL="https://localhost:10200" \
BEHAT_FEATURE="tests/acceptance/features/apiOcm/ocm.feature" \
make test-acceptance-api
```
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/TestHelpers/OcisHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public static function getServerUrl(): string {
return 'https://localhost:9200';
}

/**
* @return string
*/
public static function getFederatedServerUrl(): string {
if (\getenv('TEST_SERVER_FED_URL')) {
return \getenv('TEST_SERVER_FED_URL');
}
return 'https://localhost:10200';
}

/**
* @return bool
*/
Expand Down
72 changes: 44 additions & 28 deletions tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ class FeatureContext extends BehatVariablesContext {
*/
private string $stepLineRef = '';

/**
* @var boolean true if TEST_SERVER_FED_URL is defined
*/
private bool $federatedServerExists;
private int $ocsApiVersion = 1;
private ?ResponseInterface $response = null;
private string $responseUser = '';
Expand Down Expand Up @@ -484,19 +480,10 @@ public function __construct(
$this->alternateAdminPassword = "IHave99LotsOfPriv";
$this->publicLinkSharePassword = "publicPwd:1";

$testServerUrl = OcisHelper::getServerUrl();
$this->baseUrl = \rtrim($testServerUrl, '/');
$this->baseUrl = OcisHelper::getServerUrl();
$this->localBaseUrl = $this->baseUrl;

// federated server url from the environment
$testRemoteServerUrl = \getenv('TEST_SERVER_FED_URL');
if ($testRemoteServerUrl !== false) {
$this->remoteBaseUrl = \rtrim($testRemoteServerUrl, '/');
$this->federatedServerExists = true;
} else {
$this->remoteBaseUrl = $this->localBaseUrl;
$this->federatedServerExists = false;
}
$this->remoteBaseUrl = OcisHelper::getFederatedServerUrl();

// get the admin username from the environment (if defined)
$adminUsernameFromEnvironment = $this->getAdminUsernameFromEnvironment();
Expand Down Expand Up @@ -737,11 +724,8 @@ private static function getPublicLinkSharePasswordFromEnvironment() {
* @return string
*/
public function removeSchemeFromUrl(string $url): string {
return \preg_replace(
"(^https?://)",
"",
$url
);
$parsedUrl = parse_url($url);
return $parsedUrl["host"] . ":" . $parsedUrl["port"];
}

/**
Expand Down Expand Up @@ -1018,14 +1002,6 @@ public function usingServer(?string $server): string {
return $previousServer;
}

/**
*
* @return boolean
*/
public function federatedServerExists(): bool {
return $this->federatedServerExists;
}

/**
* Parses the response as XML
*
Expand Down Expand Up @@ -2146,6 +2122,46 @@ public function substituteInLineCodes(
],
"parameter" => []
],
[
"code" => "%local_base_url%",
"function" => [
$this,
"getLocalBaseUrl"
],
"parameter" => []
],
[
"code" => "%remote_base_url%",
"function" => [
$this,
"getRemoteBaseUrl"
],
"parameter" => []
],
[
"code" => "%base_host_port%",
"function" => [
$this,
"getBaseUrlWithoutScheme"
],
"parameter" => []
],
[
"code" => "%local_host_port%",
"function" => [
$this,
"getLocalBaseUrlWithoutScheme"
],
"parameter" => []
],
[
"code" => "%remote_host_port%",
"function" => [
$this,
"getRemoteBaseUrlWithoutScheme"
],
"parameter" => []
],
[
"code" => "%storage_path%",
"function" => [
Expand Down
31 changes: 4 additions & 27 deletions tests/acceptance/bootstrap/OcmContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@ public function before(BeforeScenarioScope $scope): void {
$this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext');
}

/**
* @return string
*/
public function getOcisDomain(): string {
return $this->extractDomain(OcisHelper::getServerUrl());
}

/**
* @return string
*/
public function getFedOcisDomain(): string {
return $this->extractDomain(\getenv('TEST_SERVER_FED_URL'));
}

/**
* @return string
* @throws Exception
Expand All @@ -77,18 +63,6 @@ public function getLastFederatedInvitationToken():string {
return $this->invitationToken;
}

/**
* @param string $url
*
* @return string
*/
public function extractDomain($url): string {
if (!$url) {
return "localhost";
}
return parse_url($url)["host"];
}

/**
* @param string $user
* @param string $email
Expand Down Expand Up @@ -152,7 +126,10 @@ public function userHasCreatedTheFederationShareInvitation(string $user, $email
* @throws GuzzleException
*/
public function acceptInvitation(string $user, string $token = null): ResponseInterface {
$providerDomain = ($this->featureContext->getCurrentServer() === "LOCAL") ? $this->getFedOcisDomain() : $this->getOcisDomain();
$providerDomain = $this->featureContext->getLocalBaseUrlWithoutScheme();
if ($this->featureContext->getCurrentServer() === "LOCAL") {
$providerDomain = $this->featureContext->getRemoteBaseUrlWithoutScheme();
}
return OcmHelper::acceptInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
Expand Down
9 changes: 2 additions & 7 deletions tests/acceptance/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,8 @@ public function createLdapUser(array $setting):void {
$entry['ownCloudUUID'] = WebDavHelper::generateUUIDv4();
}

if ($this->federatedServerExists()) {
if (!\in_array($setting['userid'], $this->ldapCreatedUsers)) {
$this->ldap->add($newDN, $entry);
}
} else {
$this->ldap->add($newDN, $entry);
}
$this->ldap->add($newDN, $entry);

$this->ldapCreatedUsers[] = $setting["userid"];
}

Expand Down
Loading

0 comments on commit c3b4424

Please sign in to comment.