test_invalid_transient_format_empty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.8333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LightSaml\Tests\Validator\Model\NameId;
4
5
use LightSaml\Model\Assertion\NameID;
6
use LightSaml\SamlConstants;
7
use LightSaml\Tests\BaseTestCase;
8
use LightSaml\Validator\Model\NameId\NameIdValidator;
9
10
class NameIdValidatorTest extends BaseTestCase
11
{
12
    public function test_ok_if_no_format()
13
    {
14
        $nameId = new NameID();
15
16
        $validator = new NameIdValidator();
17
18
        $validator->validateNameId($nameId);
19
20
        $this->assertTrue(true);
21
    }
22
23
    public function test_invalid_format()
24
    {
25
        $this->expectExceptionMessage("NameID element has Format attribute 'invalid format' which is not a wellformed absolute uri");
26
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
27
        $nameId = new NameID();
28
        $nameId->setFormat('invalid format');
29
30
        $validator = new NameIdValidator();
31
32
        $validator->validateNameId($nameId);
33
34
        $this->assertTrue(true);
35
    }
36
37
    public function test_valid_email_format()
38
    {
39
        $nameId = new NameID();
40
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_EMAIL)
41
            ->setValue('[email protected]');
42
43
        $validator = new NameIdValidator();
44
45
        $validator->validateNameId($nameId);
46
47
        $this->assertTrue(true);
48
    }
49
50
    public function test_invalid_email_format()
51
    {
52
        $this->expectExceptionMessage("Value of NameID is not a valid email address according to the IETF RFC 2822 specification");
53
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
54
        $nameId = new NameID();
55
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_EMAIL)
56
            ->setValue('not_an_email');
57
58
        $validator = new NameIdValidator();
59
60
        $validator->validateNameId($nameId);
61
62
        $this->assertTrue(true);
63
    }
64
65
    public function test_empty_email_format()
66
    {
67
        $this->expectExceptionMessage("NameID with Email Format attribute MUST contain a Value that contains more than whitespace characters");
68
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
69
        $nameId = new NameID();
70
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_EMAIL);
71
72
        $validator = new NameIdValidator();
73
74
        $validator->validateNameId($nameId);
75
76
        $this->assertTrue(true);
77
    }
78
79
    public function test_valid_x509_subject_format()
80
    {
81
        $nameId = new NameID();
82
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_X509_SUBJECT_NAME)
83
            ->setValue('CN=mt.evo.team,O=BOS,C=RS');
84
85
        $validator = new NameIdValidator();
86
87
        $validator->validateNameId($nameId);
88
89
        $this->assertTrue(true);
90
    }
91
92
    public function test_empty_x509_subject_format()
93
    {
94
        $this->expectExceptionMessage("NameID with X509SubjectName Format attribute MUST contain a Value that contains more than whitespace characters");
95
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
96
        $nameId = new NameID();
97
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_X509_SUBJECT_NAME);
98
99
        $validator = new NameIdValidator();
100
101
        $validator->validateNameId($nameId);
102
103
        $this->assertTrue(true);
104
    }
105
106
    public function test_valid_windows_format_with_domain()
107
    {
108
        $nameId = new NameID();
109
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_WINDOWS)
110
            ->setValue('DomainName\UserName');
111
112
        $validator = new NameIdValidator();
113
114
        $validator->validateNameId($nameId);
115
116
        $this->assertTrue(true);
117
    }
118
119
    public function test_valid_windows_format_with_out_domain()
120
    {
121
        $nameId = new NameID();
122
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_WINDOWS)
123
            ->setValue('UserName');
124
125
        $validator = new NameIdValidator();
126
127
        $validator->validateNameId($nameId);
128
129
        $this->assertTrue(true);
130
    }
131
132
    public function test_empty_windows_format()
133
    {
134
        $this->expectExceptionMessage("NameID with Windows Format attribute MUST contain a Value that contains more than whitespace characters");
135
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
136
        $nameId = new NameID();
137
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_WINDOWS);
138
139
        $validator = new NameIdValidator();
140
141
        $validator->validateNameId($nameId);
142
143
        $this->assertTrue(true);
144
    }
