Browse Source

Make SSL context fixes backwards compatible.

The external callers of the stream wrapper don't need to know that some
of the context options are for SSL and some are for HTTP. We can merge
the two lists and let the internals of the class keep the two separate.

Refs #6386
Mark Story 11 years ago
parent
commit
476ac29702

+ 6 - 6
src/Network/Http/Adapter/Stream.php

@@ -127,7 +127,10 @@ class Stream
         if ($scheme === 'https') {
             $this->_buildSslContext($request, $options);
         }
-        $this->_context = stream_context_create($this->contextOptions());
+        $this->_context = stream_context_create([
+            'http' => $this->_contextOptions,
+            'ssl' => $this->_sslContextOptions,
+        ]);
     }
 
     /**
@@ -226,7 +229,7 @@ class Stream
             'ssl_passphrase',
         ];
         if (empty($options['ssl_cafile'])) {
-            $options['ssl_cafile'] = CAKE . 'Config' . DS . 'cacert.pem';
+            $options['ssl_cafile'] = CAKE . 'config' . DS . 'cacert.pem';
         }
         if (!empty($options['ssl_verify_host'])) {
             $url = $request->url();
@@ -309,9 +312,6 @@ class Stream
      */
     public function contextOptions()
     {
-        return [
-            'http' => $this->_contextOptions,
-            'ssl'  => $this->_sslContextOptions,
-        ];
+        return array_merge($this->_contextOptions, $this->_sslContextOptions);
     }
 }

+ 9 - 9
tests/TestCase/Network/Http/Adapter/StreamTest.php

@@ -84,9 +84,9 @@ class StreamTest extends TestCase
             'Content-Type: application/json',
             'Cookie: testing=value; utm_src=awesome',
         ];
-        $this->assertEquals(implode("\r\n", $expected), $result['http']['header']);
-        $this->assertEquals($options['redirect'], $result['http']['max_redirects']);
-        $this->assertTrue($result['http']['ignore_errors']);
+        $this->assertEquals(implode("\r\n", $expected), $result['header']);
+        $this->assertEquals($options['redirect'], $result['max_redirects']);
+        $this->assertTrue($result['ignore_errors']);
     }
 
     /**
@@ -114,8 +114,8 @@ class StreamTest extends TestCase
             'User-Agent: CakePHP',
             'Content-Type: application/json',
         ];
-        $this->assertEquals(implode("\r\n", $expected), $result['http']['header']);
-        $this->assertEquals($content, $result['http']['content']);
+        $this->assertEquals(implode("\r\n", $expected), $result['header']);
+        $this->assertEquals($content, $result['content']);
     }
 
     /**
@@ -139,9 +139,9 @@ class StreamTest extends TestCase
             'User-Agent: CakePHP',
             'Content-Type: multipart/form-data; boundary="',
         ];
-        $this->assertStringStartsWith(implode("\r\n", $expected), $result['http']['header']);
-        $this->assertContains('Content-Disposition: form-data; name="a"', $result['http']['content']);
-        $this->assertContains('my value', $result['http']['content']);
+        $this->assertStringStartsWith(implode("\r\n", $expected), $result['header']);
+        $this->assertContains('Content-Disposition: form-data; name="a"', $result['content']);
+        $this->assertContains('my value', $result['content']);
     }
 
     /**
@@ -169,7 +169,7 @@ class StreamTest extends TestCase
             'allow_self_signed' => false,
         ];
         foreach ($expected as $k => $v) {
-            $this->assertEquals($v, $result['ssl'][$k]);
+            $this->assertEquals($v, $result[$k]);
         }
     }