-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2554 from LibreSign/feature/implement-tests
Implement tests
- Loading branch information
Showing
8 changed files
with
180 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
use OCA\Libresign\Handler\CertificateEngine\OpenSslHandler; | ||
use OCP\AppFramework\Services\IAppConfig; | ||
use OCP\Files\AppData\IAppDataFactory; | ||
use OCP\IConfig; | ||
use OCP\IDateTimeFormatter; | ||
use OCP\ITempManager; | ||
use org\bovigo\vfs\vfsStream; | ||
|
||
final class OpenSslHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { | ||
private IConfig $config; | ||
private IAppConfig $appConfig; | ||
private IAppDataFactory $appDataFactory; | ||
private IDateTimeFormatter $dateTimeFormatter; | ||
private ITempManager $tempManager; | ||
private OpenSslHandler $openSslHandler; | ||
public function setUp(): void { | ||
$this->config = $this->createMock(IConfig::class); | ||
$this->appConfig = $this->createMock(IAppConfig::class); | ||
$this->appDataFactory = $this->createMock(IAppDataFactory::class); | ||
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); | ||
$this->dateTimeFormatter | ||
->method('formatDateTime') | ||
->willReturn('fake date'); | ||
$this->tempManager = $this->createMock(ITempManager::class); | ||
$this->tempManager | ||
->method('getTemporaryFile') | ||
->willReturn(tempnam(sys_get_temp_dir(), 'temp')); | ||
$this->openSslHandler = new OpenSslHandler( | ||
$this->config, | ||
$this->appConfig, | ||
$this->appDataFactory, | ||
$this->dateTimeFormatter, | ||
$this->tempManager, | ||
); | ||
vfsStream::setup('certificate'); | ||
$this->openSslHandler->setConfigPath('vfs://certificate/'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataReadCertificate | ||
*/ | ||
public function testReadCertificate(string $commonName, array $hosts, string $password, array $csrNames): void { | ||
if (isset($csrNames['C'])) { | ||
$this->openSslHandler->setCountry($csrNames['C']); | ||
} | ||
if (isset($csrNames['ST'])) { | ||
$this->openSslHandler->setState($csrNames['ST']); | ||
} | ||
if (isset($csrNames['O'])) { | ||
$this->openSslHandler->setOrganization($csrNames['O']); | ||
} | ||
if (isset($csrNames['OU'])) { | ||
$this->openSslHandler->setOrganizationalUnit($csrNames['OU']); | ||
} | ||
$this->openSslHandler->generateRootCert($commonName, $csrNames); | ||
|
||
$this->openSslHandler->setHosts($hosts); | ||
$this->openSslHandler->setPassword($password); | ||
$certificateContent = $this->openSslHandler->generateCertificate(); | ||
$parsed = $this->openSslHandler->readCertificate($certificateContent, $password); | ||
$this->assertJsonStringEqualsJsonString( | ||
json_encode($csrNames), | ||
json_encode($parsed['subject']) | ||
); | ||
} | ||
|
||
public static function dataReadCertificate(): array { | ||
return [ | ||
[ | ||
'common name', | ||
['[email protected]'], | ||
'password', | ||
[ | ||
'C' => 'CT', | ||
'ST' => 'Some-State', | ||
'O' => 'Organization Name', | ||
], | ||
], | ||
[ | ||
'common name', | ||
['[email protected]'], | ||
'password', | ||
[ | ||
'C' => 'CT', | ||
'ST' => 'Some-State', | ||
'O' => 'Organization Name', | ||
'OU' => 'Organization Unit', | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.