145
146
    public function test_valid_kerberos_format_full()
147
    {
148
        $nameId = new NameID();
149
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS)
150
            ->setValue('name/instance@REALM');
151
152
        $validator = new NameIdValidator();
153
154
        $validator->validateNameId($nameId);
155
156
        $this->assertTrue(true);
157
    }
158
159
    public function test_valid_kerberos_format_short()
160
    {
161
        $nameId = new NameID();
162
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS)
163
            ->setValue('name@REALM');
164
165
        $validator = new NameIdValidator();
166
167
        $validator->validateNameId($nameId);
168
169
        $this->assertTrue(true);
170
    }
171
172
    public function test_invalid_kerberos_format()
173
    {
174
        $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value that contains a '@'");
175
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
176
        $nameId = new NameID();
177
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS)
178
            ->setValue('name');
179
180
        $validator = new NameIdValidator();
181
182
        $validator->validateNameId($nameId);
183
184
        $this->assertTrue(true);
185
    }
186
187
    public function test_invalid_kerberos_format_short()
188
    {
189
        $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value with at least 3 characters");
190
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
191
        $nameId = new NameID();
192
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS)
193
            ->setValue('a@');
194
195
        $validator = new NameIdValidator();
196
197
        $validator->validateNameId($nameId);
198
199
        $this->assertTrue(true);
200
    }
201
202
    public function test_invalid_kerberos_format_empty()
203
    {
204
        $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value that contains more than whitespace characters");
205
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
206
        $nameId = new NameID();
207
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS);
208
209
        $validator = new NameIdValidator();
210
211
        $validator->validateNameId($nameId);
212
213
        $this->assertTrue(true);
214
    }
215
216
    public function test_valid_entity_format()
217
    {
218
        $nameId = new NameID();
219
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY)
220
            ->setValue('some:entity');
221
222
        $validator = new NameIdValidator();
223
224
        $validator->validateNameId($nameId);
225
226
        $this->assertTrue(true);
227
    }
228
229
    public function test_invalid_entity_format_empty()
230
    {
231
        $this->expectExceptionMessage("NameID with Entity Format attribute MUST contain a Value that contains more than whitespace characters");
232
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
233
        $nameId = new NameID();
234
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY);
235
236
        $validator = new NameIdValidator();
237
238
        $validator->validateNameId($nameId);
239
240
        $this->assertTrue(true);
241
    }
242
243 View Code Duplication
    public function test_invalid_entity_format_long()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
244
    {
245
        $this->expectExceptionMessage("NameID with Entity Format attribute MUST have a Value that contains no more than 1024 characters");
246
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
247
        $nameId = new NameID();
248
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY)
249
            ->setValue(str_pad('long_string', 1030, 'x'));
250
251
        $validator = new NameIdValidator();
252
253
        $validator->validateNameId($nameId);
254
255
        $this->assertTrue(true);
256
    }
257
258 View Code Duplication
    public function test_invalid_entity_format_with_name_qualifier()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
259
    {
260
        $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the NameQualifier attribute");
261
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
262
        $nameId = new NameID();
263
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY)
264
            ->setValue('some:entity')
265
            ->setNameQualifier('name:qualifier');
266
267
        $validator = new NameIdValidator();
268
269
        $validator->validateNameId($nameId);
270
271
        $this->assertTrue(true);
272
    }
273
274 View Code Duplication
    public function test_invalid_entity_format_with_sp_name_qualifier()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
275
    {
276
        $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the SPNameQualifier attribute");
277
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
278
        $nameId = new NameID();
279
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY)
280
            ->setValue('some:entity')
281
            ->setSPNameQualifier('sp:name:qualifier');
282
283
        $validator = new NameIdValidator();
284
285
        $validator->validateNameId($nameId);
286
287
        $this->assertTrue(true);
288
    }
289
290 View Code Duplication
    public function test_invalid_entity_format_with_sp_provided_id()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
291
    {
292
        $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the SPProvidedID attribute");
293
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
294
        $nameId = new NameID();
295
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY)
296
            ->setValue('some:entity')
297
            ->setSPProvidedID('sp:provided:id');
298
299
        $validator = new NameIdValidator();
