1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\dsig11; |
6
|
|
|
|
7
|
|
|
use DOMDocument; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
10
|
|
|
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
12
|
|
|
use SimpleSAML\XMLSecurity\Constants as C; |
13
|
|
|
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; |
14
|
|
|
use SimpleSAML\XMLSecurity\Key; |
15
|
|
|
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; |
16
|
|
|
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; |
17
|
|
|
use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest; |
18
|
|
|
|
19
|
|
|
use function base64_encode; |
20
|
|
|
use function dirname; |
21
|
|
|
use function hex2bin; |
22
|
|
|
use function strval; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\X509DigestTest |
26
|
|
|
* |
27
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element |
28
|
|
|
* @covers \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest |
29
|
|
|
* |
30
|
|
|
* @package simplesamlphp/xml-security |
31
|
|
|
*/ |
32
|
|
|
final class X509DigestTest extends TestCase |
33
|
|
|
{ |
34
|
|
|
use SchemaValidationTestTrait; |
|
|
|
|
35
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
private static string $digest; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
*/ |
43
|
|
|
public static function setUpBeforeClass(): void |
44
|
|
|
{ |
45
|
|
|
self::$testedClass = X509Digest::class; |
46
|
|
|
|
47
|
|
|
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig11-schema.xsd'; |
48
|
|
|
|
49
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
50
|
|
|
dirname(__FILE__, 3) . '/resources/xml/dsig11_X509Digest.xml', |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$key = new Key\X509Certificate(PEM::fromString(PEMCertificatesMock::getPlainCertificate())); |
54
|
|
|
self::$digest = base64_encode(hex2bin($key->getRawThumbprint(C::DIGEST_SHA256))); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
*/ |
60
|
|
|
public function testMarshalling(): void |
61
|
|
|
{ |
62
|
|
|
$x509digest = new X509Digest(self::$digest, C::DIGEST_SHA256); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), |
66
|
|
|
strval($x509digest), |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|