Skip to content

Commit 181e579

Browse files
committed
test: expand CRL extractor coverage with RFC-driven data provider
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 1b81412 commit 181e579

2 files changed

Lines changed: 73 additions & 23 deletions

File tree

lib/Service/Crl/CrlDistributionPointsExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function extractFromExtensions(array $extensions): array {
4646

4747
$urls = [];
4848
foreach ($values as $value) {
49-
preg_match_all('/URI\s*:\s*([^\s,\n]+)/i', $value, $matches);
49+
preg_match_all('/URI\s*:\s*([^\s\n]+)/i', $value, $matches);
5050
if (!empty($matches[1])) {
5151
$urls = [...$urls, ...$matches[1]];
5252
}

tests/php/Unit/Service/Crl/CrlDistributionPointsExtractorTest.php

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\Libresign\Tests\Unit\Service\Crl;
1111

1212
use OCA\Libresign\Service\Crl\CrlDistributionPointsExtractor;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use PHPUnit\Framework\TestCase;
1415

1516
final class CrlDistributionPointsExtractorTest extends TestCase {
@@ -19,30 +20,79 @@ protected function setUp(): void {
1920
$this->extractor = new CrlDistributionPointsExtractor();
2021
}
2122

22-
public function testExtractFromOidExtensionName(): void {
23-
$result = $this->extractor->extractFromExtensions([
24-
'2.5.29.31' => "Full Name:\nURI:https://example.org/crl/root.crl",
25-
]);
23+
#[DataProvider('crlDistributionPointExtractionProvider')]
24+
public function testExtractFromExtensions(array $extensions, bool $expectedHasExtension, array $expectedUrls): void {
25+
$result = $this->extractor->extractFromExtensions($extensions);
2626

27-
$this->assertTrue($result['hasExtension']);
28-
$this->assertSame(['https://example.org/crl/root.crl'], $result['urls']);
27+
$this->assertSame($expectedHasExtension, $result['hasExtension']);
28+
$this->assertSame($expectedUrls, $result['urls']);
2929
}
3030

31-
public function testExtractFromX509LabelExtensionName(): void {
32-
$result = $this->extractor->extractFromExtensions([
33-
'X509v3 CRL Distribution Points' => "Full Name:\n URI : https://example.org/crl/issuer.crl",
34-
]);
35-
36-
$this->assertTrue($result['hasExtension']);
37-
$this->assertSame(['https://example.org/crl/issuer.crl'], $result['urls']);
38-
}
39-
40-
public function testIgnoreUnknownExtensionNameWithSimilarText(): void {
41-
$result = $this->extractor->extractFromExtensions([
42-
'Issuer CRL Distribution Points' => "Full Name:\nURI:https://example.org/crl/issuer.crl",
43-
]);
44-
45-
$this->assertFalse($result['hasExtension']);
46-
$this->assertSame([], $result['urls']);
31+
/**
32+
* RFC 5280 4.2.1.13 defines cRLDistributionPoints as DistributionPointName
33+
* with URI represented in GeneralNames. Tests cover common OpenSSL textual
34+
* outputs for HTTP and LDAP URIs and multiple distribution points.
35+
*
36+
* @return array<string, array{0: array<string, mixed>, 1: bool, 2: list<string>}>
37+
*/
38+
public static function crlDistributionPointExtractionProvider(): array {
39+
return [
40+
'oid-extension-with-http-uri' => [
41+
[
42+
'2.5.29.31' => "Full Name:\nURI:https://example.org/crl/root.crl",
43+
],
44+
true,
45+
['https://example.org/crl/root.crl'],
46+
],
47+
'x509v3-label-with-http-uri' => [
48+
[
49+
'X509v3 CRL Distribution Points' => "Full Name:\n URI : https://example.org/crl/issuer.crl",
50+
],
51+
true,
52+
['https://example.org/crl/issuer.crl'],
53+
],
54+
'rfc-ldap-uri-with-dn-and-query' => [
55+
[
56+
'crlDistributionPoints' => "Full Name:\nURI:ldap://ldap.example.com/cn=Example%20CA,ou=PKI,dc=example,dc=com?certificateRevocationList;binary",
57+
],
58+
true,
59+
['ldap://ldap.example.com/cn=Example%20CA,ou=PKI,dc=example,dc=com?certificateRevocationList;binary'],
60+
],
61+
'multiple-distribution-points-in-single-extension' => [
62+
[
63+
'2.5.29.31' => "Full Name:\nURI:https://pki.example.org/root.crl\nFull Name:\nURI:ldap://ldap.example.org/cn=RootCA,dc=example,dc=org?certificateRevocationList;binary",
64+
],
65+
true,
66+
[
67+
'https://pki.example.org/root.crl',
68+
'ldap://ldap.example.org/cn=RootCA,dc=example,dc=org?certificateRevocationList;binary',
69+
],
70+
],
71+
'array-extension-value-and-duplicates' => [
72+
[
73+
'2.5.29.31' => [
74+
'Full Name:',
75+
'URI:https://example.org/crl/root.crl',
76+
'URI:https://example.org/crl/root.crl',
77+
],
78+
],
79+
true,
80+
['https://example.org/crl/root.crl'],
81+
],
82+
'known-extension-without-uri' => [
83+
[
84+
'2.5.29.31' => 'Distribution Point Name: relativeName=CN=DP1',
85+
],
86+
true,
87+
[],
88+
],
89+
'unknown-extension-name-should-not-match' => [
90+
[
91+
'Issuer CRL Distribution Points' => "Full Name:\nURI:https://example.org/crl/issuer.crl",
92+
],
93+
false,
94+
[],
95+
],
96+
];
4797
}
4898
}

0 commit comments

Comments
 (0)