Cleaned up orphaned methods in SetupHelper

This commit is contained in:
Prarup Gurung
2023-03-13 13:11:37 +05:45
parent 810b7b5279
commit 68ed280e27
6 changed files with 2 additions and 730 deletions

View File

@@ -52,155 +52,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
*/
private static $adminPassword = null;
/**
* creates a user
*
* @param string|null $userName
* @param string|null $password
* @param string|null $xRequestId
* @param string|null $displayName
* @param string|null $email
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function createUser(
?string $userName,
?string $password,
?string $xRequestId = '',
?string $displayName = null,
?string $email = null
):array {
$occCommand = ['user:add', '--password-from-env'];
if ($displayName !== null) {
$occCommand = \array_merge($occCommand, ["--display-name", $displayName]);
}
if ($email !== null) {
$occCommand = \array_merge($occCommand, ["--email", $email]);
}
\putenv("OC_PASS=" . $password);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* deletes a user
*
* @param string|null $userName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function deleteUser(
?string $userName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
*
* @param string|null $userName
* @param string|null $app
* @param string|null $key
* @param string|null $value
* @param string|null $xRequestId
*
* @return string[]
* @throws Exception
*/
public static function changeUserSetting(
?string $userName,
?string $app,
?string $key,
?string $value,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* creates a group
*
* @param string|null $groupName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function createGroup(
?string $groupName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* adds an existing user to a group, creating the group if it does not exist
*
* @param string|null $groupName
* @param string|null $userName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function addUserToGroup(
?string $groupName,
?string $userName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* removes a user from a group
*
* @param string|null $groupName
* @param string|null $userName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function removeUserFromGroup(
?string $groupName,
?string $userName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* deletes a group
*
* @param string|null $groupName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function deleteGroup(
?string $groupName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
*
* @param string|null $xRequestId
*
* @return string[]
* @throws Exception
*/
public static function getGroups(
?string $xRequestId = ''
):array {
return \json_decode(
['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']
);
}
/**
*
* @param HookScope $scope
@@ -253,21 +104,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
self::$ocPath = self::normaliseOcPath($ocPath);
}
/**
*
* @return string path to the testing app occ endpoint
* @throws Exception if ocPath has not been set yet
*/
public static function getOcPath():?string {
if (self::$ocPath === null) {
throw new Exception(
"getOcPath called before ocPath is set by init"
);
}
return self::$ocPath;
}
/**
*
* @param string|null $baseUrl
@@ -657,298 +493,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
return $localContent;
}
/**
* enables an app
*
* @param string|null $appName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function enableApp(
?string $appName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* disables an app
*
* @param string|null $appName
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws Exception
*/
public static function disableApp(
?string $appName,
?string $xRequestId = ''
):array {
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* checks if an app is currently enabled
*
* @param string|null $appName
* @param string|null $xRequestId
*
* @return bool true if enabled, false if disabled or nonexistent
* @throws Exception
*/
public static function isAppEnabled(
?string $appName,
?string $xRequestId = ''
):bool {
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
return \strtolower(\substr($result['stdOut'], 0, 7)) === 'enabled';
}
/**
* lists app status (enabled or disabled)
*
* @param string|null $appName
* @param string|null $xRequestId
*
* @return bool true if the app needed to be enabled, false otherwise
* @throws Exception
*/
public static function enableAppIfNotEnabled(
?string $appName,
?string $xRequestId = ''
):bool {
if (!self::isAppEnabled($appName, $xRequestId)) {
self::enableApp(
$appName,
$xRequestId
);
return true;
}
return false;
}
/**
* Runs a list of occ commands at once
*
* @param array|null $commands
* @param string|null $xRequestId
* @param string|null $adminUsername
* @param string|null $adminPassword
* @param string|null $baseUrl
*
* @return array
* @throws GuzzleException
* @throws Exception
*/
public static function runBulkOcc(
?array $commands,
?string $xRequestId = '',
?string $adminUsername = null,
?string $adminPassword = null,
?string $baseUrl = null
):array {
return [];
}
/**
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $xRequestId
*
* @return ResponseInterface|null
* @throws GuzzleException
*/
public static function resetOpcache(
?string $baseUrl,
?string $user,
?string $password,
?string $xRequestId = ''
):?ResponseInterface {
try {
return OcsApiHelper::sendRequest(
$baseUrl,
$user,
$password,
"DELETE",
"/apps/testing/api/v1/opcache",
$xRequestId
);
} catch (ServerException $e) {
echo "could not reset opcache, if tests fail try to set " .
"'opcache.revalidate_freq=0' in the php.ini file\n";
}
return null;
}
/**
* Create local storage mount
*
* @param string|null $mount (name of local storage mount)
* @param string|null $xRequestId
*
* @return string[] associated array with "code", "stdOut", "stdErr", "storageId"
* @throws GuzzleException
*/
public static function createLocalStorageMount(
?string $mount,
?string $xRequestId = ''
):array {
$mountPath = TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER . "/$mount";
SetupHelper::mkDirOnServer(
$mountPath,
$xRequestId
);
// files_external:create requires absolute path
$serverRoot = self::getServerRoot(
self::$baseUrl,
self::$adminUsername,
self::$adminPassword,
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
// stdOut should have a string like "Storage created with id 65"
$storageIdWords = \explode(" ", \trim($result['stdOut']));
if (\array_key_exists(4, $storageIdWords)) {
$result['storageId'] = (int)$storageIdWords[4];
} else {
// presumably something went wrong with the files_external:create command
// so return "unknown" to the caller. The result array has the command exit
// code and stdErr output etc., so the caller can process what it likes
// of that information to work out what went wrong.
$result['storageId'] = "unknown";
}
return $result;
}
/**
* Get a system config setting, including status code, output and standard
* error output.
*
* @param string|null $key
* @param string|null $xRequestId
* @param string|null $output e.g. json
* @param string|null $adminUsername
* @param string|null $adminPassword
* @param string|null $baseUrl
* @param string|null $ocPath
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws GuzzleException
*/
public static function getSystemConfig(
?string $key,
?string $xRequestId = '',
?string $output = null,
?string $adminUsername = null,
?string $adminPassword = null,
?string $baseUrl = null,
?string $ocPath = null
):array {
$args = [];
$args[] = 'config:system:get';
$args[] = $key;
if ($output !== null) {
$args[] = '--output';
$args[] = $output;
}
$args[] = '--no-ansi';
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* Set a system config setting
*
* @param string|null $key
* @param string|null $value
* @param string|null $xRequestId
* @param string|null $type e.g. boolean or json
* @param string|null $output e.g. json
* @param string|null $adminUsername
* @param string|null $adminPassword
* @param string|null $baseUrl
* @param string|null $ocPath
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws GuzzleException
*/
public static function setSystemConfig(
?string $key,
?string $value,
?string $xRequestId = '',
?string $type = null,
?string $output = null,
?string $adminUsername = null,
?string $adminPassword = null,
?string $baseUrl = null,
?string $ocPath = null
):array {
$args = [];
$args[] = 'config:system:set';
$args[] = $key;
$args[] = '--value';
$args[] = $value;
if ($type !== null) {
$args[] = '--type';
$args[] = $type;
}
if ($output !== null) {
$args[] = '--output';
$args[] = $output;
}
$args[] = '--no-ansi';
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* Get the value of a system config setting
*
* @param string|null $key
* @param string|null $xRequestId
* @param string|null $output e.g. json
* @param string|null $adminUsername
* @param string|null $adminPassword
* @param string|null $baseUrl
* @param string|null $ocPath
*
* @return string
* @throws GuzzleException if parameters have not been provided yet or the testing app is not enabled
*/
public static function getSystemConfigValue(
?string $key,
?string $xRequestId = '',
?string $output = null,
?string $adminUsername = null,
?string $adminPassword = null,
?string $baseUrl = null,
?string $ocPath = null
):string {
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return self::getSystemConfig(
$key,
$xRequestId,
$output,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
)['stdOut'];
}
/**
* Finds all lines containing the given text
*
@@ -966,36 +510,4 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
}
return $results;
}
/**
* Delete a system config setting
*
* @param string|null $key
* @param string|null $xRequestId
* @param string|null $adminUsername
* @param string|null $adminPassword
* @param string|null $baseUrl
* @param string|null $ocPath
*
* @return string[] associated array with "code", "stdOut", "stdErr"
* @throws GuzzleException if parameters have not been provided yet or the testing app is not enabled
*/
public static function deleteSystemConfig(
?string $key,
?string $xRequestId = '',
?string $adminUsername = null,
?string $adminPassword = null,
?string $baseUrl = null,
?string $ocPath = null
):array {
$args = [];
$args[] = 'config:system:delete';
$args[] = $key;
$args[] = '--no-ansi';
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
}

View File

@@ -1099,12 +1099,7 @@ class AuthContext implements Context {
} else {
$value = 'false';
}
$occStatus = SetupHelper::setSystemConfig(
'token_auth_enforced',
$value,
$this->featureContext->getStepLineRef(),
'boolean'
);
$occStatus = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($occStatus['code'] !== "0") {
throw new \Exception("setSystemConfig token_auth_enforced returned error code " . $occStatus['code']);
}
@@ -1135,22 +1130,6 @@ class AuthContext implements Context {
*/
public function deleteTokenAuthEnforcedAfterScenario():void {
if ($this->tokenAuthHasBeenSet) {
if ($this->tokenAuthHasBeenSetTo === 'true') {
// Because token auth is enforced, we have to use a token
// (app password) as the password to send to the testing app
// so it will authenticate us.
$appTokenForOccCommand = $this->generateAuthTokenForAdmin();
} else {
$appTokenForOccCommand = null;
}
SetupHelper::deleteSystemConfig(
'token_auth_enforced',
$this->featureContext->getStepLineRef(),
null,
$appTokenForOccCommand,
null,
null
);
$this->tokenAuthHasBeenSet = false;
$this->tokenAuthHasBeenSetTo = '';
}

View File

@@ -1150,16 +1150,6 @@ class FeatureContext extends BehatVariablesContext {
return $storageId;
}
/**
* @param string $storageName
* @param integer $storageId
*
* @return void
*/
public function addStorageId(string $storageName, int $storageId): void {
$this->storageIds[$storageId] = $storageName;
}
/**
* @param integer $storageId
*
@@ -1319,60 +1309,6 @@ class FeatureContext extends BehatVariablesContext {
return $this->federatedServerExists;
}
/**
* disable CSRF
*
* @return string the previous setting of csrf.disabled
* @throws Exception
*/
public function disableCSRF(): string {
return $this->setCSRFDotDisabled('true');
}
/**
* enable CSRF
*
* @return string the previous setting of csrf.disabled
* @throws Exception
*/
public function enableCSRF(): string {
return $this->setCSRFDotDisabled('false');
}
/**
* set csrf.disabled
*
* @param string $setting "true", "false" or "" to delete the setting
*
* @return string the previous setting of csrf.disabled
* @throws Exception
*/
public function setCSRFDotDisabled(string $setting): string {
$oldCSRFSetting = SetupHelper::getSystemConfigValue(
'csrf.disabled',
$this->getStepLineRef()
);
if ($setting === "") {
SetupHelper::deleteSystemConfig(
'csrf.disabled',
$this->getStepLineRef()
);
} elseif (($setting === 'true') || ($setting === 'false')) {
SetupHelper::setSystemConfig(
'csrf.disabled',
$setting,
$this->getStepLineRef(),
'boolean'
);
} else {
throw new \http\Exception\InvalidArgumentException(
'setting must be "true", "false" or ""'
);
}
return \trim($oldCSRFSetting);
}
/**
* Parses the response as XML
*
@@ -3720,28 +3656,6 @@ class FeatureContext extends BehatVariablesContext {
}
}
/**
* @BeforeScenario @local_storage
*
* @return void
* @throws Exception
*/
public function setupLocalStorageBefore(): void {
$storageName = "local_storage";
$result = SetupHelper::createLocalStorageMount(
$storageName,
$this->getStepLineRef()
);
$storageId = $result['storageId'];
if (!is_numeric($storageId)) {
throw new Exception(
__METHOD__ . " storageId '$storageId' is not numeric"
);
}
$this->addStorageId($storageName, (int)$storageId);
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
/**
* @AfterScenario
*
@@ -3768,45 +3682,6 @@ class FeatureContext extends BehatVariablesContext {
}
}
/**
* deletes all created storages
*
* @return void
* @throws Exception
*/
public function deleteAllStorages(): void {
$allStorageIds = \array_keys($this->getStorageIds());
foreach ($allStorageIds as $storageId) {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
$this->storageIds = [];
}
/**
* @AfterScenario @local_storage
*
* @return void
* @throws Exception
*/
public function removeLocalStorageAfter(): void {
$this->removeExternalStorage();
$this->removeTemporaryStorageOnServerAfter();
}
/**
* This will remove test created external mount points
*
* @AfterScenario @external_storage
*
* @return void
* @throws Exception
*/
public function removeExternalStorage(): void {
if ($this->getStorageIds() !== null) {
$this->deleteAllStorages();
}
}
/**
* @BeforeScenario @temporary_storage_on_server
*

View File

@@ -845,27 +845,6 @@ trait Provisioning {
}
}
/**
* Sets back old settings
*
* @return void
* @throws Exception
*/
public function resetOldLdapConfig():void {
$toDeleteLdapConfig = $this->getToDeleteLdapConfigs();
foreach ($toDeleteLdapConfig as $configId) {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
foreach ($this->oldLdapConfig as $configId => $settings) {
foreach ($settings as $configKey => $configValue) {
$this->setLdapSetting($configId, $configKey, $configValue);
}
}
foreach ($this->toDeleteDNs as $dn) {
$this->getLdap()->delete($dn, true);
}
}
/**
* Manually add skeleton files for a single user on OCIS and reva systems
*
@@ -3130,20 +3109,6 @@ trait Provisioning {
$user = \trim($user);
$method = \trim(\strtolower($method));
switch ($method) {
case "occ":
$result = SetupHelper::createUser(
$user,
$password,
$this->getStepLineRef(),
$displayName,
$email
);
if ($result["code"] !== "0") {
throw new Exception(
__METHOD__ . " could not create user. {$result['stdOut']} {$result['stdErr']}"
);
}
break;
case "api":
case "ldap":
$settings = [];
@@ -3611,18 +3576,6 @@ trait Provisioning {
$this->pushToLastStatusCodesArrays();
}
break;
case "occ":
$result = SetupHelper::addUserToGroup(
$group,
$user,
$this->getStepLineRef()
);
if ($checkResult && ($result["code"] !== "0")) {
throw new Exception(
"could not add user to group. {$result['stdOut']} {$result['stdErr']}"
);
}
break;
case "ldap":
try {
$this->addUserToLdapGroup(
@@ -3872,19 +3825,6 @@ trait Provisioning {
);
}
break;
case "occ":
$result = SetupHelper::createGroup(
$group,
$this->getStepLineRef()
);
if ($result["code"] == 0) {
$groupCanBeDeleted = true;
} else {
throw new Exception(
"could not create group '$group'. {$result['stdOut']} {$result['stdErr']}"
);
}
break;
case "ldap":
try {
$this->createLdapGroup($group);

View File

@@ -1022,7 +1022,7 @@ trait Sharing {
$this->shareFields
);
$bodyRows = $body->getRowsHash();
if (\array_key_exists('password', $bodyRows)) {
$bodyRows['password'] = $this->getActualPassword($bodyRows['password']);
}
@@ -3335,19 +3335,6 @@ trait Sharing {
$dataResponded = $this->getAllSharesSharedWithUser($user);
$shareId = null;
foreach ($dataResponded as $shareElement) {
$shareFolder = \trim(
SetupHelper::getSystemConfigValue('share_folder', $this->getStepLineRef())
);
if ($shareFolder) {
$shareFolder = \ltrim($shareFolder, '/');
}
// Add share folder to share path if given
if ($shareFolder && !(strpos($share, "/$shareFolder") === 0)) {
$share = '/' . $shareFolder . $share;
}
// SharingHelper::SHARE_STATES has the mapping between the words for share states
// like "accepted", "pending",... and the integer constants 0, 1,... that are in
// the "state" field of the share data.

View File

@@ -5393,27 +5393,6 @@ trait WebDav {
}
}
/**
* reset settings if they were set in the scenario
*
* @AfterScenario
*
* @return void
* @throws Exception
*/
public function resetPreviousSettingsAfterScenario():void {
if ($this->previousAsyncSetting === "") {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
} elseif ($this->previousAsyncSetting !== null) {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
if ($this->previousDavSlowdownSetting === "") {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
} elseif ($this->previousDavSlowdownSetting !== null) {
['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
}
/**
* @Given /^the administrator has (enabled|disabled) the file version storage feature/
*