Browse Source

Start implementing SSL options.

Mark Story 7 years ago
parent
commit
f3f5b08db3
2 changed files with 42 additions and 0 deletions
  1. 11 0
      src/Http/Client/Adapter/Curl.php
  2. 31 0
      tests/TestCase/Http/Client/Adapter/CurlTest.php

+ 11 - 0
src/Http/Client/Adapter/Curl.php

@@ -80,9 +80,20 @@ class Curl implements AdapterInterface
             $out[CURLOPT_POSTFIELDS] = $body->getContents();
         }
 
+        $optionMap = [
+            'timeout' => CURLOPT_TIMEOUT,
+            'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
+            'ssl_verify_host' => CURLOPT_SSL_VERIFYHOST,
+            'ssl_verify_depth' => 9000,
+            'ssl_allow_self_signed' => false,
+        ];
+
         if (isset($options['timeout'])) {
             $out[CURLOPT_TIMEOUT] = $options['timeout'];
         }
+        if (isset($options['ssl_verify_peer'])) {
+            $out[CURLOPT_SSL_VERIFYPEER] = $options['ssl_verify_peer'];
+        }
 
         return $out;
     }

+ 31 - 0
tests/TestCase/Http/Client/Adapter/CurlTest.php

@@ -147,6 +147,37 @@ class CurlTest extends TestCase
     }
 
     /**
+     * Test converting client options into curl ones.
+     *
+     * @return void
+     */
+    public function testBuildOptionsSsl()
+    {
+        $options = [
+            'ssl_verify_host' => true,
+            'ssl_verify_peer' => true,
+            'ssl_verify_peer_name' => true,
+            'ssl_verify_depth' => 9000,
+            'ssl_allow_self_signed' => false,
+        ];
+        $request = new Request('http://localhost/things', 'GET');
+        $result = $this->curl->buildOptions($request, $options);
+        $expected = [
+            CURLOPT_URL => 'http://localhost/things',
+            CURLOPT_HTTP_VERSION => '1.1',
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_HEADER => true,
+            CURLOPT_HTTPHEADER => [
+                'Connection: close',
+                'User-Agent: CakePHP',
+            ],
+            CURLOPT_HTTPGET => true,
+            CURLOPT_SSL_VERIFYPEER => true
+        ];
+        $this->assertSame($expected, $result);
+    }
+
+    /**
      * Test the send method by using cakephp:// protocol.
      *
      * @return void