44 */
55class EngineBlock_Test_Corto_Module_BindingsTest extends PHPUnit_Framework_TestCase
66{
7+ /**
8+ * @var EngineBlock_Corto_Module_Bindings
9+ */
710 private $ bindings ;
811
912 public function setup ()
1013 {
1114 $ proxyServer = Phake::mock ('EngineBlock_Corto_ProxyServer ' );
15+ $ log = Phake::mock ('EngineBlock_Log ' );
16+ Phake::when ($ proxyServer )->getSessionLog ()->thenReturn ($ log );
1217 $ this ->bindings = new EngineBlock_Corto_Module_Bindings ($ proxyServer );
1318 }
1419
@@ -26,4 +31,69 @@ public function testResponseRedirectIsNotSupported()
2631 $ remoteEntity = array ();
2732 $ this ->bindings ->send ($ message , $ remoteEntity );
2833 }
29- }
34+
35+ /**
36+ * @param string $xmlFile
37+ * @param string $certificateFile
38+ *
39+ * @dataProvider responseProvider
40+ */
41+ public function testResponseVerifies ($ xmlFile , $ certificateFile )
42+ {
43+ $ xml2array = new EngineBlock_Corto_XmlToArray ();
44+ $ xml = file_get_contents ($ xmlFile );
45+
46+ $ element = $ xml2array ->xml2array ($ xml );
47+
48+ $ publicCertificate = file_get_contents ($ certificateFile );
49+
50+ $ publicKey = openssl_pkey_get_public ($ publicCertificate );
51+
52+ if (isset ($ element ['ds:Signature ' ])) {
53+ $ this ->assertTrue (
54+ $ this ->bindings ->_verifySignatureXMLElement (
55+ $ publicKey ,
56+ $ xml ,
57+ $ element
58+ )
59+ );
60+ }
61+
62+ if (isset ($ element ['saml:Assertion ' ]['ds:Signature ' ])) {
63+ $ this ->assertTrue (
64+ $ this ->bindings ->_verifySignatureXMLElement (
65+ $ publicKey ,
66+ $ xml ,
67+ $ element ['saml:Assertion ' ]
68+ )
69+ );
70+ }
71+ }
72+
73+ /**
74+ * Provides a list of paths to response xml files and certificate files
75+ *
76+ * @return array
77+ */
78+ public function responseProvider ()
79+ {
80+ $ responseFiles = array ();
81+ $ certificateFiles = array ();
82+ $ responsesDir = new DirectoryIterator (TEST_RESOURCES_DIR . '/saml/responses ' );
83+ /** @var $responseFile DirectoryIterator */
84+ foreach ($ responsesDir as $ responseFile ) {
85+ if ($ responseFile ->isFile () && !$ responseFile ->isDot ()) {
86+ $ extension = substr ($ responseFile ->getFilename (), -3 );
87+ $ fileNameWithoutExtension = substr ($ responseFile ->getFilename (), 0 , -4 );
88+
89+ if ($ extension == 'cer ' ) {
90+ $ certificateFiles [$ fileNameWithoutExtension ] = $ responseFile ->getRealPath ();
91+ } elseif ($ extension == 'xml ' ) {
92+ $ responseFiles [$ fileNameWithoutExtension ] = $ responseFile ->getRealPath ();
93+ }
94+ }
95+ }
96+
97+ return array_merge_recursive ($ responseFiles , $ certificateFiles );
98+ }
99+ }
0 commit comments