1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\XMLSecurity\Test\XML\xenc; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\XML\Chunk; |
10
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
11
|
|
|
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
12
|
|
|
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; |
13
|
|
|
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; |
14
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; |
15
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; |
16
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\KeyName; |
17
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; |
18
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509Data; |
19
|
|
|
use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; |
20
|
|
|
use SimpleSAML\XMLSecurity\XML\xenc\OriginatorKeyInfo; |
21
|
|
|
|
22
|
|
|
use function dirname; |
23
|
|
|
use function openssl_x509_parse; |
24
|
|
|
use function str_replace; |
25
|
|
|
use function strval; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\OriginatorKeyInfoTest |
29
|
|
|
* |
30
|
|
|
* @package simplesamlphp/xml-security |
31
|
|
|
*/ |
32
|
|
|
#[CoversClass(AbstractDsElement::class)] |
33
|
|
|
#[CoversClass(AbstractKeyInfoType::class)] |
34
|
|
|
#[CoversClass(OriginatorKeyInfo::class)] |
35
|
|
|
final class OriginatorKeyInfoTest extends TestCase |
36
|
|
|
{ |
37
|
|
|
use SerializableElementTestTrait; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** @var string */ |
40
|
|
|
private static string $certificate; |
41
|
|
|
|
42
|
|
|
/** @var string[] */ |
43
|
|
|
private static array $certData; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
*/ |
48
|
|
|
public function setUp(): void |
49
|
|
|
{ |
50
|
|
|
self::$testedClass = OriginatorKeyInfo::class; |
51
|
|
|
|
52
|
|
|
self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
53
|
|
|
dirname(__FILE__, 3) . '/resources/xml/xenc_OriginatorKeyInfo.xml', |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
self::$certificate = str_replace( |
57
|
|
|
[ |
58
|
|
|
'-----BEGIN CERTIFICATE-----', |
59
|
|
|
'-----END CERTIFICATE-----', |
60
|
|
|
'-----BEGIN RSA PUBLIC KEY-----', |
61
|
|
|
'-----END RSA PUBLIC KEY-----', |
62
|
|
|
"\r\n", |
63
|
|
|
"\n", |
64
|
|
|
], |
65
|
|
|
[ |
66
|
|
|
'', |
67
|
|
|
'', |
68
|
|
|
'', |
69
|
|
|
'', |
70
|
|
|
"\n", |
71
|
|
|
'', |
72
|
|
|
], |
73
|
|
|
PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE), |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
self::$certData = openssl_x509_parse( |
77
|
|
|
PEMCertificatesMock::getPlainCertificate(PEMCertificatesMock::SELFSIGNED_CERTIFICATE), |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
*/ |
84
|
|
|
public function testMarshalling(): void |
85
|
|
|
{ |
86
|
|
|
$originatorKeyInfo = new OriginatorKeyInfo( |
87
|
|
|
[ |
88
|
|
|
new KeyName('testkey'), |
89
|
|
|
new X509Data( |
90
|
|
|
[ |
91
|
|
|
new X509Certificate(self::$certificate), |
92
|
|
|
new X509SubjectName(self::$certData['name']), |
93
|
|
|
], |
94
|
|
|
), |
95
|
|
|
new Chunk(DOMDocumentFactory::fromString( |
96
|
|
|
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>', |
97
|
|
|
)->documentElement), |
98
|
|
|
], |
99
|
|
|
'fed654', |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->assertEquals( |
103
|
|
|
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
104
|
|
|
strval($originatorKeyInfo), |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
*/ |
111
|
|
|
public function testMarshallingEmpty(): void |
112
|
|
|
{ |
113
|
|
|
$this->expectException(InvalidArgumentException::class); |
114
|
|
|
$this->expectExceptionMessage('xenc:OriginatorKeyInfo cannot be empty'); |
115
|
|
|
|
116
|
|
|
new OriginatorKeyInfo([]); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
*/ |
122
|
|
|
public function testUnmarshallingEmpty(): void |
123
|
|
|
{ |
124
|
|
|
$document = DOMDocumentFactory::fromString( |
125
|
|
|
'<xenc:OriginatorKeyInfo xmlns:xenc="' . OriginatorKeyInfo::NS . '"/>', |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$this->expectException(InvalidArgumentException::class); |
129
|
|
|
$this->expectExceptionMessage('xenc:OriginatorKeyInfo cannot be empty'); |
130
|
|
|
|
131
|
|
|
OriginatorKeyInfo::fromXML($document->documentElement); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths