|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
10
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
|
11
|
|
|
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\Key; |
|
13
|
|
|
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; |
|
14
|
|
|
use SimpleSAML\XMLSecurity\Utils\Certificate as CertificateUtils; |
|
15
|
|
|
use SimpleSAML\XMLSecurity\Utils\XPath; |
|
16
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; |
|
17
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509IssuerName; |
|
18
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial; |
|
19
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; |
|
20
|
|
|
|
|
21
|
|
|
use function dirname; |
|
22
|
|
|
use function strval; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class \SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial |
|
26
|
|
|
* |
|
27
|
|
|
* @package simplesamlphp/xml-security |
|
28
|
|
|
*/ |
|
29
|
|
|
#[CoversClass(AbstractDsElement::class)] |
|
30
|
|
|
#[CoversClass(X509IssuerSerial::class)] |
|
31
|
|
|
final class X509IssuerSerialTest extends TestCase |
|
32
|
|
|
{ |
|
33
|
|
|
use SerializableElementTestTrait; |
|
34
|
|
|
|
|
35
|
|
|
/** @var \SimpleSAML\XMLSecurity\Key\X509Certificate */ |
|
36
|
|
|
private static Key\X509Certificate $key; |
|
37
|
|
|
|
|
38
|
|
|
/** @var \SimpleSAML\XMLSecurity\XML\ds\X509IssuerName */ |
|
39
|
|
|
private static X509IssuerName $issuer; |
|
40
|
|
|
|
|
41
|
|
|
/** @var \SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber */ |
|
42
|
|
|
private static X509SerialNumber $serial; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setUp(): void |
|
48
|
|
|
{ |
|
49
|
|
|
self::$testedClass = X509IssuerSerial::class; |
|
50
|
|
|
|
|
51
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
|
52
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_X509IssuerSerial.xml', |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
self::$key = new Key\X509Certificate(PEM::fromString(PEMCertificatesMock::getPlainCertificate())); |
|
56
|
|
|
|
|
57
|
|
|
/** @var string[] $details */ |
|
58
|
|
|
$details = self::$key->getCertificateDetails(); |
|
59
|
|
|
self::$issuer = new X509IssuerName(CertificateUtils::parseIssuer($details['issuer'])); |
|
60
|
|
|
self::$serial = new X509SerialNumber($details['serialNumber']); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testMarshalling(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$X509IssuerSerial = new X509IssuerSerial(self::$issuer, self::$serial); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals( |
|
71
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
72
|
|
|
strval($X509IssuerSerial), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testMarshallingElementOrdering(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$X509IssuerSerial = new X509IssuerSerial(self::$issuer, self::$serial); |
|
82
|
|
|
$X509IssuerSerialElement = $X509IssuerSerial->toXML(); |
|
83
|
|
|
|
|
84
|
|
|
$xpCache = XPath::getXPath($X509IssuerSerialElement); |
|
85
|
|
|
|
|
86
|
|
|
$issuerName = XPath::xpQuery($X509IssuerSerialElement, './ds:X509IssuerName', $xpCache); |
|
87
|
|
|
$this->assertCount(1, $issuerName); |
|
88
|
|
|
|
|
89
|
|
|
/** @var \DOMElement[] $X509IssuerSerialElements */ |
|
90
|
|
|
$X509IssuerSerialElements = XPath::xpQuery( |
|
91
|
|
|
$X509IssuerSerialElement, |
|
92
|
|
|
'./ds:X509IssuerName/following-sibling::*', |
|
93
|
|
|
$xpCache, |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
// Test ordering of X509IssuerSerial contents |
|
97
|
|
|
$this->assertCount(1, $X509IssuerSerialElements); |
|
98
|
|
|
$this->assertEquals('ds:X509SerialNumber', $X509IssuerSerialElements[0]->tagName); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|