From 751c1e77ebbbbbe3ad3108b27f416a7e12ae3c77 Mon Sep 17 00:00:00 2001 From: Hari Bhandari Date: Thu, 30 May 2019 12:09:29 +0545 Subject: [PATCH 1/2] cli test for security certificates --- .../features/bootstrap/CommandLine.php | 1 - .../features/bootstrap/OccContext.php | 54 +++++++++++++++++++ .../cliMain/securityCertificates.feature | 43 +++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/acceptance/features/cliMain/securityCertificates.feature diff --git a/tests/acceptance/features/bootstrap/CommandLine.php b/tests/acceptance/features/bootstrap/CommandLine.php index 2a4b74fc3adf..65a132d6523d 100644 --- a/tests/acceptance/features/bootstrap/CommandLine.php +++ b/tests/acceptance/features/bootstrap/CommandLine.php @@ -334,7 +334,6 @@ public function findLines($input, $text) { $results[] = $line; } } - return $results; } diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index 8f5a4f30c0d4..8fcbe4fe516a 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -38,6 +38,18 @@ class OccContext implements Context { */ private $featureContext; + /** + * + * @var ImportedCertificates + */ + private $importedCertificates = []; + + /** + * + * @var RemovedCertificates + */ + private $removedCertificates = []; + /** * @var string lastDeletedJobId */ @@ -55,6 +67,33 @@ public function invokingTheCommand($cmd) { $this->featureContext->runOcc([$cmd]); } + /** + * @When the administrator imports security certificate form the path :path + * @Given the administrator has imported security certificate form the path :path + * + * @param string $path + * + * @return void + */ + public function theAdministratorImportsSecurityCertificateFormThePath($path) { + $this->invokingTheCommand("security:certificates:import " . $path); + $pathComponents = \explode("/", $path); + $certificate = \end($pathComponents); + \array_push($this->importedCertificates, $certificate); + } + + /** + * @When the administrator removes the security certificate :certificate + * + * @param string $certificate + * + * @return void + */ + public function theAdministratorRemovesTheSecurityCertificate($certificate) { + $this->invokingTheCommand("security:certificates:remove " . $certificate); + \array_push($this->removedCertificates, $certificate); + } + /** * @When /^the administrator invokes occ command "([^"]*)" with environment variable "([^"]*)" set to "([^"]*)"$/ * @Given /^the administrator has invoked occ command "([^"]*)" with environment variable "([^"]*)" set to "([^"]*)"$/ @@ -846,6 +885,21 @@ public function theSystemConfigKeyFromLastCommandOutputShouldContainValue( ); } + /** + * This will run after EVERY scenario. + * It will set the properties for this object. + * + * @AfterScenario + * + * @return void + */ + public function removeImportedCertificates() { + $remainingCertificates = \array_diff($this->importedCertificates, $this->removedCertificates); + foreach ($remainingCertificates as $certificate) { + $this->invokingTheCommand("security:certificates:remove " . $certificate); + $this->theCommandShouldHaveBeenSuccessful(); + } + } /** * This will run before EVERY scenario. * It will set the properties for this object. diff --git a/tests/acceptance/features/cliMain/securityCertificates.feature b/tests/acceptance/features/cliMain/securityCertificates.feature new file mode 100644 index 000000000000..11a6922c2daf --- /dev/null +++ b/tests/acceptance/features/cliMain/securityCertificates.feature @@ -0,0 +1,43 @@ +@cli +Feature: security certificates + As an admin + I want to be able to manage the ownCloud security certificates + So that I can ensure the proper encrpytion mechanism + + Scenario: Import a security certificate + When the administrator imports security certificate form the path "tests/data/certificates/goodCertificate.crt" + Then the command should have been successful + When the administrator invokes occ command "security:certificates" + Then the command should have been successful + And the command output table should contain the following text: + | table_column | + | goodCertificate.crt | + + Scenario: List security certificates when multiple certificates are imported + Given the administrator has imported security certificate form the path "tests/data/certificates/goodCertificate.crt" + And the administrator has imported security certificate form the path "tests/data/certificates/badCertificate.crt" + When the administrator invokes occ command "security:certificates" + And the command output table should contain the following text: + | table_column | + | goodCertificate.crt | + | badCertificate.crt | + + Scenario: Remove a security certificate + Given the administrator has imported security certificate form the path "tests/data/certificates/goodCertificate.crt" + And the administrator has imported security certificate form the path "tests/data/certificates/badCertificate.crt" + When the administrator removes the security certificate "goodCertificate.crt" + Then the command should have been successful + When the administrator invokes occ command "security:certificates" + And the command output table should contain the following text: + | table_column | + | badCertificate.crt | + + @issue-35364 + Scenario: Remove a security certificate that is not installed + When the administrator removes the security certificate "someCertificate.crt" + Then the command should have been successful + # Then the command should not have been successful + + Scenario: Import random file as certificate + When the administrator imports security certificate form the path "tests/data/lorem.txt" + Then the command error output should contain the text "Certificate could not get parsed." \ No newline at end of file From 56b8f6fedff1582dc719e3bf682e10d429272cdc Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 5 Jun 2019 12:59:09 +0545 Subject: [PATCH 2/2] Change 'form the path' to 'from the path' --- tests/acceptance/features/bootstrap/OccContext.php | 6 +++--- .../features/cliMain/securityCertificates.feature | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/features/bootstrap/OccContext.php b/tests/acceptance/features/bootstrap/OccContext.php index 8fcbe4fe516a..c9133c02b57a 100644 --- a/tests/acceptance/features/bootstrap/OccContext.php +++ b/tests/acceptance/features/bootstrap/OccContext.php @@ -68,14 +68,14 @@ public function invokingTheCommand($cmd) { } /** - * @When the administrator imports security certificate form the path :path - * @Given the administrator has imported security certificate form the path :path + * @When the administrator imports security certificate from the path :path + * @Given the administrator has imported security certificate from the path :path * * @param string $path * * @return void */ - public function theAdministratorImportsSecurityCertificateFormThePath($path) { + public function theAdministratorImportsSecurityCertificateFromThePath($path) { $this->invokingTheCommand("security:certificates:import " . $path); $pathComponents = \explode("/", $path); $certificate = \end($pathComponents); diff --git a/tests/acceptance/features/cliMain/securityCertificates.feature b/tests/acceptance/features/cliMain/securityCertificates.feature index 11a6922c2daf..a0aac967b5f2 100644 --- a/tests/acceptance/features/cliMain/securityCertificates.feature +++ b/tests/acceptance/features/cliMain/securityCertificates.feature @@ -5,7 +5,7 @@ Feature: security certificates So that I can ensure the proper encrpytion mechanism Scenario: Import a security certificate - When the administrator imports security certificate form the path "tests/data/certificates/goodCertificate.crt" + When the administrator imports security certificate from the path "tests/data/certificates/goodCertificate.crt" Then the command should have been successful When the administrator invokes occ command "security:certificates" Then the command should have been successful @@ -14,8 +14,8 @@ Feature: security certificates | goodCertificate.crt | Scenario: List security certificates when multiple certificates are imported - Given the administrator has imported security certificate form the path "tests/data/certificates/goodCertificate.crt" - And the administrator has imported security certificate form the path "tests/data/certificates/badCertificate.crt" + Given the administrator has imported security certificate from the path "tests/data/certificates/goodCertificate.crt" + And the administrator has imported security certificate from the path "tests/data/certificates/badCertificate.crt" When the administrator invokes occ command "security:certificates" And the command output table should contain the following text: | table_column | @@ -23,8 +23,8 @@ Feature: security certificates | badCertificate.crt | Scenario: Remove a security certificate - Given the administrator has imported security certificate form the path "tests/data/certificates/goodCertificate.crt" - And the administrator has imported security certificate form the path "tests/data/certificates/badCertificate.crt" + Given the administrator has imported security certificate from the path "tests/data/certificates/goodCertificate.crt" + And the administrator has imported security certificate from the path "tests/data/certificates/badCertificate.crt" When the administrator removes the security certificate "goodCertificate.crt" Then the command should have been successful When the administrator invokes occ command "security:certificates" @@ -39,5 +39,5 @@ Feature: security certificates # Then the command should not have been successful Scenario: Import random file as certificate - When the administrator imports security certificate form the path "tests/data/lorem.txt" + When the administrator imports security certificate from the path "tests/data/lorem.txt" Then the command error output should contain the text "Certificate could not get parsed." \ No newline at end of file