Removed restoreParameters methods

This commit is contained in:
Prarup Gurung
2023-03-02 12:40:51 +05:45
parent fab9bfc734
commit 65d11ef634
2 changed files with 28 additions and 141 deletions

View File

@@ -3937,29 +3937,6 @@ class FeatureContext extends BehatVariablesContext {
return;
}
/**
* runs a function on every server (LOCAL & REMOTE).
* The callable function receives the server (LOCAL or REMOTE) as first argument
*
* @param callable $callback
*
* @return array
*/
public function runFunctionOnEveryServer(callable $callback): array {
$previousServer = $this->getCurrentServer();
$result = [];
foreach (['LOCAL', 'REMOTE'] as $server) {
$this->usingServer($server);
if (($server === 'LOCAL')
|| $this->federatedServerExists()
) {
$result[$server] = \call_user_func($callback, $server);
}
}
$this->usingServer($previousServer);
return $result;
}
/**
* Verify that the tableNode contains expected headers
*
@@ -4372,85 +4349,6 @@ class FeatureContext extends BehatVariablesContext {
];
}
/**
* restore settings of the system and delete new settings that were created in the test runs
*
* @param string $server LOCAL|REMOTE
*
* @return void
*
* @throws Exception
* @throws GuzzleException
*
*/
private function restoreParameters(string $server): void {
$commands = [];
if ($this->isTestingWithLdap()) {
$this->resetOldLdapConfig();
}
$result = SetupHelper::runOcc(
['config:list'],
$this->getStepLineRef(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getBaseUrl(),
$this->getOcPath()
);
$currentConfigList = \json_decode($result['stdOut'], true);
foreach ($currentConfigList['system'] as $configKey => $configValue) {
if (!\array_key_exists(
$configKey,
$this->savedConfigList[$server]['system']
)
) {
$commands[] = ["command" => ['config:system:delete', $configKey]];
}
}
foreach ($this->savedConfigList[$server]['system'] as $configKey => $configValue) {
if (!\array_key_exists($configKey, $currentConfigList["system"])
|| $currentConfigList["system"][$configKey] !== $this->savedConfigList[$server]['system'][$configKey]
) {
$commands[] = ["command" => ['config:system:set', "--type=json", "--value=" . \json_encode($configValue), $configKey]];
}
}
foreach ($currentConfigList['apps'] as $appName => $appSettings) {
foreach ($appSettings as $configKey => $configValue) {
//only check if the app was there in the original configuration
if (\array_key_exists($appName, $this->savedConfigList[$server]['apps'])
&& !\array_key_exists(
$configKey,
$this->savedConfigList[$server]['apps'][$appName]
)
) {
$commands[] = ["command" => ['config:app:delete', $appName, $configKey]];
} elseif (\array_key_exists($appName, $this->savedConfigList[$server]['apps'])
&& \array_key_exists($configKey, $this->savedConfigList[$server]['apps'][$appName])
&& $this->savedConfigList[$server]['apps'][$appName][$configKey] !== $configValue
) {
// Do not accidentally disable apps here (perhaps too early)
// That is done in Provisioning.php restoreAppEnabledDisabledState()
if ($configKey !== "enabled") {
$commands[] = [
"command" => [
'config:app:set',
$appName,
$configKey,
"--value=" . $this->savedConfigList[$server]['apps'][$appName][$configKey]
]
];
}
}
}
}
SetupHelper::runBulkOcc(
$commands,
$this->getStepLineRef(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getBaseUrl()
);
}
/**
* The method returns userId
*

View File

@@ -639,7 +639,6 @@ trait Provisioning {
if (!$this->skipImportLdif) {
$this->importLdifFile($ldifFile);
}
$this->theLdapUsersHaveBeenResynced();
}
/**
@@ -747,7 +746,6 @@ trait Provisioning {
$this->ldap->add($newDN, $entry);
}
$this->ldapCreatedUsers[] = $setting["userid"];
$this->theLdapUsersHaveBeenReSynced();
}
/**
@@ -854,7 +852,6 @@ trait Provisioning {
);
$this->rememberThatGroupIsNotExpectedToExist($group);
}
$this->theLdapUsersHaveBeenResynced();
}
/**
@@ -1102,8 +1099,6 @@ trait Provisioning {
$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)) {
@@ -1455,11 +1450,11 @@ trait Provisioning {
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $user],
['password', $password],
['username', $user],
['email', $email]
]
['userid', $user],
['password', $password],
['username', $user],
['email', $email]
]
);
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
@@ -1522,11 +1517,11 @@ trait Provisioning {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $password],
['username', $userToCreate],
['email', $email]
]
['userid', $userToCreate],
['password', $password],
['username', $userToCreate],
['email', $email]
]
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
@@ -1564,12 +1559,12 @@ trait Provisioning {
$email = $user . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $user],
['password', $password],
['username', $user],
['email', $email],
['groups[]', $group],
]
['userid', $user],
['password', $password],
['username', $user],
['email', $email],
['groups[]', $group],
]
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
@@ -1610,12 +1605,12 @@ trait Provisioning {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$groupadmin,
@@ -1655,12 +1650,12 @@ trait Provisioning {
$email = $userToCreate . '@owncloud.com';
$bodyTable = new TableNode(
[
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
['userid', $userToCreate],
['password', $userToCreate],
['username', $userToCreate],
['email', $email],
['groups[]', $group],
]
);
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$groupadmin,
@@ -3975,7 +3970,6 @@ trait Provisioning {
$ldapEntry = $this->ldap->getEntry($entry . "," . $this->ldapBaseDN);
Laminas\Ldap\Attribute::setAttribute($ldapEntry, $attribute, $value, $append);
$this->ldap->update($entry . "," . $this->ldapBaseDN, $ldapEntry);
$this->theLdapUsersHaveBeenReSynced();
}
/**
@@ -4049,7 +4043,6 @@ trait Provisioning {
$memberAttr,
"cn=$group,ou=$ou"
);
$this->theLdapUsersHaveBeenReSynced();
}
/**
@@ -4060,7 +4053,6 @@ trait Provisioning {
*/
public function deleteTheLdapEntry(string $entry):void {
$this->ldap->delete($entry . "," . $this->ldapBaseDN);
$this->theLdapUsersHaveBeenReSynced();
}
/**
@@ -4076,7 +4068,6 @@ trait Provisioning {
$ou = $this->getLdapGroupsOU();
}
$this->deleteTheLdapEntry("cn=$group,ou=$ou");
$this->theLdapUsersHaveBeenReSynced();
$key = \array_search($group, $this->ldapCreatedGroups);
if ($key !== false) {
unset($this->ldapCreatedGroups[$key]);
@@ -4123,7 +4114,6 @@ trait Provisioning {
$entry,
$displayName
);
$this->theLdapUsersHaveBeenReSynced();
}
/**
@@ -5674,7 +5664,6 @@ trait Provisioning {
*/
public function afterScenario():void {
$this->waitForDavRequestsToFinish();
$this->restoreParametersAfterScenario();
if ($this->someUsersHaveBeenCreated()) {
foreach ($this->getCreatedUsers() as $user) {