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

[full-ci][tests-only] Refactor test codes for parallel deployment tests #39603

Closed
wants to merge 5 commits into from
Closed
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
38 changes: 38 additions & 0 deletions tests/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@
* Helper for HTTP requests
*/
class HttpRequestHelper {

/**
* @var string
*/
private static $oCSelectorCookie = null;

/**
* @return string
*/
public static function getOCSelectorCookie(): string {
return self::$oCSelectorCookie;
}

/**
* @param string $oCSelectorCookie "owncloud-selector=oc10;path=/;"
*
* @return void
*/
public static function setOCSelectorCookie(string $oCSelectorCookie): void {
self::$oCSelectorCookie = $oCSelectorCookie;
}

/**
*
* @param string|null $url
Expand Down Expand Up @@ -296,6 +318,22 @@ public static function createRequest(
$body = \http_build_query($body, '', '&');
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
}

if (OcisHelper::isTestingParallelDeployment()) {
// oCIS cannot handle '/apps/testing' endpoints
// so those requests must be redirected to oC10 server
// change server to oC10 if the request url has `/apps/testing`
if (strpos($url, "/apps/testing") !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: in CI we always happen t have the testing app in the apps folder. Running locally, it can be in apps-external. But that should not make a difference to the API endpoint! So this should be fine.

$oCISServerUrl = \getenv('TEST_SERVER_URL');
$oC10ServerUrl = \getenv('TEST_OC10_URL');

$url = str_replace($oCISServerUrl, $oC10ServerUrl, $url);
} else {
// set 'owncloud-server' selector cookie for oCIS requests
$headers['Cookie'] = self::getOCSelectorCookie();
}
}

$request = new Request(
$method,
$url,
Expand Down
7 changes: 7 additions & 0 deletions tests/TestHelpers/OcisHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public static function isTestingOnOc10():bool {
return (!self::isTestingOnOcisOrReva());
}

/**
* @return bool
*/
public static function isTestingParallelDeployment(): bool {
return (\getenv("TEST_PARALLEL_DEPLOYMENT") === "true");
}

/**
* @return bool|string false if no command given or the command as string
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/TestHelpers/SetupHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public static function runOcc(
?string $ocPath = null,
?array $envVariables = null
):array {
if (OcisHelper::isTestingOnOcisOrReva()) {
if (OcisHelper::isTestingOnOcisOrReva() && !OcisHelper::isTestingParallelDeployment()) {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
$baseUrl = self::checkBaseUrl($baseUrl, "runOcc");
Expand Down
24 changes: 24 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,27 @@ class FeatureContext extends BehatVariablesContext {
*/
private $lastOCSStatusCodesArray = [];

/**
* @var string
*/
private $oCSelector;

/**
* @param string $selector
*
* @return void
*/
public function setOCSelector(string $selector): void {
$this->oCSelector = $selector;
}

/**
* @return string
*/
public function getOCSelector(): string {
return $this->oCSelector;
}

/**
* @param string $httpStatusCode
*
Expand Down Expand Up @@ -584,6 +605,9 @@ public function __construct(
$this->cookieJar = new CookieJar();
$this->ocPath = $ocPath;

// PARALLEL DEPLOYMENT: ownCloud selector
$this->oCSelector = "oc10";

// These passwords are referenced in tests and can be overridden by
// setting environment variables.
$this->alt1UserPassword = "1234";
Expand Down
46 changes: 41 additions & 5 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,16 @@ public function connectToLdap(array $suiteParameters):void {
];
$this->ldap = new Ldap($options);
$this->ldap->bind();
$this->importLdifFile(
__DIR__ . (string)$suiteParameters['ldapInitialUserFilePath']
);

$ldifFile = __DIR__ . (string)$suiteParameters['ldapInitialUserFilePath'];
if (OcisHelper::isTestingParallelDeployment()) {
$behatYml = \getenv("BEHAT_YML");
if ($behatYml) {
$configPath = \dirname($behatYml);
$ldifFile = $configPath . "/" . \basename($ldifFile);
}
}
$this->importLdifFile($ldifFile);
$this->theLdapUsersHaveBeenResynced();
}

Expand All @@ -597,7 +604,8 @@ public function connectToLdap(array $suiteParameters):void {
* @throws Exception
*/
public function theLdapUsersHaveBeenReSynced():void {
if (!OcisHelper::isTestingOnOcisOrReva()) {
// we need to sync ldap users when testing for parallel deployment
if (!OcisHelper::isTestingOnOcisOrReva() || OcisHelper::isTestingParallelDeployment()) {
$occResult = SetupHelper::runOcc(
['user:sync', 'OCA\User_LDAP\User_Proxy', '-m', 'remove'],
$this->getStepLineRef()
Expand Down Expand Up @@ -666,6 +674,20 @@ public function buildUsersAttributesArray(bool $setDefaultAttributes, array $tab
return $usersAttributes;
}

/**
* Generates UUIDV4
* Example: 123e4567-e89b-12d3-a456-426614174000
*
* @return string
*/
public function generateUUIDv4(): string {
$data = random_bytes(16);
$data[6] = \chr(\ord($data[6]) & 0x0f | 0x40);
$data[8] = \chr(\ord($data[8]) & 0x3f | 0x80);

return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

/**
* creates a user in the ldap server
* the created user is added to `createdUsersList`
Expand Down Expand Up @@ -702,6 +724,16 @@ public function createLdapUser(array $setting):void {
$entry['gidNumber'] = 5000;
$entry['uidNumber'] = $uidNumber;

if (OcisHelper::isTestingParallelDeployment()) {
$entry['objectclass'][] = 'organizationalPerson';
$entry['objectclass'][] = 'ownCloud';
$entry['objectclass'][] = 'person';
$entry['objectclass'][] = 'top';
$entry['uid'] = $setting["userid"];
$entry['ownCloudSelector'] = $this->getOCSelector();
$entry['ownCloudUUID'] = $this->generateUUIDv4();
}

if ($this->federatedServerExists()) {
if (!\in_array($setting['userid'], $this->ldapCreatedUsers)) {
$this->ldap->add($newDN, $entry);
Expand Down Expand Up @@ -3136,7 +3168,11 @@ public function userExists(?string $user):bool {
// So use admin account to list the user
// https://github.com/owncloud/ocis/issues/820
// The special code can be reverted once the issue is fixed
if (OcisHelper::isTestingOnOcis()) {
if (OcisHelper::isTestingParallelDeployment()) {
$requestingUser = $this->getActualUsername($user);
;
phil-davis marked this conversation as resolved.
Show resolved Hide resolved
$requestingPassword = $this->getPasswordForUser($user);
} elseif (OcisHelper::isTestingOnOcis()) {
$requestingUser = 'moss';
$requestingPassword = 'vista';
} else {
Expand Down