From 8b93c1b8f6e14f03fee6a5ddfed6314cd412b2e2 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Thu, 16 Mar 2023 16:39:02 +0545 Subject: [PATCH] Removed occ related codes --- tests/TestHelpers/SetupHelper.php | 29 +--- .../features/bootstrap/AuthContext.php | 59 -------- .../features/bootstrap/FeatureContext.php | 134 ------------------ .../features/bootstrap/Provisioning.php | 58 -------- .../acceptance/features/bootstrap/WebDav.php | 46 ------ .../webDavDELETEAuth.feature | 52 ------- 6 files changed, 1 insertion(+), 377 deletions(-) diff --git a/tests/TestHelpers/SetupHelper.php b/tests/TestHelpers/SetupHelper.php index 27f8f9b4f..6a9778b2b 100644 --- a/tests/TestHelpers/SetupHelper.php +++ b/tests/TestHelpers/SetupHelper.php @@ -464,16 +464,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert { "readSkeletonFile" ); - //find the absolute path of the currently set skeletondirectory - $occResponse = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]; - if ((int) $occResponse['code'] !== 0) { - throw new \Exception( - "could not get current skeletondirectory. " . $occResponse['stdErr'] - ); - } - $skeletonRoot = \trim($occResponse['stdOut']); - - $fileInSkeletonFolder = \rawurlencode("$skeletonRoot/$fileInSkeletonFolder"); + $fileInSkeletonFolder = \rawurlencode("/$fileInSkeletonFolder"); $response = OcsApiHelper::sendRequest( $baseUrl, $adminUsername, @@ -492,22 +483,4 @@ class SetupHelper extends \PHPUnit\Framework\Assert { $localContent = \urldecode($localContent); return $localContent; } - - /** - * Finds all lines containing the given text - * - * @param string|null $input stdout or stderr output - * @param string|null $text text to search for - * - * @return array array of lines that matched - */ - public static function findLines(?string $input, ?string $text):array { - $results = []; - foreach (\explode("\n", $input) as $line) { - if (\strpos($line, $text) !== false) { - $results[] = $line; - } - } - return $results; - } } diff --git a/tests/acceptance/features/bootstrap/AuthContext.php b/tests/acceptance/features/bootstrap/AuthContext.php index 91bb17cac..726d48a4b 100644 --- a/tests/acceptance/features/bootstrap/AuthContext.php +++ b/tests/acceptance/features/bootstrap/AuthContext.php @@ -44,28 +44,11 @@ class AuthContext implements Context { */ private $appTokens; - /** - * @var boolean - */ - private $tokenAuthHasBeenSet = false; - /** * @var FeatureContext */ private $featureContext; - /** - * @var string 'true' or 'false' or '' - */ - private $tokenAuthHasBeenSetTo = ''; - - /** - * @return string - */ - public function getTokenAuthHasBeenSetTo():string { - return $this->tokenAuthHasBeenSetTo; - } - /** * get the client token that was last generated * app acceptance tests that have their own step code may need to use this @@ -1083,32 +1066,6 @@ class AuthContext implements Context { $this->aNewBrowserSessionForHasBeenStarted($admin); } - /** - * @When /^the administrator (enforces|does not enforce)\s?token auth$/ - * @Given /^token auth has (not|)\s?been enforced$/ - * - * @param string $hasOrNot - * - * @return void - * @throws Exception - */ - public function tokenAuthHasBeenEnforced(string $hasOrNot):void { - $enforce = (($hasOrNot !== "not") && ($hasOrNot !== "does not enforce")); - if ($enforce) { - $value = 'true'; - } else { - $value = 'false'; - } - $occStatus = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]; - if ($occStatus['code'] !== "0") { - throw new \Exception("setSystemConfig token_auth_enforced returned error code " . $occStatus['code']); - } - - // Remember that we set this value, so it can be removed after the scenario - $this->tokenAuthHasBeenSet = true; - $this->tokenAuthHasBeenSetTo = $value; - } - /** * * @return string @@ -1119,22 +1076,6 @@ class AuthContext implements Context { return $this->appToken; } - /** - * delete token_auth_enforced if it was set in the scenario - * - * @AfterScenario - * - * @return void - * @throws Exception - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function deleteTokenAuthEnforcedAfterScenario():void { - if ($this->tokenAuthHasBeenSet) { - $this->tokenAuthHasBeenSet = false; - $this->tokenAuthHasBeenSetTo = ''; - } - } - /** * @When user :user requests :endpoint with :method without retrying * diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 61505bde5..7b36185db 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -301,29 +301,11 @@ class FeatureContext extends BehatVariablesContext { */ public $appConfigurationContext; - /** - * @var array saved configuration of the system before test runs as reported - * by occ config:list - */ - private $savedConfigList = []; - /** * @var array */ private $initialTrustedServer; - /** - * @var int return code of last command - */ - private $occLastCode; - /** - * @var string stdout of last command - */ - private $lastStdOut; - /** - * @var string stderr of last command - */ - private $lastStdErr; /** * The codes are stored as strings, even though they are numbers * @@ -379,22 +361,6 @@ class FeatureContext extends BehatVariablesContext { return $this->oCSelector; } - /** - * @return void - */ - public function resetOccLastCode(): void { - $this->occLastCode = null; - } - - /** - * @param int $statusCode - * - * @return void - */ - public function setOccLastCode(?int $statusCode = null): void { - $this->occLastCode = $statusCode; - } - /** * @param string|null $httpStatusCode * @@ -1057,47 +1023,6 @@ class FeatureContext extends BehatVariablesContext { return $this->stepLineRef; } - /** - * get the exit status of the last occ command - * app acceptance tests that have their own step code may need to process this - * - * @return int exit status code of the last occ command - */ - public function getExitStatusCodeOfOccCommand(): ?int { - return $this->occLastCode; - } - - /** - * get the normal output of the last occ command - * app acceptance tests that have their own step code may need to process this - * - * @return string normal output of the last occ command - */ - public function getStdOutOfOccCommand(): string { - return $this->lastStdOut; - } - - /** - * set the normal output of the last occ command - * - * @param string $stdOut - * - * @return void - */ - public function setStdOutOfOccCommand(string $stdOut): void { - $this->lastStdOut = $stdOut; - } - - /** - * get the error output of the last occ command - * app acceptance tests that have their own step code may need to process this - * - * @return string error output of the last occ command - */ - public function getStdErrOfOccCommand(): string { - return $this->lastStdErr; - } - /** * returns the base URL without any sub-path e.g. http://localhost:8080 * of the base URL http://localhost:8080/owncloud @@ -2498,25 +2423,6 @@ class FeatureContext extends BehatVariablesContext { $this->setResponse($response); } - /** - * @Given the administrator has created a file :path in temporary storage with the last exported content using the testing API - * - * @param string $path - * - * @return void - * @throws Exception - */ - public function theAdministratorHasCreatedAFileInTemporaryStorageWithLastExportedContent( - string $path - ): void { - $commandOutput = $this->getStdOutOfOccCommand(); - $this->copyContentToFileInTemporaryStorageOnSystemUnderTest($path, $commandOutput); - $this->theFileWithContentShouldExistInTheServerRoot( - TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER . "/$path", - $commandOutput - ); - } - /** * @Given the administrator has created file :path with content :content in local storage :mountPoint * @@ -3944,46 +3850,6 @@ class FeatureContext extends BehatVariablesContext { } } - /** - * Find exception texts in stderr - * - * @return array of exception texts - */ - public function findExceptions(): array { - $exceptions = []; - $captureNext = false; - // the exception text usually appears after an "[Exception]" row - foreach (\explode("\n", $this->lastStdErr) as $line) { - if (\preg_match('/\[Exception\]/', $line)) { - $captureNext = true; - continue; - } - if ($captureNext) { - $exceptions[] = \trim($line); - $captureNext = false; - } - } - - return $exceptions; - } - - /** - * remember the result of the last occ command - * - * @param string[] $result associated array with "code", "stdOut", "stdErr" - * - * @return void - */ - public function setResultOfOccCommand(array $result): void { - Assert::assertIsArray($result); - Assert::assertArrayHasKey('code', $result); - Assert::assertArrayHasKey('stdOut', $result); - Assert::assertArrayHasKey('stdErr', $result); - $this->occLastCode = (int)$result['code']; - $this->lastStdOut = $result['stdOut']; - $this->lastStdErr = $result['stdErr']; - } - /** * @param string $sourceUser * @param string $targetUser diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 396ca1d12..34a31f867 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -493,7 +493,6 @@ trait Provisioning { */ public function userHasBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(string $user):void { $this->userHasBeenCreatedWithDefaultAttributes($user); - $this->resetOccLastCode(); } /** @@ -757,59 +756,6 @@ trait Provisioning { $this->ldapCreatedGroups[] = $group; } - /** - * - * @param string $configId - * @param string $configKey - * @param string $configValue - * - * @return void - * @throws Exception - */ - public function setLdapSetting(string $configId, string $configKey, string $configValue):void { - if ($configValue === "") { - $configValue = "''"; - } - $substitutions = [ - [ - "code" => "%ldap_host_without_scheme%", - "function" => [ - $this, - "getLdapHostWithoutScheme" - ], - "parameter" => [] - ], - [ - "code" => "%ldap_host%", - "function" => [ - $this, - "getLdapHost" - ], - "parameter" => [] - ], - [ - "code" => "%ldap_port%", - "function" => [ - $this, - "getLdapPort" - ], - "parameter" => [] - ] - ]; - $configValue = $this->substituteInLineCodes( - $configValue, - null, - [], - $substitutions - ); - $occResult = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]; - if ($occResult['code'] !== "0") { - throw new Exception( - __METHOD__ . " could not set LDAP setting " . $occResult['stdErr'] - ); - } - } - /** * deletes LDAP users|groups created during test * @@ -5545,8 +5491,6 @@ trait Provisioning { * @throws Exception */ public function afterScenario():void { - $this->waitForDavRequestsToFinish(); - if ($this->someUsersHaveBeenCreated()) { foreach ($this->getCreatedUsers() as $user) { OcisHelper::deleteRevaUserData($user["actualUsername"]); @@ -5586,7 +5530,6 @@ trait Provisioning { * @throws Exception */ public function cleanupDatabaseUsers():void { - $this->authContext->deleteTokenAuthEnforcedAfterScenario(); $previousServer = $this->currentServer; $this->usingServer('LOCAL'); foreach ($this->createdUsers as $user => $userData) { @@ -5605,7 +5548,6 @@ trait Provisioning { * @throws Exception */ public function cleanupDatabaseGroups():void { - $this->authContext->deleteTokenAuthEnforcedAfterScenario(); $previousServer = $this->currentServer; $this->usingServer('LOCAL'); foreach ($this->createdGroups as $group => $groupData) { diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index c31755a06..d38a84e7b 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -79,13 +79,6 @@ trait WebDav { private $previousAsyncSetting = null; - private $previousDavSlowdownSetting = null; - - /** - * @var int - */ - private $currentDavSlowdownSettingSeconds = 0; - /** * response content parsed from XML to an array * @@ -573,45 +566,6 @@ trait WebDav { $this->httpRequestTimeout = (int) $timeout; } - /** - * @Given the :method DAV requests are slowed down by :seconds seconds - * - * @param string $method - * @param int $seconds - * - * @return void - * @throws Exception - */ - public function slowdownDavRequests(string $method, int $seconds):void { - if ($this->previousDavSlowdownSetting === null) { - $previousDavSlowdownSetting = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']; - $this->previousDavSlowdownSetting = \trim($previousDavSlowdownSetting); - } - OcsApiHelper::sendRequest( - $this->getBaseUrl(), - $this->getAdminUsername(), - $this->getAdminPassword(), - "PUT", - "/apps/testing/api/v1/davslowdown/$method/$seconds", - $this->getStepLineRef() - ); - $this->currentDavSlowdownSettingSeconds = $seconds; - } - - /** - * Wait for possible slowed-down DAV requests to finish - * - * @return void - */ - public function waitForDavRequestsToFinish():void { - if ($this->currentDavSlowdownSettingSeconds > 0) { - // There could be a slowed-down request still happening on the server - // Wait just-in-case so that we do not accidentally have an effect on - // the next scenario. - \sleep($this->currentDavSlowdownSettingSeconds); - } - } - /** * @param string $user * @param string $fileDestination diff --git a/tests/acceptance/features/coreApiAuthWebDav/webDavDELETEAuth.feature b/tests/acceptance/features/coreApiAuthWebDav/webDavDELETEAuth.feature index c905a7180..d8ab2d1b5 100644 --- a/tests/acceptance/features/coreApiAuthWebDav/webDavDELETEAuth.feature +++ b/tests/acceptance/features/coreApiAuthWebDav/webDavDELETEAuth.feature @@ -131,58 +131,6 @@ Feature: delete file/folder | /remote.php/dav/spaces/%spaceid%/PARENT/parent.txt | Then the HTTP status code of responses on all endpoints should be "401" - @issue-ocis-reva-60 - Scenario: send DELETE requests to webDav endpoints using token authentication should not work - Given token auth has been enforced - And a new browser session for "Alice" has been started - And the user has generated a new app password named "my-client" - When the user requests these endpoints with "DELETE" using the generated app password about user "Alice" - | endpoint | - | /remote.php/webdav/textfile0.txt | - | /remote.php/dav/files/%username%/textfile0.txt | - | /remote.php/webdav/PARENT | - | /remote.php/dav/files/%username%/PARENT | - | /remote.php/dav/files/%username%/PARENT/parent.txt | - Then the HTTP status code of responses on all endpoints should be "401" - - @issue-ocis-reva-60 @skipOnOcV10 @personalSpace - Scenario: send DELETE requests to webDav endpoints using token authentication should not work using the spaces WebDAV API - Given token auth has been enforced - And a new browser session for "Alice" has been started - And the user has generated a new app password named "my-client" - When the user requests these endpoints with "DELETE" using the generated app password about user "Alice" - | endpoint | - | /remote.php/dav/spaces/%spaceid%/textfile0.txt | - | /remote.php/dav/spaces/%spaceid%/PARENT | - | /remote.php/dav/spaces/%spaceid%/PARENT/parent.txt | - Then the HTTP status code of responses on all endpoints should be "401" - - @issue-ocis-reva-60 - Scenario: send DELETE requests to webDav endpoints using app password token as password - Given token auth has been enforced - And a new browser session for "Alice" has been started - And the user has generated a new app password named "my-client" - When the user "Alice" requests these endpoints with "DELETE" using basic auth and generated app password about user "Alice" - | endpoint | - | /remote.php/webdav/textfile0.txt | - | /remote.php/dav/files/%username%/textfile1.txt | - | /remote.php/dav/files/%username%/PARENT/parent.txt | - | /remote.php/webdav/PARENT | - | /remote.php/dav/files/%username%/FOLDER | - Then the HTTP status code of responses on all endpoints should be "204" - - @issue-ocis-reva-60 @skipOnOcV10 @personalSpace - Scenario: send DELETE requests to webDav endpoints using app password token as password using the spaces WebDAV API - Given token auth has been enforced - And a new browser session for "Alice" has been started - And the user has generated a new app password named "my-client" - When the user "Alice" requests these endpoints with "DELETE" using basic auth and generated app password about user "Alice" - | endpoint | - | /remote.php/dav/spaces/%spaceid%/textfile0.txt | - | /remote.php/dav/spaces/%spaceid%/PARENT | - | /remote.php/dav/spaces/%spaceid%/PARENT/parent.txt | - Then the HTTP status code of responses on all endpoints should be "204" - @skipOnOcV10 Scenario: send DELETE requests to webDav endpoints with body as normal user When user "Alice" requests these endpoints with "DELETE" including body "doesnotmatter" about user "Alice"