From d29de08607535ada390fed4a92037fa3261f1251 Mon Sep 17 00:00:00 2001 From: saw-jan Date: Wed, 15 Dec 2021 16:34:33 +0545 Subject: [PATCH 1/5] refactor test helpers and contexts for parallel deployment tests --- tests/TestHelpers/HttpRequestHelper.php | 39 +++++++++++++++++++ tests/TestHelpers/OcisHelper.php | 7 ++++ .../features/bootstrap/FeatureContext.php | 36 +++++++++++++++++ .../features/bootstrap/Provisioning.php | 32 ++++++++++++++- 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index f729a243f700..be29002a57ea 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -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 @@ -296,6 +318,23 @@ public static function createRequest( $body = \http_build_query($body, '', '&'); $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } + + if (OcisHelper::isTestingParallelDeployment()) { + $oCISServerUrl = \getenv('TEST_SERVER_URL'); + $oC10ServerUrl = \getenv('TEST_OC10_URL'); + + // 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){ + $url = str_replace($oCISServerUrl, $oC10ServerUrl, $url); + var_dump($url); + } else { + // set 'owncloud-server' selector cookie for oCIS requests + $headers['Cookie'] = self::getOCSelectorCookie(); + } + } + $request = new Request( $method, $url, diff --git a/tests/TestHelpers/OcisHelper.php b/tests/TestHelpers/OcisHelper.php index 1ff6c1918d2c..e60be488945e 100644 --- a/tests/TestHelpers/OcisHelper.php +++ b/tests/TestHelpers/OcisHelper.php @@ -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 */ diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index a0e53e9470cd..430125e9b4f7 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -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 * @@ -584,6 +605,9 @@ public function __construct( $this->cookieJar = new CookieJar(); $this->ocPath = $ocPath; + // PARALLEL DEPLOY: ownCloud selector + $this->oCSelector = "oc10"; + // These passwords are referenced in tests and can be overridden by // setting environment variables. $this->alt1UserPassword = "1234"; @@ -4170,4 +4194,16 @@ private function restoreParameters(string $server):void { $this->getBaseUrl() ); } + + /** + * @Given using :selector as owncloud selector + * + * @param string $selector 'ocis' or 'oc10' + * + * @return void + */ + public function usingOwncloudSelector(string $selector): void { + $this->setOCSelector($selector); + HttpRequestHelper::setOCSelectorCookie("owncloud-selector=$selector;path=/;"); + } } diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index fd65118c79c0..fa9e49e3c40b 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -597,7 +597,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() @@ -666,6 +667,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` @@ -702,6 +717,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); @@ -3136,7 +3161,10 @@ 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);; + $requestingPassword = $this->getPasswordForUser($user); + } else if (OcisHelper::isTestingOnOcis()) { $requestingUser = 'moss'; $requestingPassword = 'vista'; } else { From 4913d289defb4bbbcc7e81fdb74c4b8ba171f05f Mon Sep 17 00:00:00 2001 From: saw-jan Date: Thu, 16 Dec 2021 12:40:21 +0545 Subject: [PATCH 2/5] get correct config path for parallel deployment --- .../features/bootstrap/Provisioning.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index fa9e49e3c40b..98a247702855 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -584,9 +584,18 @@ 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); + var_dump($configPath); + $ldifFile = $configPath . "/" . \basename($ldifFile); + var_dump($ldifFile); + } + } + $this->importLdifFile($ldifFile); $this->theLdapUsersHaveBeenResynced(); } From 1151de8f8d974700414f0be72a8b6ffb7d6d2326 Mon Sep 17 00:00:00 2001 From: saw-jan Date: Thu, 16 Dec 2021 13:01:32 +0545 Subject: [PATCH 3/5] allow occ to run while testing for parallel deployment --- tests/TestHelpers/HttpRequestHelper.php | 1 - tests/TestHelpers/SetupHelper.php | 2 +- tests/acceptance/features/bootstrap/Provisioning.php | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index be29002a57ea..4badffe9c213 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -328,7 +328,6 @@ public static function createRequest( // change server to oC10 if the request url has `/apps/testing` if(strpos($url, "/apps/testing") !== false){ $url = str_replace($oCISServerUrl, $oC10ServerUrl, $url); - var_dump($url); } else { // set 'owncloud-server' selector cookie for oCIS requests $headers['Cookie'] = self::getOCSelectorCookie(); diff --git a/tests/TestHelpers/SetupHelper.php b/tests/TestHelpers/SetupHelper.php index 36a07a6247bd..6fb9637d50eb 100644 --- a/tests/TestHelpers/SetupHelper.php +++ b/tests/TestHelpers/SetupHelper.php @@ -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"); diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 98a247702855..fa20f881f05b 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -590,9 +590,7 @@ public function connectToLdap(array $suiteParameters):void { $behatYml = \getenv("BEHAT_YML"); if($behatYml){ $configPath = \dirname($behatYml); - var_dump($configPath); $ldifFile = $configPath . "/" . \basename($ldifFile); - var_dump($ldifFile); } } $this->importLdifFile($ldifFile); From fc76017f18b076f0f5aed1d9a379f2c94930bbba Mon Sep 17 00:00:00 2001 From: saw-jan Date: Thu, 16 Dec 2021 15:02:39 +0545 Subject: [PATCH 4/5] remove steps --- tests/TestHelpers/HttpRequestHelper.php | 6 +++--- .../features/bootstrap/FeatureContext.php | 14 +------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index 4badffe9c213..ae9d0408d005 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -320,13 +320,13 @@ public static function createRequest( } if (OcisHelper::isTestingParallelDeployment()) { - $oCISServerUrl = \getenv('TEST_SERVER_URL'); - $oC10ServerUrl = \getenv('TEST_OC10_URL'); - // 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){ + $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 diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 430125e9b4f7..3622479259ea 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -605,7 +605,7 @@ public function __construct( $this->cookieJar = new CookieJar(); $this->ocPath = $ocPath; - // PARALLEL DEPLOY: ownCloud selector + // PARALLEL DEPLOYMENT: ownCloud selector $this->oCSelector = "oc10"; // These passwords are referenced in tests and can be overridden by @@ -4194,16 +4194,4 @@ private function restoreParameters(string $server):void { $this->getBaseUrl() ); } - - /** - * @Given using :selector as owncloud selector - * - * @param string $selector 'ocis' or 'oc10' - * - * @return void - */ - public function usingOwncloudSelector(string $selector): void { - $this->setOCSelector($selector); - HttpRequestHelper::setOCSelectorCookie("owncloud-selector=$selector;path=/;"); - } } From 3fe22ea10c0cccc4f460d6a923f58496fa7f6576 Mon Sep 17 00:00:00 2001 From: saw-jan Date: Fri, 17 Dec 2021 13:36:52 +0545 Subject: [PATCH 5/5] fix php style --- tests/TestHelpers/HttpRequestHelper.php | 2 +- tests/acceptance/features/bootstrap/Provisioning.php | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php index ae9d0408d005..957f11c9b075 100644 --- a/tests/TestHelpers/HttpRequestHelper.php +++ b/tests/TestHelpers/HttpRequestHelper.php @@ -323,7 +323,7 @@ public static function createRequest( // 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){ + if (strpos($url, "/apps/testing") !== false) { $oCISServerUrl = \getenv('TEST_SERVER_URL'); $oC10ServerUrl = \getenv('TEST_OC10_URL'); diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index fa20f881f05b..f4438796dcfb 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -588,7 +588,7 @@ public function connectToLdap(array $suiteParameters):void { $ldifFile = __DIR__ . (string)$suiteParameters['ldapInitialUserFilePath']; if (OcisHelper::isTestingParallelDeployment()) { $behatYml = \getenv("BEHAT_YML"); - if($behatYml){ + if ($behatYml) { $configPath = \dirname($behatYml); $ldifFile = $configPath . "/" . \basename($ldifFile); } @@ -682,8 +682,8 @@ public function buildUsersAttributesArray(bool $setDefaultAttributes, array $tab */ public function generateUUIDv4(): string { $data = random_bytes(16); - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + $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)); } @@ -3169,9 +3169,10 @@ public function userExists(?string $user):bool { // https://github.com/owncloud/ocis/issues/820 // The special code can be reverted once the issue is fixed if (OcisHelper::isTestingParallelDeployment()) { - $requestingUser = $this->getActualUsername($user);; + $requestingUser = $this->getActualUsername($user); + ; $requestingPassword = $this->getPasswordForUser($user); - } else if (OcisHelper::isTestingOnOcis()) { + } elseif (OcisHelper::isTestingOnOcis()) { $requestingUser = 'moss'; $requestingPassword = 'vista'; } else {