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\Constants as C; |
10
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
12
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
13
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; |
14
|
|
|
|
15
|
|
|
use function dirname; |
16
|
|
|
use function strval; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class \SimpleSAML\XMLSecurity\XML\ds\X509SerialNumberTest |
20
|
|
|
* |
21
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement |
22
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber |
23
|
|
|
* |
24
|
|
|
* @package simplesamlphp/xml-security |
25
|
|
|
*/ |
26
|
|
|
final class X509SerialNumberTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
*/ |
33
|
|
|
public static function setUpBeforeClass(): void |
34
|
|
|
{ |
35
|
|
|
self::$testedClass = X509SerialNumber::class; |
36
|
|
|
|
37
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
38
|
|
|
dirname(__FILE__, 3) . '/resources/xml/ds_X509SerialNumber.xml', |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
*/ |
45
|
|
|
public function testMarshalling(): void |
46
|
|
|
{ |
47
|
|
|
$serialNumber = new X509SerialNumber('123456'); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( |
50
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
51
|
|
|
strval($serialNumber), |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
*/ |
58
|
|
|
public function testUnmarshalling(): void |
59
|
|
|
{ |
60
|
|
|
$serialNumber = X509SerialNumber::fromXML(self::$xmlRepresentation->documentElement); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( |
63
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
64
|
|
|
strval($serialNumber), |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
*/ |
71
|
|
|
public function testUnmarshallingIncorrectTypeThrowsException(): void |
72
|
|
|
{ |
73
|
|
|
$document = clone self::$xmlRepresentation; |
74
|
|
|
$document->documentElement->textContent = 'Not an integer'; |
75
|
|
|
|
76
|
|
|
$this->expectException(SchemaViolationException::class); |
77
|
|
|
X509SerialNumber::fromXML($document->documentElement); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|