Skip to content

Commit

Permalink
Add test scenario to generate pfx file
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jun 9, 2023
1 parent 15d57b6 commit e14e614
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/Handler/CertificateEngine/AEngineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ public function populateInstance(): self {
if (!$this->getCommonName()) {
$this->setCommonName($rootCert['commonName']);
}
if (!$this->getConfigPath()) {
$this->setConfigPath($this->config->getAppValue(Application::APP_ID, 'configPath'));
}
return $this;
}

protected function getConfigPath(): string {
if ($this->configPath) {
return $this->configPath;
}
$this->configPath = $this->config->getAppValue(Application::APP_ID, 'configPath');
if ($this->configPath) {
return $this->configPath;
}
Expand All @@ -138,6 +139,9 @@ protected function getConfigPath(): string {
}
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
$this->configPath = $dataDir . '/' . $this->getInternalPathOfFolder($folder);
if (!is_dir($this->configPath)) {
exec('mkdir -p "' . $this->configPath . '"');
}
return $this->configPath;
}

Expand Down
13 changes: 10 additions & 3 deletions lib/Handler/CertificateEngine/OpenSslHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
* @method CfsslHandler setClient(Client $client)
*/
class OpenSslHandler extends AEngineHandler implements IEngineHandler {
public function generateCertificate(string $certificate = '', string $privateKey = ''): string {
$configPath = $this->getConfigPath();
$certificate = file_get_contents($configPath . '/ca.pem');
$privateKey = file_get_contents($configPath . '/ca-key.pem');
return parent::generateCertificate($certificate, $privateKey);
}

public function generateRootCert(
string $commonName,
array $names = [],
Expand All @@ -35,9 +42,9 @@ public function generateRootCert(
openssl_x509_export($x509, $certout);
openssl_pkey_export($privkey, $pkeyout);

file_put_contents($configPath . 'ca.csr', $csrout);
file_put_contents($configPath . 'ca.pem', $certout);
file_put_contents($configPath . 'ca-key.pem', $pkeyout);
file_put_contents($configPath . '/ca.csr', $csrout);
file_put_contents($configPath . '/ca.pem', $certout);
file_put_contents($configPath . '/ca-key.pem', $pkeyout);

return $pkeyout;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/features/account/signature.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Feature: account/signature
Background: Create users
Given user "signer1" exists
And set the email of user "signer1" to "[email protected]"
And as user "admin"
And sending "post" to ocs "/apps/libresign/api/v1/admin/certificate/openssl"
| rootCert | {"commonName":"Common Name"} |
And the response should have a status code 200
And sending "get" to ocs "/apps/libresign/api/v1/admin/certificate"
And the response should have a status code 200
And the response should be a JSON array with the following mandatory values
| key | value |
| rootCert | {"commonName":"Common Name","names":[]} |
| generated | true |

Scenario: Create pfx with success
Given as user "signer1"
And sending "post" to ocs "/apps/libresign/api/v1/account/signature"
| signPassword | password |
Then the response should have a status code 200
And the response should be a JSON array with the following mandatory values
| key | value |
| success | true |
| signature | /signer1/files/LibreSign/signature.pfx |

0 comments on commit e14e614

Please sign in to comment.