Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] cli test for security certificates #35435

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/acceptance/features/bootstrap/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ public function findLines($input, $text) {
$results[] = $line;
}
}

return $results;
}

Expand Down
54 changes: 54 additions & 0 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ class OccContext implements Context {
*/
private $featureContext;

/**
*
* @var ImportedCertificates
*/
private $importedCertificates = [];

/**
*
* @var RemovedCertificates
*/
private $removedCertificates = [];

/**
* @var string lastDeletedJobId
*/
Expand All @@ -55,6 +67,33 @@ public function invokingTheCommand($cmd) {
$this->featureContext->runOcc([$cmd]);
}

/**
* @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 theAdministratorImportsSecurityCertificateFromThePath($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 "([^"]*)"$/
Expand Down Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions tests/acceptance/features/cliMain/securityCertificates.feature
Original file line number Diff line number Diff line change
@@ -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 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
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 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 |
| goodCertificate.crt |
| badCertificate.crt |

Scenario: Remove a security certificate
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"
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 from the path "tests/data/lorem.txt"
Then the command error output should contain the text "Certificate could not get parsed."