Passed
Push — master ( be09b3...67068d )
by Tim
13:28
created

X509DigestTest::testUnmarshalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\dsig11;
6
7
use PHPUnit\Framework\TestCase;
8
use SimpleSAML\XML\DOMDocumentFactory;
9
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
10
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11
use SimpleSAML\XMLSecurity\Constants as C;
12
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM;
13
use SimpleSAML\XMLSecurity\Key;
14
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
15
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
16
use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest;
17
18
use function base64_encode;
19
use function dirname;
20
use function hex2bin;
21
use function strval;
22
23
/**
24
 * Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\X509DigestTest
25
 *
26
 * @covers \SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element
27
 * @covers \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest
28
 *
29
 * @package simplesamlphp/xml-security
30
 */
31
final class X509DigestTest extends TestCase
32
{
33
    use SchemaValidationTestTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TestUtils\SchemaValidationTestTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\T...L\dsig11\X509DigestTest: $documentElement, $ownerDocument, $message, $line
Loading history...
34
    use SerializableElementTestTrait;
0 ignored issues
show
Bug introduced by
The trait SimpleSAML\XML\TestUtils...lizableElementTestTrait requires the property $documentElement which is not provided by SimpleSAML\XMLSecurity\T...L\dsig11\X509DigestTest.
Loading history...
35
36
    /** @var string */
37
    private static string $digest;
38
39
40
    /**
41
     */
42
    public static function setUpBeforeClass(): void
43
    {
44
        self::$testedClass = X509Digest::class;
45
46
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig11-schema.xsd';
47
48
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
49
            dirname(__FILE__, 3) . '/resources/xml/dsig11_X509Digest.xml',
50
        );
51
52
        $key = new Key\X509Certificate(PEM::fromString(PEMCertificatesMock::getPlainCertificate()));
53
        self::$digest = base64_encode(hex2bin($key->getRawThumbprint(C::DIGEST_SHA256)));
54
    }
55
56
57
    /**
58
     */
59
    public function testMarshalling(): void
60
    {
61
        $x509digest = new X509Digest(self::$digest, C::DIGEST_SHA256);
62
63
        $this->assertEquals(
64
            XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
65
            strval($x509digest),
66
        );
67
    }
68
}
69