This repository was archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponseTest.php
1718 lines (1410 loc) · 80.4 KB
/
ResponseTest.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Unit tests for Response messages
*/
class OneLogin_Saml2_ResponseTest extends PHPUnit_Framework_TestCase
{
private $_settings;
/**
* Initializes the Test Suite
*/
public function setUp()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$this->_settings = $settings;
}
/**
* Tests the OneLogin_Saml2_Response Constructor.
*
* @covers OneLogin_Saml2_Response
*/
public function testConstruct()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertTrue($response instanceof OneLogin_Saml2_Response);
$xmlEnc = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$responseEnc = new OneLogin_Saml2_Response($this->_settings, $xmlEnc);
$this->assertTrue($responseEnc instanceof OneLogin_Saml2_Response);
}
/**
* Tests that we can retrieve the raw text of an XML SAML Response
* without going through intermediate steps
*
* @covers OneLogin_Saml2_Response::getXMLDocument()
*/
public function testGetXMLDocument()
{
$encodedResponse = file_get_contents(TEST_ROOT . '/data/responses/signed_message_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $encodedResponse);
$responseDoc = new DOMDocument();
$responseDoc = OneLogin_Saml2_Utils::loadXML($responseDoc, base64_decode($encodedResponse));
$responseParsedDoc = $response->getXMLDocument();
$this->assertEquals($responseDoc, $responseParsedDoc);
$encodedResponse2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$decryptedResponse2 = file_get_contents(TEST_ROOT . '/data/responses/decrypted_valid_encrypted_assertion.xml');
$response2 = new OneLogin_Saml2_Response($this->_settings, $encodedResponse2);
$responseDoc2 = new DOMDocument();
$responseDoc2 = OneLogin_Saml2_Utils::loadXML($responseDoc2, $decryptedResponse2);
$responseParsedDoc2 = $response2->getXMLDocument();
$this->assertEquals($responseDoc2, $responseParsedDoc2);
}
/**
* Tests that we can retrieve the ID of the Response
*
* @covers OneLogin_Saml2_Response::getId()
*/
public function testGetId()
{
$encodedResponse = file_get_contents(TEST_ROOT . '/data/responses/signed_message_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $encodedResponse);
$this->assertEquals('pfxc3d2b542-0f7e-8767-8e87-5b0dc6913375', $response->getId());
}
/**
* Tests that we can retrieve the ID of the Response
*
* @covers OneLogin_Saml2_Response::getAssertionId()
*/
public function testGetAssertionId()
{
$encodedResponse = file_get_contents(TEST_ROOT . '/data/responses/signed_message_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $encodedResponse);
$this->assertEquals('_cccd6024116641fe48e0ae2c51220d02755f96c98d', $response->getAssertionId());
}
public function testNamespaces()
{
$xml = base64_encode(file_get_contents(TEST_ROOT . '/data/responses/open_saml_response.xml'));
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$attributes = $response->getAttributes();
$this->assertNotEmpty($attributes);
$this->assertEquals(array('FirstName','LastName'), array_keys($attributes));
$this->assertEquals('Someone', $attributes['FirstName'][0]);
$this->assertEquals('Special', $attributes['LastName'][0]);
}
/**
* Tests the getNameId method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getNameId
*/
public function testReturnNameId()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals('support@onelogin.com', $response->getNameId());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals('2de11defd199f8d5bb63f9b7deb265ba5c675c10', $response2->getNameId());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals('_68392312d490db6d355555cfbbd8ec95d746516f60', $response3->getNameId());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$nameId4 = $response4->getNameId();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';
$settingsInfo['security']['wantNameId'] = true;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response5 = new OneLogin_Saml2_Response($settings, $xml4);
try {
$nameId5 = $response5->getNameId();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$settingsInfo['security']['wantNameId'] = false;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response6 = new OneLogin_Saml2_Response($settings, $xml4);
$nameId6 = $response6->getNameId();
$this->assertNull($nameId6);
unset($settingsInfo['security']['wantNameId']);
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response7 = new OneLogin_Saml2_Response($settings, $xml4);
try {
$nameId7 = $response7->getNameId();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/wrong_spnamequalifier.xml.base64');
$response8 = new OneLogin_Saml2_Response($settings, $xml5);
$nameId8 = $response8->getNameId();
$this->assertEquals('492882615acf31c8096b627245d76ae53036c090', $nameId8);
$xml6 = file_get_contents(TEST_ROOT . '/data/responses/invalids/empty_nameid.xml.base64');
$response9 = new OneLogin_Saml2_Response($settings, $xml6);
$nameId9 = $response9->getNameId();
$this->assertEmpty($nameId9);
$settingsInfo['strict'] = true;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response10 = new OneLogin_Saml2_Response($settings, $xml5);
try {
$nameId10 = $response10->getNameId();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('The SPNameQualifier value mistmatch the SP entityID value.', $e->getMessage());
}
$response11 = new OneLogin_Saml2_Response($settings, $xml6);
try {
$nameId11 = $response11->getNameId();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('An empty NameID value found', $e->getMessage());
}
}
/**
* Tests the getNameIdFormat method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getNameIdFormat
*/
public function testGetNameIdFormat()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals('urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress', $response->getNameIdFormat());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', $response2->getNameIdFormat());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $response3->getNameIdFormat());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$nameId4 = $response4->getNameIdFormat();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
}
/**
* Tests the getNameIdNameQualifier method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getNameIdNameQualifier
*/
public function testGetNameIdNameQualifier()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals('https://test.example.com/saml/metadata', $response->getNameIdNameQualifier());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals(null, $response2->getNameIdNameQualifier());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals(null, $response3->getNameIdNameQualifier());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$nameId4 = $response4->getNameIdNameQualifier();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
}
/**
* Tests the getNameIdSPNameQualifier method of the Response
*
* @covers OneLogin_Saml2_Response::getNameIdSPNameQualifier
*/
public function testGetNameIdSPNameQualifier()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertNull($response->getNameIdSPNameQualifier());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals('http://stuff.com/endpoints/metadata.php', $response2->getNameIdSPNameQualifier());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals('http://stuff.com/endpoints/metadata.php', $response3->getNameIdSPNameQualifier());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/valid_response.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
$this->assertEquals('http://stuff.com/endpoints/metadata.php', $response4->getNameIdSPNameQualifier());
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64');
$response5 = new OneLogin_Saml2_Response($this->_settings, $xml5);
try {
$nameId5 = $response5->getNameIdSPNameQualifier();
$this->fail('ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
}
/**
* Tests the getNameIdData method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getNameIdData
*/
public function testGetNameIdData()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$expectedNameIdData = array (
'Value' => 'support@onelogin.com',
'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
'NameQualifier' => 'https://test.example.com/saml/metadata',
);
$nameIdData = $response->getNameIdData();
$this->assertEquals($expectedNameIdData, $nameIdData);
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$expectedNameIdData2 = array (
'Value' => '2de11defd199f8d5bb63f9b7deb265ba5c675c10',
'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
'SPNameQualifier' => 'http://stuff.com/endpoints/metadata.php'
);
$nameIdData2 = $response2->getNameIdData();
$this->assertEquals($expectedNameIdData2, $nameIdData2);
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$expectedNameIdData3 = array (
'Value' => '_68392312d490db6d355555cfbbd8ec95d746516f60',
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
'SPNameQualifier' => 'http://stuff.com/endpoints/metadata.php'
);
$nameIdData3 = $response3->getNameIdData();
$this->assertEquals($expectedNameIdData3, $nameIdData3);
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$nameIdData4 = $response4->getNameIdData();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';
$settingsInfo['security']['wantNameId'] = true;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response5 = new OneLogin_Saml2_Response($settings, $xml4);
try {
$nameIdData5 = $response5->getNameIdData();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$settingsInfo['security']['wantNameId'] = false;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response6 = new OneLogin_Saml2_Response($settings, $xml4);
$nameIdData6 = $response6->getNameIdData();
$this->assertEmpty($nameIdData6);
unset($settingsInfo['security']['wantNameId']);
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response7 = new OneLogin_Saml2_Response($settings, $xml4);
try {
$nameIdData7 = $response7->getNameIdData();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('NameID not found in the assertion of the Response', $e->getMessage());
}
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/wrong_spnamequalifier.xml.base64');
$response8 = new OneLogin_Saml2_Response($settings, $xml5);
$nameIdData8 = $response8->getNameIdData();
$expectedNameIdData8 = array(
'Value' => "492882615acf31c8096b627245d76ae53036c090",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
'SPNameQualifier' => "https://pitbulk.no-ip.org/newonelogin/demo1/metadata.php"
);
$this->assertEquals($expectedNameIdData8, $nameIdData8);
$xml6 = file_get_contents(TEST_ROOT . '/data/responses/invalids/empty_nameid.xml.base64');
$response9 = new OneLogin_Saml2_Response($settings, $xml6);
$nameIdData9 = $response9->getNameIdData();
$expectedNameIdData9 = array(
'Value' => "",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
'SPNameQualifier' => "http://stuff.com/endpoints/metadata.php"
);
$this->assertEquals($expectedNameIdData9, $nameIdData9);
$settingsInfo['strict'] = true;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$response10 = new OneLogin_Saml2_Response($settings, $xml5);
try {
$nameIdData10 = $response10->getNameIdData();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('The SPNameQualifier value mistmatch the SP entityID value.', $e->getMessage());
}
$response11 = new OneLogin_Saml2_Response($settings, $xml6);
try {
$nameIdData11 = $response11->getNameIdData();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('An empty NameID value found', $e->getMessage());
}
}
/**
* Tests the checkOneCondition method of SamlResponse
*
* @covers OneLogin_Saml2_Response::checkOneCondition
*/
public function testCheckOneCondition()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_conditions.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->checkOneCondition());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_response.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertTrue($response2->checkOneCondition());
}
/**
* Tests the checkOneAuthnStatement method of SamlResponse
*
* @covers OneLogin_Saml2_Response::checkOneAuthnStatement
*/
public function testCheckOneAuthNStatement()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_authnstatement.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->checkOneAuthnStatement());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_response.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertTrue($response2->checkOneAuthnStatement());
}
/**
* Tests the checkStatus method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::checkStatus
*/
public function testCheckStatus()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$response->checkStatus();
$xmlEnc = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$responseEnc = new OneLogin_Saml2_Response($this->_settings, $xmlEnc);
$response->checkStatus();
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/invalids/status_code_responder.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
try {
$response2->checkStatus();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('The status code of the Response was not Success, was Responder', $e->getMessage());
}
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/invalids/status_code_responer_and_msg.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
try {
$response3->checkStatus();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('The status code of the Response was not Success, was Responder -> something_is_wrong', $e->getMessage());
}
}
/**
* Tests the getAudiences method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getAudiences
*/
public function testGetAudiences()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals(array('{audience}'), $response->getAudiences());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals(array('http://stuff.com/endpoints/metadata.php'), $response2->getAudiences());
}
/**
* Tests the _queryAssertion and _query methods of the OneLogin_Saml2_Response
* using the getIssuers call
*/
public function testQueryAssertions()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/adfs_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals(array('http://login.example.com/issuer'), $response->getIssuers());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals(array('http://idp.example.com/'), $response2->getIssuers());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/double_signed_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals(array('https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php', 'http://idp.example.com/'), $response3->getIssuers());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/double_signed_response.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
$this->assertEquals(array('https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php'), $response4->getIssuers());
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/signed_message_encrypted_assertion.xml.base64');
$response5 = new OneLogin_Saml2_Response($this->_settings, $xml5);
$this->assertEquals(array('https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php', 'http://idp.example.com/'), $response5->getIssuers());
$xml6 = file_get_contents(TEST_ROOT . '/data/responses/signed_assertion_response.xml.base64');
$response6 = new OneLogin_Saml2_Response($this->_settings, $xml6);
$this->assertEquals(array('https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php'), $response6->getIssuers());
$xml7 = file_get_contents(TEST_ROOT . '/data/responses/signed_encrypted_assertion.xml.base64');
$response7 = new OneLogin_Saml2_Response($this->_settings, $xml7);
$this->assertEquals(array('http://idp.example.com/'), $response7->getIssuers());
}
/**
* Tests the getIssuers method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getIssuers
*/
public function testGetIssuers()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/adfs_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals(array('http://login.example.com/issuer'), $response->getIssuers());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals(array('http://idp.example.com/'), $response2->getIssuers());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/double_signed_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals(array('https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php', 'http://idp.example.com/'), $response3->getIssuers());
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_issuer_response.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
$issuers = $response4->getIssuers();
$this->assertEquals(array('http://idp.example.com/'), $response4->getIssuers());
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_issuer_assertion.xml.base64');
$response5 = new OneLogin_Saml2_Response($this->_settings, $xml5);
try {
$issuers = $response5->getIssuers();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('Issuer of the Assertion not found or multiple.', $e->getMessage());
}
}
/**
* Tests the getSessionIndex method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getSessionIndex
*/
public function testGetSessionIndex()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals('_531c32d283bdff7e04e487bcdbc4dd8d', $response->getSessionIndex());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEquals('_7164a9a9f97828bfdb8d0ebc004a05d2e7d873f70c', $response2->getSessionIndex());
}
/**
* Tests the getAttributes method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getAttributes
*/
public function testGetAttributes()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$expectedAttributes = array(
'uid' => array(
'demo'
),
'another_value' => array(
'value'
),
);
$this->assertEquals($expectedAttributes, $response->getAttributes());
// An assertion that has no attributes should return an empty array when asked for the attributes
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response2.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEmpty($response2->getAttributes());
// Encrypted Attributes are not supported
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/invalids/encrypted_attrs.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEmpty($response3->getAttributes());
// Duplicated Attribute names
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/duplicated_attributes.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$attrs = $response4->getAttributes();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('Found an Attribute element with duplicated Name', $e->getMessage());
}
}
/**
* Tests the getAttributes method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getAttributes
*/
public function testGetAttributesWithFriendlyName()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response6.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$expectedAttributes = array(
'uid' => array(
'demo'
),
'givenName' => array(
'value'
),
);
$this->assertEquals($expectedAttributes, $response->getAttributesWithFriendlyName());
// An assertion that has no attributes should return an empty array when asked for the attributes
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response2.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertEmpty($response2->getAttributesWithFriendlyName());
// Encrypted Attributes are not supported
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/invalids/encrypted_attrs.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEmpty($response3->getAttributesWithFriendlyName());
// Duplicated Attribute names
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/duplicated_attributes_with_friendly_names.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$attrs = $response4->getAttributesWithFriendlyName();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertContains('Found an Attribute element with duplicated FriendlyName', $e->getMessage());
}
}
/**
* Tests the getNameId method of the OneLogin_Saml2_Response
*
* The Assertion is unsigned, the response is invalid but is able to retrieve the NameID
*
* @covers OneLogin_Saml2_Response::getNameId
*/
public function testOnlyRetrieveAssertionWithIDThatMatchesSignatureReference()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/wrapped_response_2.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$nameId = $response->getNameId();
$this->assertFalse($response->isValid());
$this->assertEquals('root@example.com', $nameId);
}
/**
* Tests the getError method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getError
*/
public function testGetError()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response4.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertNull($response->getError());
$this->assertFalse($response->isValid());
$this->assertEquals('SAML Response must contain 1 assertion', $response->getError());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_response.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertTrue($response2->isValid());
$this->assertNull($response2->getError());
}
/**
* Tests the getNameId method of the OneLogin_Saml2_Response
*
* Test that the SignatureWrappingAttack is not allowed
*
* @covers OneLogin_Saml2_Response::getNameId
*/
public function testDoesNotAllowSignatureWrappingAttack()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response4.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals('test@onelogin.com', $response->getNameId());
$this->assertFalse($response->isValid());
$this->assertEquals('SAML Response must contain 1 assertion', $response->getError());
}
public function testDoesNotAllowSignatureWrappingAttack2()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';
unset($settingsInfo['idp']['x509cert']);
$settingsInfo['strict'] = false;
$settingsInfo['idp']['certFingerprint'] = "385b1eec71143f00db6af936e2ea12a28771d72c";
$settingsInfo['sp']['privateKey'] = 'MIICXAIBAAKBgQDo6m+QZvYQ/xL0ElLgupK1QDcYL4f5PckwsNgS9pUvV7fzTqCHk8ThLxTk42MQ2McJsOeUJVP728KhymjFCqxgP4VuwRk9rpAl0+mhy6MPdyjyA6G14jrDWS65ysLchK4t/vwpEDz0SQlEoG1kMzllSm7zZS3XregA7DjNaUYQqwIDAQABAoGBALGR6bRBit+yV5TUU3MZSrf8WQSLWDLgs/33FQSAEYSib4+DJke2lKbI6jkGUoSJgFUXFbaQLtMY2+3VDsMKPBdAge9gIdvbkC4yoKjLGm/FBDOxxZcfLpR+9OPqU3qM9D0CNuliBWI7Je+p/zs09HIYucpDXy9E18KA1KNF6rfhAkEA9KoNam6wAKnmvMzz31ws3RuIOUeo2rx6aaVY95+P9tTxd6U+pNkwxy1aCGP+InVSwlYNA1aQ4Axi/GdMIWMkxwJBAPO1CP7cQNZQmu7yusY+GUObDII5YK9WLaY4RAicn5378crPBFxvUkqf9G6FHo7u88iTCIp+vwa3Hn9Tumg3iP0CQQDgUXWBasCVqzCxU5wY4tMDWjXYhpoLCpmVeRML3dDJt004rFm2HKe7Rhpw7PTZNQZOxUSjFeA4e0LaNf838UWLAkB8QfbHM3ffjhOg96PhhjINdVWoZCb230LBOHj/xxPfUmFTHcBEfQIBSJMxcrBFAnLL9qPpMXymqOFk3ETz9DTlAj8E0qGbp78aVbTOtuwEwNJII+RPw+Zkc+lKR+yaWkAzfIXw527NPHH3+rnBG72wyZr9ud4LAum9jh+5No1LQpk=';
$settingsInfo['sp']['x509cert'] = 'MIICGzCCAYQCCQCNNcQXom32VDANBgkqhkiG9w0BAQUFADBSMQswCQYDVQQGEwJVUzELMAkGA1UECBMCSU4xFTATBgNVBAcTDEluZGlhbmFwb2xpczERMA8GA1UEChMIT25lTG9naW4xDDAKBgNVBAsTA0VuZzAeFw0xNDA0MjMxODQxMDFaFw0xNTA0MjMxODQxMDFaMFIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJJTjEVMBMGA1UEBxMMSW5kaWFuYXBvbGlzMREwDwYDVQQKEwhPbmVMb2dpbjEMMAoGA1UECxMDRW5nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo6m+QZvYQ/xL0ElLgupK1QDcYL4f5PckwsNgS9pUvV7fzTqCHk8ThLxTk42MQ2McJsOeUJVP728KhymjFCqxgP4VuwRk9rpAl0+mhy6MPdyjyA6G14jrDWS65ysLchK4t/vwpEDz0SQlEoG1kMzllSm7zZS3XregA7DjNaUYQqwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBALM2vGCiQ/vm+a6v40+VX2zdqHA2Q/1vF1ibQzJ54MJCOVWvs+vQXfZFhdm0OPM2IrDU7oqvKPqP6xOAeJK6H0yP7M4YL3fatSvIYmmfyXC9kt3Svz/NyrHzPhUnJ0ye/sUSXxnzQxwcm/9PwAqrQaA3QpQkH57ybF/OoryPe+2h';
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$xml = file_get_contents(TEST_ROOT . '/data/responses/wrapped_response_3.xml.base64');
$response = new OneLogin_Saml2_Response($settings, $xml);
$valid = $response->isValid();
$this->assertFalse($valid);
}
/**
* Tests the getNameId and getAttributes methods of the
* OneLogin_Saml2_Response
*
* Test that the node text with comment attack (VU#475445)
* is not allowed
*
* @covers OneLogin_Saml2_Response::getNameId
* @covers OneLogin_Saml2_Response::getAttributes
*/
public function testNodeTextAttack()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response_node_text_attack.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$nameId = $response->getNameId();
$attributes = $response->getAttributes();
$this->assertEquals("support@onelogin.com", $nameId);
$this->assertEquals("smith", $attributes['surname'][0]);
}
/**
* Tests the getSessionNotOnOrAfter method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::getSessionNotOnOrAfter
*/
public function testGetSessionNotOnOrAfter()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertEquals(1290203857, $response->getSessionNotOnOrAfter());
// An assertion that do not specified Session timeout should return NULL
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/response2.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertNull($response2->getSessionNotOnOrAfter());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
$this->assertEquals(2696012228, $response3->getSessionNotOnOrAfter());
}
/**
* Tests the validateNumAssertions method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::validateNumAssertions
*/
public function testValidateNumAssertions()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertTrue($response->validateNumAssertions());
$xmlMultiAssertion = file_get_contents(TEST_ROOT . '/data/responses/invalids/multiple_assertions.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xmlMultiAssertion);
$this->assertFalse($response2->validateNumAssertions());
}
/**
* Tests the validateTimestamps method of the OneLogin_Saml2_Response
*
* @covers OneLogin_Saml2_Response::validateTimestamps
*/
public function testValidateTimestamps()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/valid_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertTrue($response->validateTimestamps());
$xml2 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64');
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml2);
$this->assertTrue($response2->validateTimestamps());
$xml3 = file_get_contents(TEST_ROOT . '/data/responses/expired_response.xml.base64');
$response3 = new OneLogin_Saml2_Response($this->_settings, $xml3);
try {
$response3->validateTimestamps();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertEquals($e->getMessage(), 'Could not validate timestamp: expired. Check system clock.');
}
$xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/not_after_failed.xml.base64');
$response4 = new OneLogin_Saml2_Response($this->_settings, $xml4);
try {
$response4->validateTimestamps();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertEquals($e->getMessage(), 'Could not validate timestamp: expired. Check system clock.');
}
$xml5 = file_get_contents(TEST_ROOT . '/data/responses/invalids/not_before_failed.xml.base64');
$response5 = new OneLogin_Saml2_Response($this->_settings, $xml5);
try {
$response5->validateTimestamps();
$this->fail('OneLogin_Saml2_ValidationError was not raised');
} catch (OneLogin_Saml2_ValidationError $e) {
$this->assertEquals($e->getMessage(), 'Could not validate timestamp: not yet valid. Check system clock.');
}
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid version
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testValidateVersion()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_saml2.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('Unsupported SAML version', $response->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid no ID
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testValidateID()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_id.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('Missing ID attribute on SAML Response', $response->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid reference
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidReference()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('Reference validation failed', $response->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case expired response
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidExpired()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/expired_response.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertTrue($response->isValid());
$this->_settings->setStrict(true);
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response2->isValid());
$this->assertEquals('Could not validate timestamp: expired. Check system clock.', $response2->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case no key
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidNoKey()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_key.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('We have no idea about the key', $response->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid multiple assertions
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidMultipleAssertions()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/multiple_assertions.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('SAML Response must contain 1 assertion', $response->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid Encrypted Attrs
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidEncAttrs()
{
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/encrypted_attrs.xml.base64');
$response = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response->isValid());
$this->assertEquals('No Signature found. SAML Response rejected', $response->getError());
$this->_settings->setStrict(true);
$response2 = new OneLogin_Saml2_Response($this->_settings, $xml);
$this->assertFalse($response2->isValid());
$this->assertEquals('There is an EncryptedAttribute in the Response and this SP not support them', $response2->getError());
}
/**
* Tests the isValid method of the OneLogin_Saml2_Response
* Case invalid xml
*
* @covers OneLogin_Saml2_Response::isValid
*/
public function testIsInValidWrongXML()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';
$settingsInfo['security']['wantXMLValidation'] = false;
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$settings->setStrict(false);
$xml = file_get_contents(TEST_ROOT . '/data/responses/invalids/invalid_xml.xml.base64');
$response = new OneLogin_Saml2_Response($settings, $xml);
$this->assertTrue($response->isValid());
$settings->setStrict(true);
$response2 = new OneLogin_Saml2_Response($settings, $xml);
$response2->isValid();
$this->assertNotEquals('Invalid SAML Response. Not match the saml-schema-protocol-2.0.xsd', $response2->getError());
$settingsInfo['security']['wantXMLValidation'] = true;
$settings2 = new OneLogin_Saml2_Settings($settingsInfo);
$settings2->setStrict(false);
$response3 = new OneLogin_Saml2_Response($settings2, $xml);
$this->assertTrue($response3->isValid());
$settings2->setStrict(true);