-
Notifications
You must be signed in to change notification settings - Fork 2
/
EventSerializationAndDeserializationTest.php
235 lines (226 loc) · 9.42 KB
/
EventSerializationAndDeserializationTest.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/**
* Copyright 2016 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Surfnet\Stepup\Tests\Configuration\Event;
use Broadway\Serializer\Serializable as SerializableInterface;
use PHPUnit\Framework\TestCase;
use Rhumsaa\Uuid\Uuid;
use Surfnet\Stepup\Configuration\Configuration;
use Surfnet\Stepup\Configuration\Event\AllowedSecondFactorListUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\ConfigurationUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\EmailTemplatesUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\IdentityProvidersUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\NewConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent;
use Surfnet\Stepup\Configuration\Event\SelfVetOptionChangedEvent;
use Surfnet\Stepup\Configuration\Event\ServiceProvidersUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\ShowRaaContactInformationOptionChangedEvent;
use Surfnet\Stepup\Configuration\Event\SraaUpdatedEvent;
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent;
use Surfnet\Stepup\Configuration\Event\UseRaLocationsOptionChangedEvent;
use Surfnet\Stepup\Configuration\Event\VerifyEmailOptionChangedEvent;
use Surfnet\Stepup\Configuration\Value\AllowedSecondFactorList;
use Surfnet\Stepup\Configuration\Value\ContactInformation;
use Surfnet\Stepup\Configuration\Value\Institution;
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
use Surfnet\Stepup\Configuration\Value\Location;
use Surfnet\Stepup\Configuration\Value\NumberOfTokensPerIdentityOption;
use Surfnet\Stepup\Configuration\Value\RaLocationId;
use Surfnet\Stepup\Configuration\Value\RaLocationName;
use Surfnet\Stepup\Configuration\Value\SelfAssertedTokensOption;
use Surfnet\Stepup\Configuration\Value\SelfVetOption;
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
use Surfnet\Stepup\Configuration\Value\SsoOn2faOption;
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
use Surfnet\Stepup\Configuration\Value\VerifyEmailOption;
use Surfnet\StepupBundle\Value\SecondFactorType;
class EventSerializationAndDeserializationTest extends TestCase
{
/**
* @test
* @group domain
*
* @dataProvider institutionConfigurationEventsProvider
*/
public function an_event_should_be_the_same_after_serialization_and_deserialization(SerializableInterface $unserializedEvent)
{
$serializedEvent = $unserializedEvent->serialize();
$deserializedEvent = $unserializedEvent::deserialize($serializedEvent);
$this->assertEquals($unserializedEvent, $deserializedEvent);
}
/**
* @return SerializableInterface[]
*/
public function institutionConfigurationEventsProvider()
{
$institution = new Institution('A test institution');
$institutionConfigurationId = InstitutionConfigurationId::from($institution);
$uuid = (string)Uuid::uuid4();
return [
// Configuration
'NewConfigurationCreatedEvent' => [
new NewConfigurationCreatedEvent(
Configuration::CONFIGURATION_ID
)
],
'ConfigurationUpdatedEvent' => [
new ConfigurationUpdatedEvent(
Configuration::CONFIGURATION_ID,
['configurationKey' => 'configurationValue']
)
],
'EmailTemplatesUpdatedEvent' => [
new EmailTemplatesUpdatedEvent(
Configuration::CONFIGURATION_ID,
['template']
)
],
'IdentityProvidersUpdatedEvent' => [
new IdentityProvidersUpdatedEvent(
Configuration::CONFIGURATION_ID,
['idp']
)
],
'ServiceProvidersUpdatedEvent' => [
new ServiceProvidersUpdatedEvent(
Configuration::CONFIGURATION_ID,
['sp']
)
],
'SraaUpdatedEvent' => [
new SraaUpdatedEvent(
Configuration::CONFIGURATION_ID,
['sraa']
)
],
// InstitutionConfiguration
'NewInstitutionConfigurationCreatedEvent' => [
new NewInstitutionConfigurationCreatedEvent(
$institutionConfigurationId,
$institution,
new UseRaLocationsOption(true),
new ShowRaaContactInformationOption(true),
new VerifyEmailOption(true),
new NumberOfTokensPerIdentityOption(0),
new SsoOn2faOption(false),
new SelfVetOption(true),
new SelfAssertedTokensOption(true)
)
],
'UseRaLocationsOptionChangedEvent' => [
new UseRaLocationsOptionChangedEvent(
$institutionConfigurationId,
$institution,
new UseRaLocationsOption(true)
)
],
'ShowRaaContactInformationOptionChangedEvent' => [
new ShowRaaContactInformationOptionChangedEvent(
$institutionConfigurationId,
$institution,
new ShowRaaContactInformationOption(true)
)
],
'VerifyEmailOptionChangedEvent' => [
new VerifyEmailOptionChangedEvent(
$institutionConfigurationId,
$institution,
new VerifyEmailOption(true)
)
],
'SelfVetOptionChangedEvent' => [
new SelfVetOptionChangedEvent(
$institutionConfigurationId,
$institution,
new SelfVetOption(false)
)
],
'SsoOn2faOptionChangedEvent' => [
new SsoOn2faOptionChangedEvent(
$institutionConfigurationId,
$institution,
new SsoOn2faOption(false)
)
],
'AllowedSecondFactorListUpdatedEvent:withSecondFactors' => [
new AllowedSecondFactorListUpdatedEvent(
$institutionConfigurationId,
$institution,
AllowedSecondFactorList::ofTypes([
new SecondFactorType('yubikey'),
new SecondFactorType('sms'),
])
)
],
'AllowedSecondFactorListUpdatedEvent:blank' => [
new AllowedSecondFactorListUpdatedEvent(
$institutionConfigurationId,
$institution,
AllowedSecondFactorList::blank()
)
],
'RaLocationAddedEvent' => [
new RaLocationAddedEvent(
$institutionConfigurationId,
$institution,
new RaLocationId($uuid),
new RaLocationName('Test name'),
new Location('Test location'),
new ContactInformation('Test contact information')
)
],
'RaLocationRenamedEvent' => [
new RaLocationRenamedEvent(
$institutionConfigurationId,
new RaLocationId($uuid),
new RaLocationName('Test name')
)
],
'RaLocationRelocatedEvent' => [
new RaLocationRelocatedEvent(
$institutionConfigurationId,
new RaLocationId($uuid),
new Location('Test location')
)
],
'RaLocationContactInformationChangedEvent' => [
new RaLocationContactInformationChangedEvent(
$institutionConfigurationId,
new RaLocationId($uuid),
new ContactInformation('Test contact information')
)
],
'RaLocationRemovedEvent' => [
new RaLocationRemovedEvent(
$institutionConfigurationId,
new RaLocationId($uuid)
)
],
'InstitutionConfigurationRemovedEvent' => [
new InstitutionConfigurationRemovedEvent(
$institutionConfigurationId,
new Institution('Babelfish Inc')
)
]
];
}
}