Removed method isTestingOnOcisOrReva, and refactored its use

This commit is contained in:
Prarup Gurung
2023-03-09 14:25:15 +05:45
parent d9092d7e17
commit fab9bfc734
11 changed files with 147 additions and 1063 deletions
@@ -642,25 +642,6 @@ trait Provisioning {
$this->theLdapUsersHaveBeenResynced();
}
/**
* @Given the LDAP users have been resynced
*
* @return void
* @throws Exception
*/
public function theLdapUsersHaveBeenReSynced():void {
// 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()
);
if ($occResult['code'] !== "0") {
throw new Exception(__METHOD__ . " could not sync LDAP users " . $occResult['stdErr']);
}
}
}
/**
* prepares suitable nested array with user-attributes for multiple users to be created
*
@@ -861,35 +842,18 @@ trait Provisioning {
* @throws Exception
*/
public function deleteLdapUsersAndGroups():void {
$isOcisOrReva = OcisHelper::isTestingOnOcisOrReva();
foreach ($this->ldapCreatedUsers as $user) {
if ($isOcisOrReva) {
$this->ldap->delete(
"uid=" . ldap_escape($user, "", LDAP_ESCAPE_DN) . ",ou=" . $this->ldapUsersOU . "," . $this->ldapBaseDN,
);
}
$this->ldap->delete(
"uid=" . ldap_escape($user, "", LDAP_ESCAPE_DN) . ",ou=" . $this->ldapUsersOU . "," . $this->ldapBaseDN,
);
$this->rememberThatUserIsNotExpectedToExist($user);
}
foreach ($this->ldapCreatedGroups as $group) {
if ($isOcisOrReva) {
$this->ldap->delete(
"cn=" . ldap_escape($group, "", LDAP_ESCAPE_DN) . ",ou=" . $this->ldapGroupsOU . "," . $this->ldapBaseDN,
);
}
$this->ldap->delete(
"cn=" . ldap_escape($group, "", LDAP_ESCAPE_DN) . ",ou=" . $this->ldapGroupsOU . "," . $this->ldapBaseDN,
);
$this->rememberThatGroupIsNotExpectedToExist($group);
}
if (!$isOcisOrReva || !$this->skipImportLdif) {
//delete ou from LDIF import
$this->ldap->delete(
"ou=" . $this->ldapUsersOU . "," . $this->ldapBaseDN,
true
);
//delete all created ldap groups
$this->ldap->delete(
"ou=" . $this->ldapGroupsOU . "," . $this->ldapBaseDN,
true
);
}
$this->theLdapUsersHaveBeenResynced();
}
@@ -1034,18 +998,16 @@ trait Provisioning {
$attributesToCreateUser['userid'] = $userAttributes['userid'];
$attributesToCreateUser['password'] = $userAttributes['password'];
$attributesToCreateUser['displayname'] = $userAttributes['displayName'];
if (OcisHelper::isTestingOnOcisOrReva()) {
$attributesToCreateUser['username'] = $userAttributes['userid'];
if ($userAttributes['email'] === null) {
Assert::assertArrayHasKey(
'userid',
$userAttributes,
__METHOD__ . " userAttributes array does not have key 'userid'"
);
$attributesToCreateUser['email'] = $userAttributes['userid'] . '@owncloud.com';
} else {
$attributesToCreateUser['email'] = $userAttributes['email'];
}
$attributesToCreateUser['username'] = $userAttributes['userid'];
if ($userAttributes['email'] === null) {
Assert::assertArrayHasKey(
'userid',
$userAttributes,
__METHOD__ . " userAttributes array does not have key 'userid'"
);
$attributesToCreateUser['email'] = $userAttributes['userid'] . '@owncloud.com';
} else {
$attributesToCreateUser['email'] = $userAttributes['email'];
}
if ($useGraph) {
$body = \TestHelpers\GraphHelper::prepareCreateUserPayload(
@@ -1134,33 +1096,14 @@ trait Provisioning {
$userAttributes['id']
);
if (OcisHelper::isTestingOnOcisOrReva()) {
OcisHelper::createEOSStorageHome(
$this->getBaseUrl(),
$userAttributes['userid'],
$userAttributes['password'],
$this->getStepLineRef()
);
// We don't need to set displayName and email while running in oCIS
// As they are set when creating the user
continue;
}
if (isset($userAttributes['displayName'])) {
$editData[] = ['user' => $userAttributes['userid'], 'key' => 'displayname', 'value' => $userAttributes['displayName']];
}
if (isset($userAttributes['email'])) {
$editData[] = ['user' => $userAttributes['userid'], 'key' => 'email', 'value' => $userAttributes['email']];
}
}
// Edit the users in parallel to make the process faster.
if (!OcisHelper::isTestingOnOcisOrReva() && !$useLdap && \count($editData) > 0) {
UserHelper::editUserBatch(
OcisHelper::createEOSStorageHome(
$this->getBaseUrl(),
$editData,
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->stepLineRef
$userAttributes['userid'],
$userAttributes['password'],
$this->getStepLineRef()
);
// We don't need to set displayName and email while running in oCIS
// As they are set when creating the user
}
if (isset($exceptionToThrow)) {
@@ -1171,7 +1114,7 @@ trait Provisioning {
// then do some work to "manually" put the skeleton files in place.
// When testing on ownCloud 10 the user is already getting whatever
// skeleton dir is defined in the server-under-test.
if ($skeleton && OcisHelper::isTestingOnOcisOrReva()) {
if ($skeleton) {
$this->manuallyAddSkeletonFiles($usersAttributes);
}
@@ -1461,10 +1404,8 @@ trait Provisioning {
$displayname = \array_key_exists("displayname", $table) ? $table["displayname"] : null;
$email = \array_key_exists("email", $table) ? $table["email"] : null;
if (OcisHelper::isTestingOnOcisOrReva()) {
if ($email === null) {
$email = $username . '@owncloud.com';
}
if ($email === null) {
$email = $username . '@owncloud.com';
}
$userAttributes = [
@@ -1480,9 +1421,7 @@ trait Provisioning {
$userAttributes[] = ["email", $email];
}
if (OcisHelper::isTestingOnOcisOrReva()) {
$userAttributes[] = ["username", $username];
}
$userAttributes[] = ["username", $username];
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
@@ -1498,9 +1437,7 @@ trait Provisioning {
null,
$this->theHTTPStatusCodeWasSuccess()
);
if (OcisHelper::isTestingOnOcisOrReva()) {
$this->manuallyAddSkeletonFilesForUser($username, $password);
}
$this->manuallyAddSkeletonFilesForUser($username, $password);
}
/**
@@ -1515,20 +1452,15 @@ trait Provisioning {
public function adminSendsUserCreationRequestUsingTheProvisioningApi(string $user, string $password):void {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
if (OcisHelper::isTestingOnOcisOrReva()) {
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $user],
['password', $password],
['username', $user],
['email', $email]
]
);
} else {
$email = null;
$bodyTable = new TableNode([['userid', $user], ['password', $password]]);
}
);
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
@@ -1547,7 +1479,7 @@ trait Provisioning {
null,
$success
);
if (OcisHelper::isTestingOnOcisOrReva() && $success) {
if ($success) {
OcisHelper::createEOSStorageHome(
$this->getBaseUrl(),
$user,
@@ -1587,20 +1519,15 @@ trait Provisioning {
public function userSendsUserCreationRequestUsingTheProvisioningApi(string $user, string $userToCreate, string $password):void {
$userToCreate = $this->getActualUsername($userToCreate);
$password = $this->getActualPassword($password);
if (OcisHelper::isTestingOnOcisOrReva()) {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $password],
['username', $userToCreate],
['email', $email]
]
);
} else {
$email = null;
$bodyTable = new TableNode([['userid', $userToCreate], ['password', $password]]);
}
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
"POST",
@@ -1634,23 +1561,16 @@ trait Provisioning {
):void {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
if (OcisHelper::isTestingOnOcisOrReva()) {
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $user],
['password', $password],
['username', $user],
['email', $email],
['groups[]', $group],
]
);
} else {
$email = null;
$bodyTable = new TableNode(
[['userid', $user], ['password', $password], ['groups[]', $group]]
);
}
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
"POST",
@@ -1665,9 +1585,7 @@ trait Provisioning {
null,
$this->theHTTPStatusCodeWasSuccess()
);
if (OcisHelper::isTestingOnOcisOrReva()) {
$this->manuallyAddSkeletonFilesForUser($user, $password);
}
$this->manuallyAddSkeletonFilesForUser($user, $password);
}
/**
@@ -1689,23 +1607,16 @@ trait Provisioning {
):void {
$userToCreate = $this->getActualUsername($userToCreate);
$password = $this->getActualPassword($password);
if (OcisHelper::isTestingOnOcisOrReva()) {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
);
} else {
$email = null;
$bodyTable = new TableNode(
[['userid', $userToCreate], ['password', $password], ['groups[]', $group]]
);
}
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$groupadmin,
"POST",
@@ -1720,9 +1631,7 @@ trait Provisioning {
null,
$this->theHTTPStatusCodeWasSuccess()
);
if (OcisHelper::isTestingOnOcisOrReva()) {
$this->manuallyAddSkeletonFilesForUser($userToCreate, $password);
}
$this->manuallyAddSkeletonFilesForUser($userToCreate, $password);
}
/**
@@ -1743,23 +1652,16 @@ trait Provisioning {
):void {
$userToCreate = $this->getActualUsername($userToCreate);
$password = $this->getActualPassword($password);
if (OcisHelper::isTestingOnOcisOrReva()) {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
);
} else {
$email = null;
$bodyTable = new TableNode(
[['userid', $userToCreate], ['password', $password], ['groups[]', $group]]
);
}
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$groupadmin,
"POST",
@@ -3389,27 +3291,22 @@ trait Provisioning {
// sending the username in lowercase in the auth but in uppercase in
// the URL see https://github.com/owncloud/core/issues/36822
$user = $this->getActualUsername($user);
if (OcisHelper::isTestingOnOcisOrReva()) {
// In OCIS an intermittent issue restricts users to list their own account
// 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::isTestingParallelDeployment()) {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($user);
} elseif (OcisHelper::isTestingWithGraphApi()) {
$requestingUser = $this->getAdminUsername();
$requestingPassword = $this->getAdminPassword();
} elseif (OcisHelper::isTestingOnOcis()) {
$requestingUser = 'moss';
$requestingPassword = 'vista';
} else {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($requestingUser);
}
} else {
// In OCIS an intermittent issue restricts users to list their own account
// 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::isTestingParallelDeployment()) {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($user);
} elseif (OcisHelper::isTestingWithGraphApi()) {
$requestingUser = $this->getAdminUsername();
$requestingPassword = $this->getAdminPassword();
} elseif (OcisHelper::isTestingOnOcis()) {
$requestingUser = 'moss';
$requestingPassword = 'vista';
} else {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($requestingUser);
}
$path = (OcisHelper::isTestingWithGraphApi())
? "/graph/v1.0"
@@ -4511,7 +4408,7 @@ trait Provisioning {
* @throws GuzzleException
*/
public function groupExists(string $group):bool {
if ($this->isTestingWithLdap() && OcisHelper::isTestingOnOcisOrReva()) {
if ($this->isTestingWithLdap()) {
$baseDN = $this->getLdapBaseDN();
$newDN = 'cn=' . $group . ',ou=' . $this->ldapGroupsOU . ',' . $baseDN;
if ($this->ldap->getEntry($newDN) !== null) {
@@ -5779,13 +5676,12 @@ trait Provisioning {
$this->waitForDavRequestsToFinish();
$this->restoreParametersAfterScenario();
if (OcisHelper::isTestingOnOcisOrReva() && $this->someUsersHaveBeenCreated()) {
if ($this->someUsersHaveBeenCreated()) {
foreach ($this->getCreatedUsers() as $user) {
OcisHelper::deleteRevaUserData($user["actualUsername"]);
}
} elseif (OcisHelper::isTestingOnOc10()) {
$this->resetAdminUserAttributes();
}
if ($this->isTestingWithLdap()) {
$this->deleteLdapUsersAndGroups();
}
@@ -5863,27 +5759,6 @@ trait Provisioning {
$this->usingServer($previousServer);
}
/**
* @BeforeScenario
*
* @return void
* @throws Exception
*/
public function rememberAppEnabledDisabledState():void {
if (!OcisHelper::isTestingOnOcisOrReva()) {
SetupHelper::init(
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getBaseUrl(),
$this->getOcPath()
);
$this->runOcc(['app:list', '--output json']);
$apps = \json_decode($this->getStdOutOfOccCommand(), true);
$this->enabledApps = \array_keys($apps["enabled"]);
$this->disabledApps = \array_keys($apps["disabled"]);
}
}
/**
* @BeforeScenario @rememberGroupsThatExist
*
@@ -5894,34 +5769,6 @@ trait Provisioning {
$this->startingGroups = $this->getArrayOfGroupsResponded($this->getAllGroups());
}
/**
* @AfterScenario
*
* @return void
* @throws Exception
*/
public function restoreAppEnabledDisabledState():void {
if (!OcisHelper::isTestingOnOcisOrReva() && !$this->isRunningForDbConversion()) {
$this->runOcc(['app:list', '--output json']);
$apps = \json_decode($this->getStdOutOfOccCommand(), true);
$currentlyEnabledApps = \array_keys($apps["enabled"]);
$currentlyDisabledApps = \array_keys($apps["disabled"]);
foreach ($currentlyDisabledApps as $disabledApp) {
if (\in_array($disabledApp, $this->enabledApps)) {
$this->adminEnablesOrDisablesApp('enables', $disabledApp);
}
}
foreach ($currentlyEnabledApps as $enabledApp) {
if (\in_array($enabledApp, $this->disabledApps)) {
$this->adminEnablesOrDisablesApp('disables', $enabledApp);
}
}
}
}
/**
* disable or enable user
*
@@ -6074,36 +5921,16 @@ trait Provisioning {
* @throws Exception
*/
private function setSkeletonDirByType(string $skeletonType): string {
if (OcisHelper::isTestingOnOcisOrReva()) {
$originalSkeletonPath = \getenv("SKELETON_DIR");
if ($originalSkeletonPath === false) {
$originalSkeletonPath = '';
}
if ($skeletonType !== '') {
$skeletonDirName = $skeletonType . "Skeleton";
$newSkeletonPath = \dirname($originalSkeletonPath) . '/' . $skeletonDirName;
\putenv(
"SKELETON_DIR=" . $newSkeletonPath
);
}
} else {
$baseUrl = $this->getBaseUrl();
$originalSkeletonPath = $this->getSkeletonDirectory($baseUrl);
if ($skeletonType !== '') {
OcsApiHelper::sendRequest(
$baseUrl,
$this->getAdminUsername(),
$this->getAdminPassword(),
'POST',
"/apps/testing/api/v1/testingskeletondirectory",
$this->getStepLineRef(),
[
'directory' => $skeletonType . "Skeleton"
],
$this->getOcsApiVersion()
);
}
$originalSkeletonPath = \getenv("SKELETON_DIR");
if ($originalSkeletonPath === false) {
$originalSkeletonPath = '';
}
if ($skeletonType !== '') {
$skeletonDirName = $skeletonType . "Skeleton";
$newSkeletonPath = \dirname($originalSkeletonPath) . '/' . $skeletonDirName;
\putenv(
"SKELETON_DIR=" . $newSkeletonPath
);
}
return $originalSkeletonPath;
}
@@ -6119,22 +5946,9 @@ trait Provisioning {
* @throws Exception
*/
private function setSkeletonDir(string $skeletonDir): string {
if (OcisHelper::isTestingOnOcisOrReva()) {
$originalSkeletonPath = \getenv("SKELETON_DIR");
if ($skeletonDir !== '') {
\putenv("SKELETON_DIR=" . $skeletonDir);
}
} else {
$baseUrl = $this->getBaseUrl();
$originalSkeletonPath = $this->getSkeletonDirectory($baseUrl);
if ($skeletonDir !== '') {
$this->runOcc(
["config:system:set skeletondirectory --value $skeletonDir"],
null,
null,
$baseUrl
);
}
$originalSkeletonPath = \getenv("SKELETON_DIR");
if ($skeletonDir !== '') {
\putenv("SKELETON_DIR=" . $skeletonDir);
}
return $originalSkeletonPath;
}