|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\xenc; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use SimpleSAML\XML\Attribute as XMLAttribute; |
|
9
|
|
|
use SimpleSAML\XML\Chunk; |
|
10
|
|
|
use SimpleSAML\XML\Constants as C; |
|
11
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
12
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
|
13
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
|
14
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties; |
|
15
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty; |
|
16
|
|
|
|
|
17
|
|
|
use function dirname; |
|
18
|
|
|
use function strval; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\EncryptionPropertiesTest |
|
22
|
|
|
* |
|
23
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement |
|
24
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertiesType |
|
25
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties |
|
26
|
|
|
* |
|
27
|
|
|
* @package simplesamlphp/xml-security |
|
28
|
|
|
*/ |
|
29
|
|
|
final class EncryptionPropertiesTest extends TestCase |
|
30
|
|
|
{ |
|
31
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
|
|
32
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function setUpBeforeClass(): void |
|
37
|
|
|
{ |
|
38
|
|
|
self::$testedClass = EncryptionProperties::class; |
|
39
|
|
|
|
|
40
|
|
|
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xenc-schema.xsd'; |
|
41
|
|
|
|
|
42
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
|
43
|
|
|
dirname(__FILE__, 3) . '/resources/xml/xenc_EncryptionProperties.xml', |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// marshalling |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testMarshalling(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$someDoc = DOMDocumentFactory::fromString( |
|
56
|
|
|
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>', |
|
57
|
|
|
); |
|
58
|
|
|
$otherDoc = DOMDocumentFactory::fromString( |
|
59
|
|
|
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Other</ssp:Chunk>', |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
/** @var \DOMElement $someElt */ |
|
63
|
|
|
$someElt = $someDoc->documentElement; |
|
64
|
|
|
/** @var \DOMElement $otherElt */ |
|
65
|
|
|
$otherElt = $otherDoc->documentElement; |
|
66
|
|
|
|
|
67
|
|
|
$attr1 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'en'); |
|
68
|
|
|
$attr2 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'nl'); |
|
69
|
|
|
|
|
70
|
|
|
$encryptionProperty1 = new EncryptionProperty( |
|
71
|
|
|
[new Chunk($someElt)], |
|
72
|
|
|
'urn:x-simplesamlphp:phpunit', |
|
73
|
|
|
'inner-first', |
|
74
|
|
|
[$attr1], |
|
75
|
|
|
); |
|
76
|
|
|
$encryptionProperty2 = new EncryptionProperty( |
|
77
|
|
|
[new Chunk($otherElt)], |
|
78
|
|
|
'urn:x-simplesamlphp:phpunit', |
|
79
|
|
|
'inner-second', |
|
80
|
|
|
[$attr2], |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$encryptionProperties = new EncryptionProperties([$encryptionProperty1, $encryptionProperty2], 'outer'); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals( |
|
86
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
|
87
|
|
|
strval($encryptionProperties), |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|