-
Notifications
You must be signed in to change notification settings - Fork 135
/
EntityAttributesTest.php
184 lines (160 loc) · 5.81 KB
/
EntityAttributesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\SAML2\XML\mdattr;
use DateTimeImmutable;
use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML2\Utils\XPath;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\XML\saml\Attribute;
use SimpleSAML\SAML2\XML\saml\AttributeStatement;
use SimpleSAML\SAML2\XML\saml\AttributeValue;
use SimpleSAML\SAML2\XML\saml\AuthnContext;
use SimpleSAML\SAML2\XML\saml\AuthnContextClassRef;
use SimpleSAML\SAML2\XML\saml\AuthnContextDeclRef;
use SimpleSAML\SAML2\XML\saml\Audience;
use SimpleSAML\SAML2\XML\saml\AudienceRestriction;
use SimpleSAML\SAML2\XML\saml\Conditions;
use SimpleSAML\SAML2\XML\saml\Issuer;
use SimpleSAML\SAML2\XML\saml\NameID;
use SimpleSAML\SAML2\XML\saml\Subject;
use SimpleSAML\SAML2\XML\mdattr\EntityAttributes;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
use SimpleSAML\XMLSecurity\Key\PrivateKey;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use function dirname;
use function strval;
/**
* Class \SAML2\XML\mdattr\EntityAttributesTest
*
* @covers \SimpleSAML\SAML2\XML\mdattr\EntityAttributes
* @covers \SimpleSAML\SAML2\XML\mdattr\AbstractMdattrElement
* @requires PHP >= 8.1
* @package simplesamlphp/saml2
*/
final class EntityAttributesTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;
/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/sstc-metadata-attr.xsd';
self::$testedClass = EntityAttributes::class;
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/mdattr_EntityAttributes.xml',
);
}
/**
*/
public function testMarshalling(): void
{
$attribute1 = new Attribute(
name: 'attrib1',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('is'),
new AttributeValue('really'),
new AttributeValue('cool'),
],
);
// Create an Issuer
$issuer = new Issuer('testIssuer');
// Create the conditions
$conditions = new Conditions(
condition: [],
audienceRestriction: [
new AudienceRestriction([
new Audience(C::ENTITY_IDP),
new Audience(C::ENTITY_URN),
]),
],
);
// Create the statements
$attrStatement = new AttributeStatement([
new Attribute(
name: 'urn:mace:dir:attribute-def:uid',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('student2'),
],
),
new Attribute(
name: 'urn:mace:terena.org:attribute-def:schacHomeOrganization',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('university.example.org'),
new AttributeValue('bbb.cc'),
],
),
new Attribute(
name: 'urn:schac:attribute-def:schacPersonalUniqueCode',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('urn:schac:personalUniqueCode:nl:local:uvt.nl:memberid:524020'),
new AttributeValue('urn:schac:personalUniqueCode:nl:local:surfnet.nl:studentid:12345'),
],
),
new Attribute(
name: 'urn:mace:dir:attribute-def:eduPersonAffiliation',
nameFormat: C::NAMEFORMAT_URI,
attributeValue: [
new AttributeValue('member'),
new AttributeValue('student'),
],
),
]);
$subject = new Subject(new NameID(
value: 'some:entity',
Format: C::NAMEID_ENTITY,
));
// Create an assertion
$unsignedAssertion = new Assertion(
$issuer,
new DateTimeImmutable('2022-10-16T22:51:18Z'),
'_93af655219464fb403b34436cfb0c5cb1d9a5502',
$subject,
$conditions,
[$attrStatement]
);
// Sign the assertion
$signer = (new SignatureAlgorithmFactory())->getAlgorithm(
C::SIG_RSA_SHA256,
PEMCertificatesMock::getPrivateKey(PEMCertificatesMock::PRIVATE_KEY)
);
$unsignedAssertion->sign($signer);
$signedAssertion = Assertion::fromXML($unsignedAssertion->toXML());
$attribute2 = new Attribute(
name: 'foo',
nameFormat: 'urn:simplesamlphp:v1:simplesamlphp',
attributeValue: [
new AttributeValue('is'),
new AttributeValue('really'),
new AttributeValue('cool'),
],
);
$entityAttributes = new EntityAttributes([$attribute1]);
$entityAttributes->addChild($signedAssertion);
$entityAttributes->addChild($attribute2);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($entityAttributes),
);
}
/**
*/
public function testUnmarshalling(): void
{
$entityAttributes = EntityAttributes::fromXML(self::$xmlRepresentation->documentElement);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($entityAttributes),
);
}
}