From 9f99d03fc8a8b19e26e7e48bf35f92abcca7ad94 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Wed, 15 Mar 2023 17:06:52 +0545 Subject: [PATCH] Removed LoggingContext and LoggingHelper --- tests/TestHelpers/LoggingHelper.php | 250 ------------------ tests/acceptance/config/behat-core.yml | 2 - .../features/bootstrap/LoggingContext.php | 227 ---------------- .../uploadFileUsingOldChunking.feature | 47 ---- 4 files changed, 526 deletions(-) delete mode 100644 tests/TestHelpers/LoggingHelper.php delete mode 100644 tests/acceptance/features/bootstrap/LoggingContext.php diff --git a/tests/TestHelpers/LoggingHelper.php b/tests/TestHelpers/LoggingHelper.php deleted file mode 100644 index 33f52e02f..000000000 --- a/tests/TestHelpers/LoggingHelper.php +++ /dev/null @@ -1,250 +0,0 @@ - - * @copyright Copyright (c) 2017 Artur Neumann artur@jankaritech.com - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, - * as published by the Free Software Foundation; - * either version 3 of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ -namespace TestHelpers; - -use Exception; -use InvalidArgumentException; - -/** - * Helper to read and analyze the owncloud log file - * - * @author Artur Neumann - * - */ -class LoggingHelper { - /** - * @var array - */ - public const LOG_LEVEL_ARRAY = [ - "debug", - "info", - "warning", - "error", - "fatal" - ]; - - /** - * returns the log file path local to the system ownCloud is running on - * - * @param string|null $xRequestId - * - * @return string - * @throws Exception - */ - public static function getLogFilePath( - ?string $xRequestId = '' - ):string { - // Currently we don't interact with the log file on reva or OCIS - return ""; - } - - /** - * - * @param string|null $baseUrl - * @param string|null $adminUsername - * @param string|null $adminPassword - * @param string|null $xRequestId - * @param int|null $noOfLinesToRead - * - * @return array - * @throws Exception - */ - public static function getLogFileContent( - ?string $baseUrl, - ?string $adminUsername, - ?string $adminPassword, - ?string $xRequestId = '', - ?int $noOfLinesToRead = 0 - ):array { - $result = OcsApiHelper::sendRequest( - $baseUrl, - $adminUsername, - $adminPassword, - "GET", - "/apps/testing/api/v1/logfile/$noOfLinesToRead", - $xRequestId - ); - if ($result->getStatusCode() !== 200) { - throw new Exception( - "could not get logfile content " . $result->getReasonPhrase() - ); - } - $response = HttpRequestHelper::getResponseXml($result, __METHOD__); - - $result = []; - foreach ($response->data->element as $line) { - array_push($result, (string)$line); - } - return $result; - } - - /** - * returns the currently set log level [debug, info, warning, error, fatal] - * - * @param string|null $xRequestId - * - * @return string - * @throws Exception - */ - public static function getLogLevel( - ?string $xRequestId = '' - ):string { - return "debug"; - } - - /** - * - * @param string|null $logLevel (debug|info|warning|error|fatal) - * @param string|null $xRequestId - * - * @return void - * @throws Exception - */ - public static function setLogLevel( - ?string $logLevel, - ?string $xRequestId = '' - ):void { - // Currently we can't manage log file settings on reva or OCIS - return; - } - - /** - * returns the currently set logging backend (owncloud|syslog|errorlog) - * - * @param string|null $xRequestId - * - * @return string - * @throws Exception - */ - public static function getLogBackend( - ?string $xRequestId = '' - ):string { - return "errorlog"; - } - - /** - * - * @param string|null $backend (owncloud|syslog|errorlog) - * @param string|null $xRequestId - * - * @return void - * @throws Exception - */ - public static function setLogBackend( - ?string $backend, - ?string $xRequestId = '' - ):void { - if (!\in_array($backend, ["owncloud", "syslog", "errorlog"])) { - throw new InvalidArgumentException("invalid log backend"); - } - // Currently we can't manage log file settings on reva or OCIS - return; - } - - /** - * returns the currently set logging timezone - * - * @param string|null $xRequestId - * - * @return string - * @throws Exception - */ - public static function getLogTimezone( - ?string $xRequestId = '' - ):string { - return "UTC"; - } - - /** - * - * @param string|null $timezone - * @param string|null $xRequestId - * - * @return void - * @throws Exception - */ - public static function setLogTimezone( - ?string $timezone, - ?string $xRequestId = '' - ):void { - // Currently we can't manage log file settings on reva or OCIS - return; - } - - /** - * - * @param string|null $baseUrl - * @param string|null $adminUsername - * @param string|null $adminPassword - * @param string|null $xRequestId - * - * @return void - * @throws Exception - */ - public static function clearLogFile( - ?string $baseUrl, - ?string $adminUsername, - ?string $adminPassword, - ?string $xRequestId = '' - ):void { - // Currently we don't interact with the log file on reva or OCIS - return; - } - - /** - * - * @param string|null $logLevel - * @param string|null $backend - * @param string|null $timezone - * @param string|null $xRequestId - * - * @return void - * @throws Exception - */ - public static function restoreLoggingStatus( - ?string $logLevel, - ?string $backend, - ?string $timezone, - ?string $xRequestId = '' - ):void { - // Currently we don't interact with the log file on reva or OCIS - return; - } - - /** - * returns the currently set log level, backend and timezone - * - * @param string|null $xRequestId - * - * @return array|string[] - * @throws Exception - */ - public static function getLogInfo( - ?string $xRequestId = '' - ):array { - return [ - "level" => "debug", - "backend" => "errorlog", - "timezone" => "UTC" - ]; - } -} diff --git a/tests/acceptance/config/behat-core.yml b/tests/acceptance/config/behat-core.yml index 6b066a0b3..fdb1a7b4c 100644 --- a/tests/acceptance/config/behat-core.yml +++ b/tests/acceptance/config/behat-core.yml @@ -349,7 +349,6 @@ default: context: *common_ldap_suite_context contexts: - FeatureContext: *common_feature_context_params - - LoggingContext: - PublicWebDavContext: - WebDavPropertiesContext: @@ -359,7 +358,6 @@ default: context: *common_ldap_suite_context contexts: - FeatureContext: *common_feature_context_params - - LoggingContext: - PublicWebDavContext: coreApiWebdavUploadTUS: diff --git a/tests/acceptance/features/bootstrap/LoggingContext.php b/tests/acceptance/features/bootstrap/LoggingContext.php deleted file mode 100644 index 51c467133..000000000 --- a/tests/acceptance/features/bootstrap/LoggingContext.php +++ /dev/null @@ -1,227 +0,0 @@ - - * @copyright Copyright (c) 2018 Artur Neumann artur@jankaritech.com - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, - * as published by the Free Software Foundation; - * either version 3 of the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ - -use Behat\Behat\Context\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; -use Behat\Gherkin\Node\TableNode; -use PHPUnit\Framework\Assert; -use TestHelpers\LoggingHelper; -use TestHelpers\OcisHelper; -use TestHelpers\SetupHelper; - -require_once 'bootstrap.php'; - -/** - * Context to make the Logging steps available - */ -class LoggingContext implements Context { - /** - * @var FeatureContext - */ - private $featureContext; - - private $oldLogLevel = null; - private $oldLogBackend = null; - private $oldLogTimezone = null; - - /** - * @When the owncloud log level is set to :logLevel - * - * @param string $logLevel (debug|info|warning|error|fatal) - * - * @return void - * @throws Exception - */ - public function owncloudLogLevelIsSetTo(string $logLevel):void { - LoggingHelper::setLogLevel( - $logLevel, - $this->featureContext->getStepLineRef() - ); - } - - /** - * @Given the owncloud log level has been set to :logLevel - * - * @param string $logLevel (debug|info|warning|error|fatal) - * - * @return void - * @throws Exception - */ - public function owncloudLogLevelHasBeenSetTo(string $logLevel):void { - $this->owncloudLogLevelIsSetTo($logLevel); - $logLevelArray = LoggingHelper::LOG_LEVEL_ARRAY; - $logLevelExpected = \array_search($logLevel, $logLevelArray); - $logLevelActual = \array_search( - LoggingHelper::getLogLevel( - $this->featureContext->getStepLineRef() - ), - $logLevelArray - ); - Assert::assertEquals( - $logLevelExpected, - $logLevelActual, - "The expected log level is {$logLevelExpected} but the log level has been set to {$logLevelActual}" - ); - } - - /** - * @When the owncloud log backend is set to :backend - * - * @param string $backend (owncloud|syslog|errorlog) - * - * @return void - * @throws Exception - */ - public function owncloudLogBackendIsSetTo(string $backend):void { - LoggingHelper::setLogBackend( - $backend, - $this->featureContext->getStepLineRef() - ); - } - - /** - * @Given the owncloud log backend has been set to :backend - * - * @param string $expectedBackend (owncloud|syslog|errorlog) - * - * @return void - * @throws Exception - */ - public function owncloudLogBackendHasBeenSetTo(string $expectedBackend):void { - $this->owncloudLogBackendIsSetTo($expectedBackend); - $currentBackend = LoggingHelper::getLogBackend( - $this->featureContext->getStepLineRef() - ); - Assert::assertEquals( - $expectedBackend, - $currentBackend, - "The owncloud log backend was expected to be set to {$expectedBackend} but got {$currentBackend}" - ); - } - - /** - * @When the owncloud log timezone is set to :timezone - * - * @param string $timezone - * - * @return void - * @throws Exception - */ - public function owncloudLogTimezoneIsSetTo(string $timezone):void { - LoggingHelper::setLogTimezone( - $timezone, - $this->featureContext->getStepLineRef() - ); - } - - /** - * @Given the owncloud log timezone has been set to :timezone - * - * @param string $expectedTimezone - * - * @return void - * @throws Exception - */ - public function owncloudLogTimezoneHasBeenSetTo(string $expectedTimezone):void { - $this->owncloudLogTimezoneIsSetTo($expectedTimezone); - $currentTimezone = LoggingHelper::getLogTimezone( - $this->featureContext->getStepLineRef() - ); - Assert::assertEquals( - $expectedTimezone, - $currentTimezone, - "The owncloud log timezone was expected to be set to {$expectedTimezone}, but got {$currentTimezone}" - ); - } - - /** - * @When the owncloud log is cleared - * @Given the owncloud log has been cleared - * - * checks for the httpRequest is done inside clearLogFile function - * - * @return void - * @throws Exception - */ - public function theOwncloudLogIsCleared():void { - LoggingHelper::clearLogFile( - $this->featureContext->getBaseUrl(), - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - $this->featureContext->getStepLineRef() - ); - } - - /** - * After Scenario for logging. Sets back old log settings - * - * @AfterScenario - * - * @return void - * @throws Exception - */ - public function tearDownScenarioLogging():void { - LoggingHelper::restoreLoggingStatus( - $this->oldLogLevel, - $this->oldLogBackend, - $this->oldLogTimezone, - $this->featureContext->getStepLineRef() - ); - } - - /** - * @BeforeScenario - * - * @param BeforeScenarioScope $scope - * - * @return void - */ - public function setUpScenario(BeforeScenarioScope $scope):void { - // Get the environment - $environment = $scope->getEnvironment(); - // Get all the contexts you need in this context - $this->featureContext = $environment->getContext('FeatureContext'); - SetupHelper::init( - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - $this->featureContext->getBaseUrl(), - $this->featureContext->getOcPath() - ); - } - - /** - * Before Scenario for logging. Saves current log settings - * - * @BeforeScenario - * - * @return void - * @throws Exception - */ - public function setUpScenarioLogging():void { - $logging = LoggingHelper::getLogInfo( - $this->featureContext->getStepLineRef() - ); - $this->oldLogLevel = $logging["level"]; - $this->oldLogBackend = $logging["backend"]; - $this->oldLogTimezone = $logging["timezone"]; - } -} diff --git a/tests/acceptance/features/coreApiWebdavUpload2/uploadFileUsingOldChunking.feature b/tests/acceptance/features/coreApiWebdavUpload2/uploadFileUsingOldChunking.feature index 53b57f7a9..be9478069 100644 --- a/tests/acceptance/features/coreApiWebdavUpload2/uploadFileUsingOldChunking.feature +++ b/tests/acceptance/features/coreApiWebdavUpload2/uploadFileUsingOldChunking.feature @@ -74,8 +74,6 @@ Feature: upload file using old chunking Scenario Outline: Checking file id after a move overwrite using old chunking endpoint Given using DAV path And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "textfile0.txt" - And the owncloud log level has been set to debug - And the owncloud log has been cleared And user "Alice" has copied file "/textfile0.txt" to "/existingFile.txt" And user "Alice" has stored id of file "/existingFile.txt" When user "Alice" uploads file "filesForUpload/textfile.txt" to "/existingFile.txt" in 3 chunks with old chunking and using the WebDAV API @@ -87,9 +85,6 @@ Feature: upload file using old chunking Cheers. """ - And the log file should not contain any log-entries containing these attributes: - | app | - | dav | Examples: | dav_version | | old | @@ -125,48 +120,9 @@ Feature: upload file using old chunking | spaces | &#? TIÄFÜ @a#8a=b?c=d ?abc=oc # | | spaces | 0 | - # This scenario does extra checks with the log level set to debug. - # It does not run in smoke test runs. (see comments in scenario above) - Scenario Outline: Chunked upload files with difficult name and check the log - Given using DAV path - And the owncloud log level has been set to debug - And the owncloud log has been cleared - When user "Alice" uploads file "filesForUpload/textfile.txt" to "/" in 3 chunks using the WebDAV API - Then the HTTP status code should be "201" - And as "Alice" file "/" should exist - And the content of file "/" for user "Alice" should be: - """ - This is a testfile. - - Cheers. - """ - And the log file should not contain any log-entries containing these attributes: - | app | - | dav | - Examples: - | dav_version | file-name | - | old | file-name | - | old | &#? | - | old | TIÄFÜ | - | old | 0 | - | old | @a#8a=b?c=d | - | old | ?abc=oc # | - - @skipOnOcV10 @personalSpace - Examples: - | dav_version | file-name | - | spaces | file-name | - | spaces | &#? | - | spaces | TIÄFÜ | - | spaces | 0 | - | spaces | @a#8a=b?c=d | - | spaces | ?abc=oc # | - Scenario Outline: Upload chunked file with old chunking with lengthy filenames Given using DAV path - Given the owncloud log level has been set to debug - And the owncloud log has been cleared When user "Alice" uploads the following chunks to "नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-12345678910.txt" with old chunking and using the WebDAV API | number | content | | 1 | AAAAAAAAAAAAAAAAAAAAAAAAA | @@ -177,9 +133,6 @@ Feature: upload file using old chunking | ETag | /^"[a-f0-9:\.]{1,32}"$/ | And as "Alice" file "नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-12345678910.txt" should exist And the content of file "नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-नेपालि-file-नाम-12345678910.txt" for user "Alice" should be "AAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCC" - And the log file should not contain any log-entries containing these attributes: - | app | - | dav | Examples: | dav_version | | old |