1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\dsig11; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
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\AbstractDsig11Element; |
18
|
|
|
use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest; |
19
|
|
|
|
20
|
|
|
use function base64_encode; |
21
|
|
|
use function dirname; |
22
|
|
|
use function hex2bin; |
23
|
|
|
use function strval; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\X509DigestTest |
27
|
|
|
* |
28
|
|
|
* @package simplesamlphp/xml-security |
29
|
|
|
*/ |
30
|
|
|
#[CoversClass(AbstractDsig11Element::class)] |
31
|
|
|
#[CoversClass(X509Digest::class)] |
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::$xmlRepresentation = DOMDocumentFactory::fromFile( |
48
|
|
|
dirname(__FILE__, 3) . '/resources/xml/dsig11_X509Digest.xml', |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$key = new Key\X509Certificate(PEM::fromString(PEMCertificatesMock::getPlainCertificate())); |
52
|
|
|
/** @var string $binary */ |
53
|
|
|
$binary = hex2bin($key->getRawThumbprint(C::DIGEST_SHA256)); |
54
|
|
|
self::$digest = base64_encode($binary); |
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
|
|
|
|