|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use SimpleSAML\XML\Chunk; |
|
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
10
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
|
11
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
|
12
|
|
|
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; |
|
13
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; |
|
14
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509Data; |
|
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509IssuerName; |
|
16
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial; |
|
17
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; |
|
18
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; |
|
19
|
|
|
|
|
20
|
|
|
use function dirname; |
|
21
|
|
|
use function openssl_x509_parse; |
|
22
|
|
|
use function str_replace; |
|
23
|
|
|
use function strval; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\X509DataTest |
|
27
|
|
|
* |
|
28
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement |
|
29
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\X509Data |
|
30
|
|
|
* |
|
31
|
|
|
* @package simplesamlphp/xml-security |
|
32
|
|
|
*/ |
|
33
|
|
|
final class X509DataTest extends TestCase |
|
34
|
|
|
{ |
|
35
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
|
|
36
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
private static string $certificate; |
|
40
|
|
|
|
|
41
|
|
|
/** @var string[] */ |
|
42
|
|
|
private static array $certData; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function setUpBeforeClass(): void |
|
48
|
|
|
{ |
|
49
|
|
|
self::$testedClass = X509Data::class; |
|
50
|
|
|
|
|
51
|
|
|
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd'; |
|
52
|
|
|
|
|
53
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
|
54
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_X509Data.xml', |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
self::$certificate = str_replace( |
|
58
|
|
|
[ |
|
59
|
|
|
'-----BEGIN CERTIFICATE-----', |
|
60
|
|
|
'-----END CERTIFICATE-----', |
|
61
|
|
|
'-----BEGIN RSA PUBLIC KEY-----', |
|
62
|
|
|
'-----END RSA PUBLIC KEY-----', |
|
63
|
|
|
"\r\n", |
|
64
|
|
|
"\n", |
|
65
|
|
|
], |
|
66
|
|
|
[ |
|
67
|
|
|
'', |
|
68
|
|
|
'', |
|
69
|
|
|
'', |
|
70
|
|
|
'', |
|
71
|
|
|
"\n", |
|
72
|
|
|
'' |
|
73
|
|
|
], |
|
74
|
|
|
PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE), |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
self::$certData = openssl_x509_parse( |
|
78
|
|
|
PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE), |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testMarshalling(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$x509data = new X509Data( |
|
88
|
|
|
[ |
|
89
|
|
|
new Chunk( |
|
90
|
|
|
DOMDocumentFactory::fromString( |
|
91
|
|
|
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>' |
|
92
|
|
|
)->documentElement, |
|
93
|
|
|
), |
|
94
|
|
|
new X509Certificate(self::$certificate), |
|
95
|
|
|
new X509IssuerSerial( |
|
96
|
|
|
new X509IssuerName(sprintf( |
|
97
|
|
|
'C=US,ST=Hawaii,L=Honolulu,O=SimpleSAMLphp HQ,CN=SimpleSAMLphp Testing CA,emailAddress=%s', |
|
98
|
|
|
'[email protected]' |
|
99
|
|
|
)), |
|
100
|
|
|
new X509SerialNumber('2'), |
|
101
|
|
|
), |
|
102
|
|
|
new X509SubjectName(self::$certData['name']), |
|
103
|
|
|
new Chunk(DOMDocumentFactory::fromString( |
|
104
|
|
|
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">other</ssp:Chunk>' |
|
105
|
|
|
)->documentElement) |
|
106
|
|
|
], |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( |
|
110
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
111
|
|
|
strval($x509data), |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|