Passed
Pull Request — master (#57)
by Tim
02:12
created

DHKeyValueTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMarshallingElementOrder() 0 35 1
A setUpBeforeClass() 0 8 1
A testMarshalling() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Test\XML\xenc;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\Assert\AssertionFailedException;
10
use SimpleSAML\XML\DOMDocumentFactory;
11
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
12
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
14
use SimpleSAML\XMLSecurity\Utils\XPath;
15
use SimpleSAML\XMLSecurity\XML\xenc\AbstractDHKeyValueType;
16
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
17
use SimpleSAML\XMLSecurity\XML\xenc\DHKeyValue;
18
use SimpleSAML\XMLSecurity\XML\xenc\Generator;
19
use SimpleSAML\XMLSecurity\XML\xenc\P;
20
use SimpleSAML\XMLSecurity\XML\xenc\PgenCounter;
21
use SimpleSAML\XMLSecurity\XML\xenc\Q;
22
use SimpleSAML\XMLSecurity\XML\xenc\Seed;
23
use SimpleSAML\XMLSecurity\XML\xenc\XencPublic;
24
25
use function dirname;
26
use function strval;
27
28
/**
29
 * Class \SimpleSAML\XMLSecurity\Test\XML\xenc\DHKeyValueTest
30
 *
31
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
32
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractDHKeyValueType
33
 * @covers \SimpleSAML\XMLSecurity\XML\xenc\DHKeyValue
34
 *
35
 * @package simplesamlphp/xml-security
36
 */
37
#[CoversClass(AbstractXencElement::class)]
38
#[CoversClass(AbstractDHKeyValueType::class)]
39
#[CoversClass(DHKeyValue::class)]
40
final class DHKeyValueTest extends TestCase
41
{
42
    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...XML\xenc\DHKeyValueTest: $documentElement, $ownerDocument, $message, $line
Loading history...
43
    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...XML\xenc\DHKeyValueTest.
Loading history...
44
45
    /**
46
     */
47
    public static function setUpBeforeClass(): void
48
    {
49
        self::$testedClass = DHKeyValue::class;
50
51
        self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xenc-schema.xsd';
52
53
        self::$xmlRepresentation = DOMDocumentFactory::fromFile(
54
            dirname(__FILE__, 3) . '/resources/xml/xenc_DHKeyValue.xml',
55
        );
56
    }
57
58
59
    /**
60
     */
61
    public function testMarshalling(): void
62
    {
63
        $xencPublic = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
64
        $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
65
        $q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
66
        $generator = new Generator('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
67
        $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
68
        $pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
69
70
        $dhKeyValue = new DHKeyValue($xencPublic, $p, $q, $generator, $seed, $pgenCounter);
71
72
        $this->assertEquals(
73
            self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
74
            strval($dhKeyValue),
75
        );
76
    }
77
    /**
78
     */
79
    public function testMarshallingElementOrder(): void
80
    {
81
        $xencPublic = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
82
        $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
83
        $q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
84
        $generator = new Generator('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
85
        $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
86
        $pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
87
88
        $dhKeyValue = new DHKeyValue($xencPublic, $p, $q, $generator, $seed, $pgenCounter);
89
90
        // Marshall it to a \DOMElement
91
        $dhKeyValueElement = $dhKeyValue->toXML();
92
93
        $xpCache = XPath::getXPath($dhKeyValueElement);
94
95
        // Test for an P
96
        /** @var \DOMElement[] $kaNonceElements */
97
        $pElements = XPath::xpQuery($dhKeyValueElement, './xenc:P', $xpCache);
98
        $this->assertCount(1, $pElements);
99
100
        // Test ordering of DHKeyValue contents
101
        /** @var \DOMElement[] $dhKeyValueElements */
102
        $dhKeyValueElements = XPath::xpQuery(
103
            $dhKeyValueElement,
104
            './xenc:P/following-sibling::*',
105
            $xpCache,
106
        );
107
108
        $this->assertCount(5, $dhKeyValueElements);
109
        $this->assertEquals('xenc:Q', $dhKeyValueElements[0]->tagName);
110
        $this->assertEquals('xenc:Generator', $dhKeyValueElements[1]->tagName);
111
        $this->assertEquals('xenc:Public', $dhKeyValueElements[2]->tagName);
112
        $this->assertEquals('xenc:seed', $dhKeyValueElements[3]->tagName);
113
        $this->assertEquals('xenc:pgenCounter', $dhKeyValueElements[4]->tagName);
114
    }
115
}
116