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\Chunk; |
10
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
12
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
13
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
14
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; |
15
|
|
|
|
16
|
|
|
use function dirname; |
17
|
|
|
use function strval; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class \SimpleSAML\XMLSecurity\XML\Test\ds\DigestMethodTest |
21
|
|
|
* |
22
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement |
23
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\DigestMethod |
24
|
|
|
* |
25
|
|
|
* @package simplesamlphp/xml-security |
26
|
|
|
*/ |
27
|
|
|
final class DigestMethodTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
30
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
*/ |
34
|
|
|
public static function setUpBeforeClass(): void |
35
|
|
|
{ |
36
|
|
|
self::$testedClass = DigestMethod::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_DigestMethod.xml', |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
*/ |
48
|
|
|
public function testMarshalling(): void |
49
|
|
|
{ |
50
|
|
|
$digestMethod = new DigestMethod( |
51
|
|
|
C::DIGEST_SHA256, |
52
|
|
|
[ |
53
|
|
|
new Chunk(DOMDocumentFactory::fromString( |
54
|
|
|
'<some:Chunk xmlns:some="urn:test:some">Random</some:Chunk>' |
55
|
|
|
)->documentElement) |
56
|
|
|
], |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->assertEquals( |
60
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
61
|
|
|
strval($digestMethod), |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
*/ |
68
|
|
|
public function testUnmarshalling(): void |
69
|
|
|
{ |
70
|
|
|
$digestMethod = DigestMethod::fromXML(self::$xmlRepresentation->documentElement); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( |
73
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
74
|
|
|
strval($digestMethod), |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|