300
301
        $validator->validateNameId($nameId);
302
303
        $this->assertTrue(true);
304
    }
305
306
    public function test_valid_persistent_format()
307
    {
308
        $nameId = new NameID();
309
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT)
310
            ->setValue('12345678');
311
312
        $validator = new NameIdValidator();
313
314
        $validator->validateNameId($nameId);
315
316
        $this->assertTrue(true);
317
    }
318
319 View Code Duplication
    public function test_valid_persistent_format_with_other_attributes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
320
    {
321
        $nameId = new NameID();
322
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT)
323
            ->setValue('12345678')
324
            ->setSPProvidedID('sp:provided:id')
325
            ->setSPNameQualifier('sp:name:qualifier')
326
            ->setNameQualifier('name:qualifier')
327
        ;
328
329
        $validator = new NameIdValidator();
330
331
        $validator->validateNameId($nameId);
332
333
        $this->assertTrue(true);
334
    }
335
336
    public function test_invalid_persistent_format_empty()
337
    {
338
        $this->expectExceptionMessage("NameID with Persistent Format attribute MUST contain a Value that contains more than whitespace characters");
339
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
340
        $nameId = new NameID();
341
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT);
342
343
        $validator = new NameIdValidator();
344
345
        $validator->validateNameId($nameId);
346
347
        $this->assertTrue(true);
348
    }
349
350 View Code Duplication
    public function test_invalid_persistent_format_long()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
351
    {
352
        $this->expectExceptionMessage("NameID with Persistent Format attribute MUST have a Value that contains no more than 256 characters");
353
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
354
        $nameId = new NameID();
355
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT)
356
            ->setValue(str_pad('a', 260, 'x'));
357
358
        $validator = new NameIdValidator();
359
360
        $validator->validateNameId($nameId);
361
362
        $this->assertTrue(true);
363
    }
364
365
    public function test_valid_transient_format()
366
    {
367
        $nameId = new NameID();
368
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT)
369
            ->setValue('1234567890123456');
370
371
        $validator = new NameIdValidator();
372
373
        $validator->validateNameId($nameId);
374
375
        $this->assertTrue(true);
376
    }
377
378 View Code Duplication
    public function test_valid_transient_format_with_other_attributes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
    {
380
        $nameId = new NameID();
381
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT)
382
            ->setValue('1234567890123456')
383
            ->setSPProvidedID('sp:provided:id')
384
            ->setSPNameQualifier('sp:name:qualifier')
385
            ->setNameQualifier('name:qualifier')
386
        ;
387
388
        $validator = new NameIdValidator();
389
390
        $validator->validateNameId($nameId);
391
392
        $this->assertTrue(true);
393
    }
394
395
    public function test_invalid_transient_format_empty()
396
    {
397
        $this->expectExceptionMessage("NameID with Transient Format attribute MUST contain a Value that contains more than whitespace characters");
398
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
399
        $nameId = new NameID();
400
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT);
401
402
        $validator = new NameIdValidator();
403
404
        $validator->validateNameId($nameId);
405
406
        $this->assertTrue(true);
407
    }
408
409 View Code Duplication
    public function test_invalid_transient_format_long()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
410
    {
411
        $this->expectExceptionMessage("NameID with Transient Format attribute MUST have a Value that contains no more than 256 characters");
412
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
413
        $nameId = new NameID();
414
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT)
415
            ->setValue(str_pad('a', 260, 'x'));
416
417
        $validator = new NameIdValidator();
418
419
        $validator->validateNameId($nameId);
420
421
        $this->assertTrue(true);
422
    }
423
424
    public function test_invalid_transient_format_short()
425
    {
426
        $this->expectExceptionMessage("NameID '123456789012345' with Transient Format attribute MUST have a Value with at least 16 characters (the equivalent of 128 bits)");
427
        $this->expectException(\LightSaml\Error\LightSamlValidationException::class);
428
        $nameId = new NameID();
429
        $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT)
430
            ->setValue('123456789012345');
431
432
        $validator = new NameIdValidator();
433
434
        $validator->validateNameId($nameId);
435
436
        $this->assertTrue(true);
437
    }
438
}
439