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