Removed method isTestingOnOcisOrReva, and refactored its use

This commit is contained in:
Prarup Gurung
2023-03-02 10:43:37 +05:45
parent d9092d7e17
commit fab9bfc734
11 changed files with 147 additions and 1063 deletions
@@ -73,12 +73,7 @@ class AppConfigurationContext implements Context {
public function serverParameterHasBeenSetTo(string $parameter, string $app, string $value):void {
// The capturing group of the regex always includes the quotes at each
// end of the captured string, so trim them.
if (\TestHelpers\OcisHelper::isTestingOnOcisOrReva()) {
return;
}
$value = \trim($value, $value[0]);
$this->modifyAppConfig($app, $parameter, $value);
$this->featureContext->clearStatusCodeArrays();
return;
}
/**
@@ -1593,11 +1593,7 @@ class FeatureContext extends BehatVariablesContext {
$urlEnding = \substr($url, \strlen($this->getBaseUrl() . '/'));
}
if (OcisHelper::isTestingOnOcisOrReva()) {
$matchResult = \preg_match("%^(#/)?s/([a-zA-Z0-9]{15})$%", $urlEnding);
} else {
$matchResult = \preg_match("%^(index.php/)?s/([a-zA-Z0-9]{15})$%", $urlEnding);
}
$matchResult = \preg_match("%^(#/)?s/([a-zA-Z0-9]{15})$%", $urlEnding);
// preg_match returns (int) 1 for a match, we want to return a boolean.
if ($matchResult === 1) {
@@ -3915,24 +3911,6 @@ class FeatureContext extends BehatVariablesContext {
Assert::assertEquals("200", $response->getStatusCode());
}
/**
* After Scenario. clear file locks
*
* @AfterScenario
*
* @return void
* @throws Exception
*/
public function clearFileLocks(): void {
if (!OcisHelper::isTestingOnOcisOrReva()) {
$this->authContext->deleteTokenAuthEnforcedAfterScenario();
$this->clearFileLocksForServer($this->getBaseUrl());
if ($this->remoteBaseUrl !== $this->localBaseUrl) {
$this->clearFileLocksForServer($this->getRemoteBaseUrl());
}
}
}
/**
* @AfterScenario
*
@@ -3956,49 +3934,7 @@ class FeatureContext extends BehatVariablesContext {
* @throws Exception
*/
public static function useBigFileIDs(BeforeSuiteScope $scope): void {
if (OcisHelper::isTestingOnOcisOrReva()) {
return;
}
$fullUrl = \getenv('TEST_SERVER_URL');
if (\substr($fullUrl, -1) !== '/') {
$fullUrl .= '/';
}
$fullUrl .= "ocs/v1.php/apps/testing/api/v1/increasefileid";
$suiteSettingsContexts = $scope->getSuite()->getSettings()['contexts'];
$adminUsername = null;
$adminPassword = null;
foreach ($suiteSettingsContexts as $context) {
if (isset($context[__CLASS__])) {
$adminUsername = $context[__CLASS__]['adminUsername'];
$adminPassword = $context[__CLASS__]['adminPassword'];
break;
}
}
// get the admin username from the environment (if defined)
$adminUsernameFromEnvironment = self::getAdminUsernameFromEnvironment();
if ($adminUsernameFromEnvironment !== false) {
$adminUsername = $adminUsernameFromEnvironment;
}
// get the admin password from the environment (if defined)
$adminPasswordFromEnvironment = self::getAdminPasswordFromEnvironment();
if ($adminPasswordFromEnvironment !== false) {
$adminPassword = $adminPasswordFromEnvironment;
}
if (($adminUsername === null) || ($adminPassword === null)) {
throw new Exception(
"Could not find adminUsername and/or adminPassword in useBigFileIDs"
);
}
HttpRequestHelper::post(
$fullUrl,
'',
$adminUsername,
$adminPassword
);
return;
}
/**
@@ -4349,25 +4285,6 @@ class FeatureContext extends BehatVariablesContext {
}
}
/**
*
* @return void
* @throws Exception
*/
public function restoreParametersAfterScenario(): void {
if (!OcisHelper::isTestingOnOcisOrReva()) {
$this->authContext->deleteTokenAuthEnforcedAfterScenario();
$user = $this->getCurrentUser();
$this->setCurrentUser($this->getAdminUsername());
$this->runFunctionOnEveryServer(
function ($server) {
$this->restoreParameters($server);
}
);
$this->setCurrentUser($user);
}
}
/**
* Get the array of trusted servers in format ["url" => "id"]
*
@@ -4440,37 +4357,6 @@ class FeatureContext extends BehatVariablesContext {
return $body;
}
/**
* @BeforeScenario
*
* @return void
* @throws Exception
*/
public function prepareParametersBeforeScenario(): void {
if (!OcisHelper::isTestingOnOcisOrReva()) {
$user = $this->getCurrentUser();
$this->setCurrentUser($this->getAdminUsername());
$previousServer = $this->getCurrentServer();
foreach (['LOCAL', 'REMOTE'] as $server) {
if (($server === 'LOCAL') || $this->federatedServerExists()) {
$this->usingServer($server);
$this->resetAppConfigs();
$result = SetupHelper::runOcc(
['config:list', '--private'],
$this->getStepLineRef(),
$this->getAdminUsername(),
$this->getAdminPassword(),
$this->getBaseUrl(),
$this->getOcPath()
);
$this->savedConfigList[$server] = \json_decode($result['stdOut'], true);
}
}
$this->usingServer($previousServer);
$this->setCurrentUser($user);
}
}
/**
* Before Scenario to Save trusted Servers
*
@@ -65,86 +65,9 @@ class LoggingContext implements Context {
int $ignoredLines = 0,
?TableNode $expectedLogEntries = null
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
$ignoredLines = (int) $ignoredLines;
//-1 because getRows gives also the header
$linesToRead = \count($expectedLogEntries->getRows()) - 1 + $ignoredLines;
$logLines = LoggingHelper::getLogFileContent(
$this->featureContext->getBaseUrl(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getStepLineRef(),
$linesToRead
);
$lineNo = 0;
foreach ($expectedLogEntries as $expectedLogEntry) {
$logEntry = \json_decode($logLines[$lineNo], true);
if ($logEntry === null) {
throw new Exception("the log line :\n{$logLines[$lineNo]} is not valid JSON");
}
foreach (\array_keys($expectedLogEntry) as $attribute) {
if ($comparingMode === 'matching') {
$expectedLogEntry[$attribute]
= $this->featureContext->substituteInLineCodes(
$expectedLogEntry[$attribute],
null,
['preg_quote' => ['/']]
);
} else {
$expectedLogEntry[$attribute]
= $this->featureContext->substituteInLineCodes(
$expectedLogEntry[$attribute]
);
}
if ($expectedLogEntry[$attribute] !== "") {
Assert::assertArrayHasKey(
$attribute,
$logEntry,
"could not find attribute: '$attribute' in log entry: '{$logLines[$lineNo]}'"
);
$message = "log entry:\n{$logLines[$lineNo]}\n";
if (!\is_string($logEntry[$attribute])) {
$logEntry[$attribute] = \json_encode(
$logEntry[$attribute],
JSON_UNESCAPED_SLASHES
);
}
if ($comparingMode === 'with') {
Assert::assertEquals(
$expectedLogEntry[$attribute],
$logEntry[$attribute],
$message
);
} elseif ($comparingMode === 'containing') {
Assert::assertStringContainsString(
$expectedLogEntry[$attribute],
$logEntry[$attribute],
$message
);
} elseif ($comparingMode === 'matching') {
Assert::assertMatchesRegularExpression(
$expectedLogEntry[$attribute],
$logEntry[$attribute],
$message
);
} else {
throw new \InvalidArgumentException(
"$comparingMode is not a valid mode"
);
}
}
}
$lineNo++;
if (($lineNo + $ignoredLines) >= $linesToRead) {
break;
}
}
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
/**
@@ -279,90 +202,9 @@ class LoggingContext implements Context {
TableNode $expectedLogEntries,
bool $regexCompare = false
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
$logLines = LoggingHelper::getLogFileContent(
$this->featureContext->getBaseUrl(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getStepLineRef()
);
$expectedLogEntries = $expectedLogEntries->getHash();
foreach ($logLines as $logLine) {
$logEntry = \json_decode($logLine, true);
if ($logEntry === null) {
throw new Exception("the log line :\n{$logLine} is not valid JSON");
}
//reindex the array, we might have deleted entries
$expectedLogEntries = \array_values($expectedLogEntries);
for ($entryNo = 0; $entryNo < \count($expectedLogEntries); $entryNo++) {
$count = 0;
$expectedLogEntry = $expectedLogEntries[$entryNo];
$foundLine = true;
foreach (\array_keys($expectedLogEntry) as $attribute) {
if ($expectedLogEntry[$attribute] === "") {
//don't check empty table entries
continue;
}
if (!\array_key_exists($attribute, $logEntry)) {
//this line does not have the attribute we are looking for
$foundLine = false;
break;
}
if (!\is_string($logEntry[$attribute])) {
$logEntry[$attribute] = \json_encode(
$logEntry[$attribute],
JSON_UNESCAPED_SLASHES
);
}
if ($regexCompare === true) {
$expectedLogEntry[$attribute]
= $this->featureContext->substituteInLineCodes(
$expectedLogEntry[$attribute],
null,
['preg_quote' => ['/']]
);
$matchAttribute = \preg_match(
$expectedLogEntry[$attribute],
$logEntry[$attribute]
);
} else {
$expectedLogEntry[$attribute]
= $this->featureContext->substituteInLineCodes(
$expectedLogEntry[$attribute]
);
$matchAttribute
= ($expectedLogEntry[$attribute] === $logEntry[$attribute]);
}
if (!$matchAttribute) {
$foundLine = false;
break;
}
if ($matchAttribute and !$shouldOrNot) {
$count += 1;
Assert::assertNotEquals(
$count,
\count($expectedLogEntry),
"The entry matches"
);
}
}
if ($foundLine === true) {
unset($expectedLogEntries[$entryNo]);
}
}
}
$notFoundLines = \print_r($expectedLogEntries, true);
if ($shouldOrNot) {
Assert::assertEmpty(
$expectedLogEntries,
"could not find these expected line(s):\n $notFoundLines"
);
}
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
/**
@@ -387,50 +229,9 @@ class LoggingContext implements Context {
$withOrContaining,
TableNode $logEntriesExpectedNotToExist
):void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
$logLines = LoggingHelper::getLogFileContent(
$this->featureContext->getBaseUrl(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$this->featureContext->getStepLineRef()
);
foreach ($logLines as $logLine) {
$logEntry = \json_decode($logLine, true);
if ($logEntry === null) {
throw new Exception("the log line :\n$logLine is not valid JSON");
}
foreach ($logEntriesExpectedNotToExist as $logEntryExpectedNotToExist) {
$match = true; // start by assuming the worst, we match the unwanted log entry
foreach (\array_keys($logEntryExpectedNotToExist) as $attribute) {
$logEntryExpectedNotToExist[$attribute]
= $this->featureContext->substituteInLineCodes(
$logEntryExpectedNotToExist[$attribute]
);
if (isset($logEntry[$attribute]) && ($logEntryExpectedNotToExist[$attribute] !== "")) {
if ($withOrContaining === 'with') {
$match = ($logEntryExpectedNotToExist[$attribute] === $logEntry[$attribute]);
} else {
$match = (\strpos($logEntry[$attribute], $logEntryExpectedNotToExist[$attribute]) !== false);
}
}
if (!isset($logEntry[$attribute])) {
$match = false;
}
if (!$match) {
break;
}
}
}
Assert::assertFalse(
$match,
"found a log entry that should not be there\n$logLine\n"
);
}
// Currently we don't interact with the log file on reva or OCIS
// So skip processing this test step.
return;
}
/**
@@ -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;
}
@@ -125,7 +125,7 @@ class PublicWebDavContext implements Context {
* @return void
*/
public function deleteFileFromPublicShare(string $fileName, string $publicWebDAVAPIVersion, string $password = ""):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
$token = $this->featureContext->getLastPublicShareToken();
@@ -179,7 +179,7 @@ class PublicWebDavContext implements Context {
* @return void
*/
public function renameFileFromPublicShare(string $fileName, string $toFileName, string $publicWebDAVAPIVersion, ?string $password = ""):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
$token = $this->featureContext->getLastPublicShareToken();
@@ -720,7 +720,7 @@ class PublicWebDavContext implements Context {
string $password,
string $expectedContent
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -869,7 +869,7 @@ class PublicWebDavContext implements Context {
string $password,
string $content
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -901,7 +901,7 @@ class PublicWebDavContext implements Context {
string $password,
string $content
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -977,7 +977,7 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion,
string $password
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -1009,7 +1009,7 @@ class PublicWebDavContext implements Context {
string $password,
string $expectedHttpCode = "401"
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -1093,7 +1093,7 @@ class PublicWebDavContext implements Context {
string $expectedHttpCode
):void {
$filename = "";
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
$filename = (string)$this->featureContext->getLastPublicShareData()->data[0]->file_target;
@@ -1124,7 +1124,7 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion,
string $expectedHttpCode = null
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -1219,7 +1219,7 @@ class PublicWebDavContext implements Context {
$path = "whateverfilefortesting-$publicWebDAVAPIVersion-publicWebDAVAPI.txt";
$content = "test $publicWebDAVAPIVersion";
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
@@ -1259,7 +1259,7 @@ class PublicWebDavContext implements Context {
):void {
$content = "test $publicWebDAVAPIVersion";
$should = ($shouldOrNot !== "not");
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
} elseif ($publicWebDAVAPIVersion === "new") {
$path = $this->featureContext->getLastPublicSharePath();
@@ -1435,30 +1435,18 @@ class PublicWebDavContext implements Context {
):void {
$token = $this->featureContext->getLastPublicShareToken();
$baseUrl = $this->featureContext->getBaseUrl();
if (\TestHelpers\OcisHelper::isTestingOnOcisOrReva()) {
$mtime = \explode(" ", $mtime);
\array_pop($mtime);
$mtime = \implode(" ", $mtime);
Assert::assertStringContainsString(
$mtime,
WebDavHelper::getMtimeOfFileinPublicLinkShare(
$baseUrl,
$fileName,
$token,
$this->featureContext->getStepLineRef()
)
);
} else {
Assert::assertEquals(
$mtime,
WebDavHelper::getMtimeOfFileinPublicLinkShare(
$baseUrl,
$fileName,
$token,
$this->featureContext->getStepLineRef()
)
);
}
$mtime = \explode(" ", $mtime);
\array_pop($mtime);
$mtime = \implode(" ", $mtime);
Assert::assertStringContainsString(
$mtime,
WebDavHelper::getMtimeOfFileinPublicLinkShare(
$baseUrl,
$fileName,
$token,
$this->featureContext->getStepLineRef()
)
);
}
/**
@@ -1507,7 +1495,7 @@ class PublicWebDavContext implements Context {
array $additionalHeaders = [],
string $publicWebDAVAPIVersion = "old"
):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
$password = $this->featureContext->getActualPassword($password);
@@ -1599,7 +1587,7 @@ class PublicWebDavContext implements Context {
* @throws GuzzleException
*/
public function publicSendsRequestToLastPublicShare(string $method, string $publicWebDAVAPIVersion, ?string $password = ''):void {
if (OcisHelper::isTestingOnOcisOrReva() && $publicWebDAVAPIVersion === "old") {
if ($publicWebDAVAPIVersion === "old") {
return;
}
if ($method === "PROPFIND") {
@@ -423,17 +423,9 @@ trait Sharing {
* @return void
*/
public function autoAcceptSharesHasBeenDisabled():void {
if (OcisHelper::isTestingOnOcisOrReva()) {
// auto-accept shares is disabled by default on OCIS.
// so there is nothing to do, just return
return;
}
$this->appConfigurationContext->serverParameterHasBeenSetTo(
"shareapi_auto_accept_share",
"core",
"no"
);
// auto-accept shares is disabled by default on OCIS.
// so there is nothing to do, just return
return;
}
/**
@@ -4466,12 +4466,6 @@ trait WebDav {
// slashes need to stay
$encodedPath = \str_replace('%2F', '/', \rawurlencode($path));
// in ocis even brackets are encoded
if (OcisHelper::isTestingOnOcisOrReva()) {
return $encodedPath;
}
// do not encode '(' and ')' for oc10
$encodedPath = \str_replace('%28', '(', $encodedPath);
$encodedPath = \str_replace('%29', ')', $encodedPath);
return $encodedPath;
}