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