Repository navigation
Expand file tree
/
Copy pathSignatureTest.php
More file actions
151 lines (133 loc) · 4.89 KB
/
Copy pathSignatureTest.php
File metadata and controls
151 lines (133 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
declare(strict_types=1);
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSchema\Type\IDValue;
use SimpleSAML\XMLSecurity\Utils\XPath;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
use SimpleSAML\XMLSecurity\XML\ds\DsObject;
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo;
use SimpleSAML\XMLSecurity\XML\ds\Signature;
use SimpleSAML\XMLSecurity\XML\ds\SignatureValue;
use SimpleSAML\XMLSecurity\XML\ds\SignedInfo;
use function dirname;
use function strval;
/**
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\SignatureTest
*
* @package simplesamlphp/xml-security
*/
#[Group('ds')]
#[CoversClass(AbstractDsElement::class)]
#[CoversClass(Signature::class)]
final class SignatureTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;
/**
* Set up the test.
*/
public static function setUpBeforeClass(): void
{
self::$testedClass = Signature::class;
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_Signature.xml',
);
}
/**
* Test creating a SignatureValue from scratch.
*/
public function testMarshalling(): void
{
$signature = new Signature(
SignedInfo::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_SignedInfo.xml',
)->documentElement,
),
SignatureValue::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_SignatureValue.xml',
)->documentElement,
),
KeyInfo::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_KeyInfo.xml',
)->documentElement,
),
[
new DsObject(
null,
null,
null,
[
new Chunk(
DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
)->documentElement,
),
],
),
],
IDValue::fromString('def456'),
);
$expectedXml = self::$xmlRepresentation->saveXml(self::$xmlRepresentation->documentElement);
$this->assertNotFalse($expectedXml);
$actualXml = strval($signature);
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
}
/**
*/
public function testMarshallingElementOrdering(): void
{
$signature = new Signature(
SignedInfo::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_SignedInfo.xml',
)->documentElement,
),
SignatureValue::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_SignatureValue.xml',
)->documentElement,
),
KeyInfo::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_KeyInfo.xml',
)->documentElement,
),
[
new DsObject(
null,
null,
null,
[
new Chunk(
DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
)->documentElement,
),
],
),
],
IDValue::fromString('def456'),
);
$signatureElement = $signature->toXML();
$xpCache = XPath::getXPath($signatureElement);
$signedInfo = XPath::xpQuery($signatureElement, './ds:SignedInfo', $xpCache);
$this->assertCount(1, $signedInfo);
/** @var \Dom\Element[] $signatureElements */
$signatureElements = XPath::xpQuery($signatureElement, './ds:SignedInfo/following-sibling::*', $xpCache);
// Test ordering of Signature contents
$this->assertCount(3, $signatureElements);
$this->assertEquals('ds:SignatureValue', $signatureElements[0]->tagName);
$this->assertEquals('ds:KeyInfo', $signatureElements[1]->tagName);
$this->assertEquals('ds:Object', $signatureElements[2]->tagName);
}
}