diff --git a/.travis.yml b/.travis.yml index a619bb05..52ec054b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: php php: - '5.6' - '7.0' -- hhvm +- hhvm-3.18 cache: directories: - $HOME/.composer/cache diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index bb3b4440..e36adb7b 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -190,8 +190,9 @@ private function doRequest($method, $url, array $urlParams, array $options) { */ private function checkResponseHeaderContentType($response) { $contentType = implode('', $response->getHeader('Content-Type')); - if (empty($contentType) || ((!$this->isEncrypted && strpos($contentType, 'application/json') === false) || - ($this->isEncrypted && strpos($contentType, 'application/jose+json') === false ))) { + $expectedContentType = $this->isEncrypted ? 'application/jose+json' : 'application/json'; + $invalidContentType = $response->getStatusCode() !== 204 && !empty($contentType) && strpos($contentType, $expectedContentType) === false; + if ($invalidContentType) { throw new HyperwalletException('Invalid Content-Type specified in Response Header'); } } diff --git a/tests/Hyperwallet/Tests/Util/ApiClientTest.php b/tests/Hyperwallet/Tests/Util/ApiClientTest.php index 266f6997..d3d3b7e4 100644 --- a/tests/Hyperwallet/Tests/Util/ApiClientTest.php +++ b/tests/Hyperwallet/Tests/Util/ApiClientTest.php @@ -70,6 +70,30 @@ public function testDoPost_with_encryption_successful() { $this->validateRequest('POST', '/test', 'test=true', array('test2' => 'value2'), true, array(), true); } + public function testDoPost_with_encryption_return_response_204_status() { + // Setup data + $clientPath = __DIR__ . "/../../../resources/private-jwkset1"; + $hyperwalletPath = __DIR__ . "/../../../resources/public-jwkset1"; + $originalMessage = array('test2' => 'value2'); + $encryption = new HyperwalletEncryption($clientPath, $hyperwalletPath); + $encryptedMessage = $encryption->encrypt($originalMessage); + + // Execute test + $mockHandler = new MockHandler(array( + new Response(204) + )); + $this->createApiClientWithEncryption($mockHandler); + + $model = new BaseModel(array(), $originalMessage); + + // Execute test + $data = $this->apiClient->doPost('/test', array(), null, array()); + $this->assertEquals(array(), $data); + + // Validate api request + $this->validateRequest('POST', '/test', '', array(), true, array(), true); + } + public function testDoPost_with_encryption_charset_in_content_type() { // Setup data $clientPath = __DIR__ . "/../../../resources/private-jwkset1"; @@ -292,6 +316,21 @@ public function testDoPost_throw_exception_when_response_has_wrong_content_type_ $this->validateRequest('POST', '/test', '', array('test2' => 'value2'), true); } + public function testDoPost_return_response_204_status() { + // Setup data + $mockHandler = new MockHandler(array( + new Response(204) + )); + $this->createApiClient($mockHandler); + + // Execute test + $data = $this->apiClient->doPost('/test', array(), null, array()); + $this->assertEquals(array(), $data); + + // Validate api request + $this->validateRequest('POST', '/test', '', array(), true); + } + public function testDoPost_throw_exception_connection_issue() { // Setup data $mockHandler = new MockHandler(array( @@ -510,6 +549,23 @@ public function testDoPut_return_response_with_path_placeholder() { $this->validateRequest('PUT', '/test/token', '', array('test2' => 'value2'), true); } + public function testDoPut_return_response_204_status() { + // Setup data + $mockHandler = new MockHandler(array( + new Response(204) + )); + $this->createApiClient($mockHandler); + + $model = new BaseModel(array(), array()); + + // Execute test + $data = $this->apiClient->doPut('/test', array(), $model, array()); + $this->assertEquals(array(), $data); + + // Validate api request + $this->validateRequest('PUT', '/test', '', array(), true); + } + public function testDoPut_throw_exception_connection_issue() { // Setup data $mockHandler = new MockHandler(array(