1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\ds; |
6
|
|
|
|
7
|
|
|
use DOMDocument; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
10
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
12
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
13
|
|
|
use SimpleSAML\XML\Utils\XPath; |
14
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Exponent; |
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\Modulus; |
16
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue; |
17
|
|
|
|
18
|
|
|
use function dirname; |
19
|
|
|
use function strval; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\RSAKeyValueTest |
23
|
|
|
* |
24
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement |
25
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue |
26
|
|
|
* |
27
|
|
|
* @package simplesamlphp/xml-security |
28
|
|
|
*/ |
29
|
|
|
final class RSAKeyValueTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
32
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
*/ |
36
|
|
|
public static function setUpBeforeClass(): void |
37
|
|
|
{ |
38
|
|
|
self::$testedClass = RSAKeyValue::class; |
39
|
|
|
|
40
|
|
|
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd'; |
41
|
|
|
|
42
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
43
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_RSAKeyValue.xml', |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
*/ |
50
|
|
|
public function testMarshalling(): void |
51
|
|
|
{ |
52
|
|
|
$RSAKeyValue = new RSAKeyValue( |
53
|
|
|
new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), |
54
|
|
|
new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->assertEquals( |
58
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
59
|
|
|
strval($RSAKeyValue), |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
*/ |
66
|
|
|
public function testMarshallingElementOrder(): void |
67
|
|
|
{ |
68
|
|
|
$RSAKeyValue = new RSAKeyValue( |
69
|
|
|
new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), |
70
|
|
|
new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$RSAKeyValueElement = $RSAKeyValue->toXML(); |
74
|
|
|
$xpCache = XPath::getXPath($RSAKeyValueElement); |
75
|
|
|
|
76
|
|
|
$modulus = XPath::xpQuery($RSAKeyValueElement, './ds:Modulus', $xpCache); |
77
|
|
|
$this->assertCount(1, $modulus); |
78
|
|
|
|
79
|
|
|
/** @psalm-var \DOMElement[] $RSAKeyValueElements */ |
80
|
|
|
$RSAKeyValueElements = XPath::xpQuery($RSAKeyValueElement, './ds:Modulus/following-sibling::*', $xpCache); |
81
|
|
|
|
82
|
|
|
// Test ordering of RSAKeyValue contents |
83
|
|
|
$this->assertCount(1, $RSAKeyValueElements); |
84
|
|
|
$this->assertEquals('ds:Exponent', $RSAKeyValueElements[0]->tagName); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
*/ |
90
|
|
|
public function testUnmarshalling(): void |
91
|
|
|
{ |
92
|
|
|
$RSAKeyValue = RSAKeyValue::fromXML(self::$xmlRepresentation->documentElement); |
93
|
|
|
|
94
|
|
|
$this->assertEquals( |
95
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
96
|
|
|
strval($RSAKeyValue), |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|