diff --git a/src/Response.php b/src/Response.php index 50d1c96f81..4a0e8192a3 100644 --- a/src/Response.php +++ b/src/Response.php @@ -7,6 +7,7 @@ namespace Zend\Http; +use Zend\Http\Exception\RuntimeException; use Zend\Stdlib\ErrorHandler; use Zend\Stdlib\ResponseInterface; @@ -189,20 +190,18 @@ public static function fromString($string) $firstLine = array_shift($lines); $response = new static(); + $response->parseStatusLine($firstLine); - $regex = '/^HTTP\/(?P1\.[01]) (?P\d{3})(?:[ ]+(?P.*))?$/'; - $matches = []; - if (! preg_match($regex, $firstLine, $matches)) { - throw new Exception\InvalidArgumentException( - 'A valid response status line was not found in the provided string' - ); + /** + * @link https://tools.ietf.org/html/rfc7231#section-6.2.1 + */ + if ($response->statusCode === static::STATUS_CODE_100) { + $next = array_shift($lines); // take next line + $next = !empty($next) ? $next : array_shift($lines); // take next or skip if empty + $response->parseStatusLine($next); } - $response->version = $matches['version']; - $response->setStatusCode($matches['status']); - $response->setReasonPhrase((isset($matches['reason']) ? $matches['reason'] : '')); - - if (empty($lines)) { + if (count($lines) === 0) { return $response; } @@ -243,6 +242,26 @@ public static function fromString($string) return $response; } + /** + * @param string $line + * @throws Exception\InvalidArgumentException + * @throws Exception\RuntimeException + */ + protected function parseStatusLine($line) + { + $regex = '/^HTTP\/(?P1\.[01]) (?P\d{3})(?:[ ]+(?P.*))?$/'; + $matches = []; + if (! preg_match($regex, $line, $matches)) { + throw new Exception\InvalidArgumentException( + 'A valid response status line was not found in the provided string' + ); + } + + $this->version = $matches['version']; + $this->setStatusCode($matches['status']); + $this->setReasonPhrase((isset($matches['reason']) ? $matches['reason'] : '')); + } + /** * @return Header\SetCookie[] */ diff --git a/test/Client/CurlTest.php b/test/Client/CurlTest.php index 0e6c75fc92..5c513a2430 100644 --- a/test/Client/CurlTest.php +++ b/test/Client/CurlTest.php @@ -105,8 +105,7 @@ public function testConfigSetAsZendConfig() */ public function testSetConfigInvalidConfig($config) { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Array or Traversable object expected'); + $this->setExpectedException(InvalidArgumentException::class, 'Array or Traversable object expected'); $this->_adapter->setOptions($config); } @@ -129,8 +128,7 @@ public function testSettingInvalidCurlOption() ]; $this->client = new Client($this->client->getUri(true), $config); - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Unknown or erroreous cURL option'); + $this->setExpectedException(RuntimeException::class, 'Unknown or erroreous cURL option'); $this->client->send(); } @@ -176,9 +174,8 @@ public function testRedirectPostToGetWithCurlFollowLocationOptionLeadsToTimeout( $this->client->setParameterGet(['swallow' => 'african']); $this->client->setParameterPost(['Camelot' => 'A silly place']); $this->client->setMethod('POST'); - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage( - 'Error in cURL request: Operation timed out after 1000 milliseconds with 0 bytes received' + $this->setExpectedException( + RuntimeException::class, 'Error in cURL request: Operation timed out after 1000 milliseconds with 0 bytes received' ); $this->client->send(); } @@ -239,15 +236,14 @@ public function testPutFileHandleWithHttpClient() public function testWritingAndNotConnectedWithCurlHandleThrowsException() { $adapter = new Adapter\Curl(); - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Trying to write but we are not connected'); + $this->setExpectedException(RuntimeException::class, 'Trying to write but we are not connected'); $adapter->write('GET', 'someUri'); } public function testSetConfigIsNotArray() { $adapter = new Adapter\Curl(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $adapter->setOptions('foo'); } diff --git a/test/Client/SocketTest.php b/test/Client/SocketTest.php index 1610c571f2..a812595293 100644 --- a/test/Client/SocketTest.php +++ b/test/Client/SocketTest.php @@ -165,8 +165,7 @@ public function testConfigSetAsZendConfig() */ public function testSetConfigInvalidConfig($config) { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Array or Zend\Config object expected'); + $this->setExpectedException(InvalidArgumentException::class, 'Array or Zend\Config object expected'); $this->_adapter->setOptions($config); } @@ -225,8 +224,10 @@ public function testSetNewStreamContextOptions() */ public function testSetInvalidContextOptions($invalid) { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Expecting either a stream context resource or array'); + $this->setExpectedException( + InvalidArgumentException::class, + 'Expecting either a stream context resource or array' + ); $adapterClass = $this->config['adapter']; $adapter = new $adapterClass(); diff --git a/test/Client/StaticTest.php b/test/Client/StaticTest.php index 935eb0d2b0..2f7a4f190e 100644 --- a/test/Client/StaticTest.php +++ b/test/Client/StaticTest.php @@ -153,8 +153,10 @@ public function testGetHeader() */ public function testExceptUnsupportedAuthDynamic() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid or not supported authentication type: \'SuperStrongAlgo\''); + $this->setExpectedException( + InvalidArgumentException::class, + 'Invalid or not supported authentication type: \'SuperStrongAlgo\'' + ); $this->_client->setAuth('shahar', '1234', 'SuperStrongAlgo'); } @@ -200,8 +202,10 @@ public function testUnsetCookies() */ public function testSetInvalidCookies() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid parameter type passed as Cookie'); + $this->setExpectedException( + InvalidArgumentException::class, + 'Invalid parameter type passed as Cookie' + ); $this->_client->addCookie('cookie'); } @@ -259,8 +263,7 @@ public function testConfigSetAsZendConfig() */ public function testConfigSetInvalid($config) { - $this->expectException(ClientException\InvalidArgumentException::class); - $this->expectExceptionMessage('Config parameter is not valid'); + $this->setExpectedException(ClientException\InvalidArgumentException::class, 'Config parameter is not valid'); $this->_client->setOptions($config); } @@ -345,8 +348,7 @@ public function testInvalidPostContentType() HTTPClient::class )); } - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Cannot handle content type \'x-foo/something-fake\' automatically'); + $this->setExpectedException(RuntimeException::class, 'Cannot handle content type \'x-foo/something-fake\' automatically'); $this->_client->setEncType('x-foo/something-fake'); $this->_client->setParameterPost(['parameter' => 'value']); @@ -366,8 +368,10 @@ public function testSocketErrorException() HTTPClient::class )); } - $this->expectException(ClientAdapterException\RuntimeException::class); - $this->expectExceptionMessage('Unable to connect to 255.255.255.255:80'); + $this->setExpectedException( + ClientAdapterException\RuntimeException::class, + 'Unable to connect to 255.255.255.255:80' + ); // Try to connect to an invalid host $this->_client->setUri('http://255.255.255.255'); @@ -389,8 +393,7 @@ public function testSocketErrorException() */ public function testSettingInvalidMethodThrowsException($method) { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid HTTP method passed'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid HTTP method passed'); $this->_client->setMethod($method); } @@ -522,8 +525,7 @@ public function testOpenTempStreamWithBogusFileClosesTheConnection() $client = new HTTPClient($url, $config); $client->setMethod('GET'); - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('Could not open temp file /path/to/bogus/file.ext'); + $this->setExpectedException(RuntimeException::class, 'Could not open temp file /path/to/bogus/file.ext'); $client->send(); } diff --git a/test/Client/TestAdapterTest.php b/test/Client/TestAdapterTest.php index 3c64fcd268..d4eba32617 100644 --- a/test/Client/TestAdapterTest.php +++ b/test/Client/TestAdapterTest.php @@ -50,8 +50,7 @@ public function tearDown() */ public function testSetConfigThrowsOnInvalidConfig() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Array or Traversable object expected'); + $this->setExpectedException(InvalidArgumentException::class, 'Array or Traversable object expected'); $this->adapter->setOptions('foo'); } diff --git a/test/ClientTest.php b/test/ClientTest.php index c3833ba133..b2ac0f7b54 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -122,7 +122,8 @@ public function testIfNullValueCookiesThrowsException() { $client = new Client(); - $this->expectException(HttpException\InvalidArgumentException::class); + $this->setExpectedException(HttpException\InvalidArgumentException::class); + $client->addCookie('test', null); } @@ -217,13 +218,13 @@ public function testEncodeAuthHeaderWorksAsExpected() public function testEncodeAuthHeaderThrowsExceptionWhenUsernameContainsSemiColon() { - $this->expectException(ClientException\InvalidArgumentException::class); + $this->setExpectedException(ClientException\InvalidArgumentException::class); Client::encodeAuthHeader('test:', 'test'); } public function testEncodeAuthHeaderThrowsExceptionWhenInvalidAuthTypeIsUsed() { - $this->expectException(ClientException\InvalidArgumentException::class); + $this->setExpectedException(ClientException\InvalidArgumentException::class); Client::encodeAuthHeader('test', 'test', 'test'); } @@ -453,7 +454,7 @@ public function testHttpQueryParametersCastToString() { $client = new Client(); - $adapter = $this->createMock(AdapterInterface::class); + $adapter = $this->getMock(AdapterInterface::class); $client->setAdapter($adapter); diff --git a/test/Header/AcceptCharsetTest.php b/test/Header/AcceptCharsetTest.php index e8c8a0100b..7ecb1837fe 100644 --- a/test/Header/AcceptCharsetTest.php +++ b/test/Header/AcceptCharsetTest.php @@ -94,7 +94,7 @@ public function testWildcharCharset() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); AcceptCharset::fromString("Accept-Charset: iso-8859-5\r\n\r\nevilContent"); } @@ -105,8 +105,7 @@ public function testPreventsCRLFAttackViaFromString() public function testPreventsCRLFAttackViaSetters() { $header = new AcceptCharset(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid type'); + $this->setExpectedException(InvalidArgumentException::class, 'valid type'); $header->addCharset("\niso\r-8859-\r\n5"); } } diff --git a/test/Header/AcceptEncodingTest.php b/test/Header/AcceptEncodingTest.php index 82907ca167..395f4208fc 100644 --- a/test/Header/AcceptEncodingTest.php +++ b/test/Header/AcceptEncodingTest.php @@ -95,7 +95,7 @@ public function testWildcharEncoder() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = AcceptEncoding::fromString("Accept-Encoding: compress\r\n\r\nevilContent"); } @@ -106,8 +106,7 @@ public function testPreventsCRLFAttackViaFromString() public function testPreventsCRLFAttackViaSetters() { $header = new AcceptEncoding(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid type'); + $this->setExpectedException(InvalidArgumentException::class, 'valid type'); $header->addEncoding("\nc\rom\r\npress"); } diff --git a/test/Header/AcceptLanguageTest.php b/test/Header/AcceptLanguageTest.php index 24b011e827..d56272020f 100644 --- a/test/Header/AcceptLanguageTest.php +++ b/test/Header/AcceptLanguageTest.php @@ -111,7 +111,7 @@ public function testWildcards() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = AcceptLanguage::fromString("Accept-Language: da\r\n\r\nevilContent"); } @@ -122,8 +122,7 @@ public function testPreventsCRLFAttackViaFromString() public function testPreventsCRLFAttackViaSetters() { $header = new AcceptLanguage(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid type'); + $this->setExpectedException(InvalidArgumentException::class, 'valid type'); $header->addLanguage("\nen\r-\r\nus"); } diff --git a/test/Header/AcceptRangesTest.php b/test/Header/AcceptRangesTest.php index 54576186e1..29d0e7f3de 100644 --- a/test/Header/AcceptRangesTest.php +++ b/test/Header/AcceptRangesTest.php @@ -51,7 +51,7 @@ public function testAcceptRangesToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = AcceptRanges::fromString("Accept-Ranges: bytes;\r\n\r\nevilContent"); } @@ -61,7 +61,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = new AcceptRanges("bytes;\r\n\r\nevilContent"); } } diff --git a/test/Header/AcceptTest.php b/test/Header/AcceptTest.php index 8670a15110..2737c496b7 100644 --- a/test/Header/AcceptTest.php +++ b/test/Header/AcceptTest.php @@ -18,7 +18,7 @@ class AcceptTest extends TestCase { public function testInvalidHeaderLine() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Accept::fromString(''); } @@ -60,7 +60,7 @@ public function testAcceptToStringReturnsHeaderFormattedString() $acceptHeader->toString() ); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $acceptHeader->addMediaType('\\', 0.9); } @@ -464,7 +464,7 @@ public function testWildcardDefaults() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Accept::fromString("Accept: application/text\r\n\r\nevilContent"); } diff --git a/test/Header/AgeTest.php b/test/Header/AgeTest.php index 4f40fbaefa..dead5f8dd2 100644 --- a/test/Header/AgeTest.php +++ b/test/Header/AgeTest.php @@ -55,7 +55,7 @@ public function testAgeCorrectsDeltaSecondsOverflow() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = Age::fromString("Age: 100\r\n\r\nevilContent"); } @@ -65,7 +65,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = new Age("100\r\n\r\nevilContent"); } } diff --git a/test/Header/AllowTest.php b/test/Header/AllowTest.php index d43ad1822c..ef6bea4376 100644 --- a/test/Header/AllowTest.php +++ b/test/Header/AllowTest.php @@ -90,8 +90,7 @@ public function testAllowChecksAllowedMethod() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid header value detected'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid header value detected'); Allow::fromString("Allow: GET\r\n\r\nevilContent"); } @@ -115,8 +114,7 @@ public function injectionMethods() public function testPreventsCRLFAttackViaAllowMethods($methods) { $header = new Allow(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid method'); + $this->setExpectedException(InvalidArgumentException::class, 'valid method'); $header->allowMethods($methods); } @@ -132,8 +130,7 @@ public function testPreventsCRLFAttackViaAllowMethods($methods) public function testPreventsCRLFAttackViaDisallowMethods($methods) { $header = new Allow(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid method'); + $this->setExpectedException(InvalidArgumentException::class, 'valid method'); $header->disallowMethods($methods); } diff --git a/test/Header/AuthenticationInfoTest.php b/test/Header/AuthenticationInfoTest.php index ad111051d9..8ec72a07dd 100644 --- a/test/Header/AuthenticationInfoTest.php +++ b/test/Header/AuthenticationInfoTest.php @@ -53,7 +53,7 @@ public function testAuthenticationInfoToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = AuthenticationInfo::fromString("Authentication-Info: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new AuthenticationInfo("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/AuthorizationTest.php b/test/Header/AuthorizationTest.php index a1afedd03e..fe97a748e0 100644 --- a/test/Header/AuthorizationTest.php +++ b/test/Header/AuthorizationTest.php @@ -50,7 +50,7 @@ public function testAuthorizationToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = Authorization::fromString("Authorization: xxx\r\n\r\nevilContent"); } @@ -60,7 +60,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Authorization("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/CacheControlTest.php b/test/Header/CacheControlTest.php index 09ecb3c9e9..ce96bfc80a 100644 --- a/test/Header/CacheControlTest.php +++ b/test/Header/CacheControlTest.php @@ -106,7 +106,7 @@ public function testCacheControlParse() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); CacheControl::fromString("Cache-Control: xxx\r\n\r\n"); } @@ -117,7 +117,7 @@ public function testPreventsCRLFAttackViaFromString() public function testProtectsFromCRLFAttackViaSetters() { $header = new CacheControl(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header->addDirective("\rsome\r\ninvalid\nkey", "\ra\r\nCRLF\ninjection"); } } diff --git a/test/Header/ConnectionTest.php b/test/Header/ConnectionTest.php index 5e9adca6cd..9f3722ec49 100644 --- a/test/Header/ConnectionTest.php +++ b/test/Header/ConnectionTest.php @@ -60,7 +60,7 @@ public function testConnectionSetPersistentReturnsProperValue() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Connection::fromString("Connection: close\r\n\r\nevilContent"); } @@ -71,7 +71,7 @@ public function testPreventsCRLFAttackViaFromString() public function testPreventsCRLFAttackViaSetters() { $header = new Connection(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header->setValue("close\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentDispositionTest.php b/test/Header/ContentDispositionTest.php index 773af476e9..bd2888e3f6 100644 --- a/test/Header/ContentDispositionTest.php +++ b/test/Header/ContentDispositionTest.php @@ -53,7 +53,7 @@ public function testContentDispositionToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentDisposition::fromString("Content-Disposition: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentDisposition("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentEncodingTest.php b/test/Header/ContentEncodingTest.php index 5702d1740e..9c8b9f5660 100644 --- a/test/Header/ContentEncodingTest.php +++ b/test/Header/ContentEncodingTest.php @@ -53,7 +53,7 @@ public function testContentEncodingToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentEncoding::fromString("Content-Encoding: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentEncoding("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentLanguageTest.php b/test/Header/ContentLanguageTest.php index b6fbf961e2..183748a048 100644 --- a/test/Header/ContentLanguageTest.php +++ b/test/Header/ContentLanguageTest.php @@ -53,7 +53,7 @@ public function testContentLanguageToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentLanguage::fromString("Content-Language: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentLanguage("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentLengthTest.php b/test/Header/ContentLengthTest.php index ac5edca0b8..5ce0bcffaa 100644 --- a/test/Header/ContentLengthTest.php +++ b/test/Header/ContentLengthTest.php @@ -53,7 +53,7 @@ public function testContentLengthToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentLength::fromString("Content-Length: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentLength("Content-Length: xxx\r\n\r\nevilContent"); } diff --git a/test/Header/ContentLocationTest.php b/test/Header/ContentLocationTest.php index e695e7fb50..9c9ba9abf3 100644 --- a/test/Header/ContentLocationTest.php +++ b/test/Header/ContentLocationTest.php @@ -66,7 +66,7 @@ public function testContentLocationCanSetAndAccessRelativeUri() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentLocation::fromString("Content-Location: /path/to\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentMD5Test.php b/test/Header/ContentMD5Test.php index 519ef0c480..d6ab7a8c30 100644 --- a/test/Header/ContentMD5Test.php +++ b/test/Header/ContentMD5Test.php @@ -53,7 +53,7 @@ public function testContentMD5ToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentMD5::fromString("Content-MD5: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentMD5("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentRangeTest.php b/test/Header/ContentRangeTest.php index 76f204faf2..e991c5949a 100644 --- a/test/Header/ContentRangeTest.php +++ b/test/Header/ContentRangeTest.php @@ -53,7 +53,7 @@ public function testContentRangeToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentRange::fromString("Content-Range: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentRange("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentSecurityPolicyTest.php b/test/Header/ContentSecurityPolicyTest.php index a4e6edb21d..6283acb089 100644 --- a/test/Header/ContentSecurityPolicyTest.php +++ b/test/Header/ContentSecurityPolicyTest.php @@ -16,7 +16,7 @@ class ContentSecurityPolicyTest extends TestCase { public function testContentSecurityPolicyFromStringThrowsExceptionIfImproperHeaderNameUsed() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentSecurityPolicy::fromString('X-Content-Security-Policy: default-src *;'); } @@ -80,7 +80,7 @@ public function testContentSecurityPolicySetDirectiveWithEmptySourcesDefaultsToN public function testContentSecurityPolicySetDirectiveThrowsExceptionIfInvalidDirectiveNameGiven() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $csp = new ContentSecurityPolicy(); $csp->setDirective('foo', []); } @@ -99,7 +99,7 @@ public function testContentSecurityPolicyGetFieldValueReturnsProperValue() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentSecurityPolicy::fromString("Content-Security-Policy: default-src 'none'\r\n\r\nevilContent"); } @@ -110,7 +110,7 @@ public function testPreventsCRLFAttackViaFromString() public function testPreventsCRLFAttackViaDirective() { $header = new ContentSecurityPolicy(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header->setDirective('default-src', ["\rsome\r\nCRLF\ninjection"]); } diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php index 437cd82d62..fdeb1c6ef4 100644 --- a/test/Header/ContentTransferEncodingTest.php +++ b/test/Header/ContentTransferEncodingTest.php @@ -53,7 +53,7 @@ public function testContentTransferEncodingToStringReturnsHeaderFormattedString( */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentTransferEncoding::fromString("Content-Transfer-Encoding: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentTransferEncoding("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ContentTypeTest.php b/test/Header/ContentTypeTest.php index cd726526f6..42f647c3e9 100644 --- a/test/Header/ContentTypeTest.php +++ b/test/Header/ContentTypeTest.php @@ -157,7 +157,7 @@ public function testContentTypeParsesParametersCorrectly($headerString, $expecte */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ContentType::fromString("Content-Type: foo/bar;\r\n\r\nevilContent"); } @@ -167,7 +167,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ContentType("foo/bar\r\n\r\nevilContent"); } } diff --git a/test/Header/CookieTest.php b/test/Header/CookieTest.php index 1d84980c18..19c1d67d80 100644 --- a/test/Header/CookieTest.php +++ b/test/Header/CookieTest.php @@ -75,7 +75,7 @@ public function testCookieToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Cookie::fromString("Cookie: foo=bar\r\n\r\nevilContent"); } diff --git a/test/Header/DateTest.php b/test/Header/DateTest.php index 4980a36347..9bedbadfb4 100644 --- a/test/Header/DateTest.php +++ b/test/Header/DateTest.php @@ -57,13 +57,13 @@ public function testDateFromTimestampCreatesValidDateHeader() public function testDateFromTimeStringDetectsBadInput() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Date::fromTimeString('3 Days of the Condor'); } public function testDateFromTimestampDetectsBadInput() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Date::fromTimestamp('The Day of the Jackal'); } @@ -113,8 +113,7 @@ public function testDateReturnsProperlyFormattedDate() public function testDateThrowsExceptionForInvalidDate() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid date'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid date'); $dateHeader = new Date(); $dateHeader->setDate('~~~~'); } @@ -142,7 +141,7 @@ public function testDateCanOutputDatesInOldFormats() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Date::fromString("Date: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent"); } } diff --git a/test/Header/EtagTest.php b/test/Header/EtagTest.php index e680c5a600..8e7c6acb00 100644 --- a/test/Header/EtagTest.php +++ b/test/Header/EtagTest.php @@ -53,7 +53,7 @@ public function testEtagToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Etag::fromString("Etag: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Etag("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ExpectTest.php b/test/Header/ExpectTest.php index eaeaf20e7d..e0b8e7af48 100644 --- a/test/Header/ExpectTest.php +++ b/test/Header/ExpectTest.php @@ -53,7 +53,7 @@ public function testExpectToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Expect::fromString("Expect: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Expect("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ExpiresTest.php b/test/Header/ExpiresTest.php index 26c80896a8..a384777aad 100644 --- a/test/Header/ExpiresTest.php +++ b/test/Header/ExpiresTest.php @@ -52,7 +52,7 @@ public function testExpiresToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Expires::fromString("Expires: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent"); } diff --git a/test/Header/FromTest.php b/test/Header/FromTest.php index a436eaac93..74d61492c5 100644 --- a/test/Header/FromTest.php +++ b/test/Header/FromTest.php @@ -53,7 +53,7 @@ public function testFromToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); From::fromString("From: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new From("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/GenericHeaderTest.php b/test/Header/GenericHeaderTest.php index ba1ed200c3..7f62ac9540 100644 --- a/test/Header/GenericHeaderTest.php +++ b/test/Header/GenericHeaderTest.php @@ -64,7 +64,7 @@ public function testDoesNotReplaceUnderscoresWithDashes() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); GenericHeader::fromString("X_Foo_Bar: Bar\r\n\r\nevilContent"); } @@ -74,7 +74,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new GenericHeader('X_Foo_Bar', "Bar\r\n\r\nevilContent"); } @@ -85,8 +85,7 @@ public function testPreventsCRLFAttackViaConstructor() public function testProtectsFromCRLFAttackViaSetFieldName() { $header = new GenericHeader(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('valid'); + $this->setExpectedException(InvalidArgumentException::class, 'valid'); $header->setFieldName("\rX-\r\nFoo-\nBar"); } @@ -97,7 +96,7 @@ public function testProtectsFromCRLFAttackViaSetFieldName() public function testProtectsFromCRLFAttackViaSetFieldValue() { $header = new GenericHeader(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header->setFieldValue("\rSome\r\nCLRF\nAttack"); } diff --git a/test/Header/HeaderValueTest.php b/test/Header/HeaderValueTest.php index 9b6359fc0a..58a19f5479 100644 --- a/test/Header/HeaderValueTest.php +++ b/test/Header/HeaderValueTest.php @@ -101,7 +101,7 @@ public function assertValues() */ public function testAssertValidRaisesExceptionForInvalidValue($value) { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); HeaderValue::assertValid($value); } } diff --git a/test/Header/HostTest.php b/test/Header/HostTest.php index c7e3fb8e18..72ac1b2b89 100644 --- a/test/Header/HostTest.php +++ b/test/Header/HostTest.php @@ -53,7 +53,7 @@ public function testHostToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Host::fromString("Host: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Host("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/IfMatchTest.php b/test/Header/IfMatchTest.php index a659461eec..8fc95a7cdb 100644 --- a/test/Header/IfMatchTest.php +++ b/test/Header/IfMatchTest.php @@ -53,7 +53,7 @@ public function testIfMatchToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); IfMatch::fromString("If-Match: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new IfMatch("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/IfModifiedSinceTest.php b/test/Header/IfModifiedSinceTest.php index 8518cc8745..b8975588d7 100644 --- a/test/Header/IfModifiedSinceTest.php +++ b/test/Header/IfModifiedSinceTest.php @@ -52,7 +52,7 @@ public function testIfModifiedSinceToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); IfModifiedSince::fromString( "If-Modified-Since: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent" ); diff --git a/test/Header/IfNoneMatchTest.php b/test/Header/IfNoneMatchTest.php index 9f7cc1a91a..eb7996b340 100644 --- a/test/Header/IfNoneMatchTest.php +++ b/test/Header/IfNoneMatchTest.php @@ -53,7 +53,7 @@ public function testIfNoneMatchToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); IfNoneMatch::fromString("If-None-Match: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new IfNoneMatch("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/IfRangeTest.php b/test/Header/IfRangeTest.php index d1923c47a9..465ade5507 100644 --- a/test/Header/IfRangeTest.php +++ b/test/Header/IfRangeTest.php @@ -53,7 +53,7 @@ public function testIfRangeToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); IfRange::fromString("If-Range: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new IfRange("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/IfUnmodifiedSinceTest.php b/test/Header/IfUnmodifiedSinceTest.php index efa6cd9513..6985cb875a 100644 --- a/test/Header/IfUnmodifiedSinceTest.php +++ b/test/Header/IfUnmodifiedSinceTest.php @@ -52,7 +52,7 @@ public function testIfUnmodifiedSinceToStringReturnsHeaderFormattedString() */ public function testCRLFAttack() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); IfUnmodifiedSince::fromString( "If-Unmodified-Since: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent" ); diff --git a/test/Header/KeepAliveTest.php b/test/Header/KeepAliveTest.php index 0cc1eee344..1104b3b0b7 100644 --- a/test/Header/KeepAliveTest.php +++ b/test/Header/KeepAliveTest.php @@ -53,7 +53,7 @@ public function testKeepAliveToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); KeepAlive::fromString("Keep-Alive: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new KeepAlive("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/LastModifiedTest.php b/test/Header/LastModifiedTest.php index af8005a5b5..34a89b194b 100644 --- a/test/Header/LastModifiedTest.php +++ b/test/Header/LastModifiedTest.php @@ -52,7 +52,7 @@ public function testLastModifiedToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); LastModified::fromString("Last-Modified: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent"); } } diff --git a/test/Header/LocationTest.php b/test/Header/LocationTest.php index d3ba39a3ad..aa4b006a3c 100644 --- a/test/Header/LocationTest.php +++ b/test/Header/LocationTest.php @@ -131,7 +131,7 @@ public function testLocationCanSetAndAccessRelativeUri() */ public function testCRLFAttack() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Location::fromString("Location: http://www.example.com/path\r\n\r\nevilContent"); } } diff --git a/test/Header/MaxForwardsTest.php b/test/Header/MaxForwardsTest.php index ddea63f70e..f5797b49ef 100644 --- a/test/Header/MaxForwardsTest.php +++ b/test/Header/MaxForwardsTest.php @@ -53,7 +53,7 @@ public function testMaxForwardsToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); MaxForwards::fromString("Max-Forwards: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructorValue() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new MaxForwards("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/OriginTest.php b/test/Header/OriginTest.php index 4fae8b7d32..9ff50c1e4f 100644 --- a/test/Header/OriginTest.php +++ b/test/Header/OriginTest.php @@ -50,7 +50,7 @@ public function testOriginGetFieldValueReturnsProperValue() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidUriPartException::class); + $this->setExpectedException(InvalidUriPartException::class); Origin::fromString("Origin: http://zend.org\r\n\r\nevilContent"); } @@ -59,7 +59,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Origin("http://zend.org\r\n\r\nevilContent"); } } diff --git a/test/Header/PragmaTest.php b/test/Header/PragmaTest.php index bc46cbddd4..154c19084f 100644 --- a/test/Header/PragmaTest.php +++ b/test/Header/PragmaTest.php @@ -53,7 +53,7 @@ public function testPragmaToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Pragma::fromString("Pragma: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Pragma("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ProxyAuthenticateTest.php b/test/Header/ProxyAuthenticateTest.php index b56254b86b..189dcac13d 100644 --- a/test/Header/ProxyAuthenticateTest.php +++ b/test/Header/ProxyAuthenticateTest.php @@ -53,7 +53,7 @@ public function testProxyAuthenticateToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ProxyAuthenticate::fromString("Proxy-Authenticate: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ProxyAuthenticate("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ProxyAuthorizationTest.php b/test/Header/ProxyAuthorizationTest.php index 3892cef317..52ceafb539 100644 --- a/test/Header/ProxyAuthorizationTest.php +++ b/test/Header/ProxyAuthorizationTest.php @@ -53,7 +53,7 @@ public function testProxyAuthorizationToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); ProxyAuthorization::fromString("Proxy-Authorization: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new ProxyAuthorization("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/RangeTest.php b/test/Header/RangeTest.php index 59a124b696..24bd964af5 100644 --- a/test/Header/RangeTest.php +++ b/test/Header/RangeTest.php @@ -53,7 +53,7 @@ public function testRangeToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Range::fromString("Range: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructorValue() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Range("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/RefererTest.php b/test/Header/RefererTest.php index 6abd97fbcd..4a2aeb803c 100644 --- a/test/Header/RefererTest.php +++ b/test/Header/RefererTest.php @@ -74,7 +74,7 @@ public function testRefererDoesNotHaveUriFragment() */ public function testCRLFAttack() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Referer::fromString("Referer: http://www.example.com/\r\n\r\nevilContent"); } } diff --git a/test/Header/RefreshTest.php b/test/Header/RefreshTest.php index 49e563d537..ace5d916dc 100644 --- a/test/Header/RefreshTest.php +++ b/test/Header/RefreshTest.php @@ -53,7 +53,7 @@ public function testRefreshToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Refresh::fromString("Refresh: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructorValue() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Refresh("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/RetryAfterTest.php b/test/Header/RetryAfterTest.php index 554091202d..19079bcd10 100644 --- a/test/Header/RetryAfterTest.php +++ b/test/Header/RetryAfterTest.php @@ -60,7 +60,7 @@ public function testRetryAfterToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); RetryAfter::fromString("Retry-After: 10\r\n\r\nevilContent"); } } diff --git a/test/Header/ServerTest.php b/test/Header/ServerTest.php index b026b53a0d..8bf4d31eaa 100644 --- a/test/Header/ServerTest.php +++ b/test/Header/ServerTest.php @@ -53,7 +53,7 @@ public function testServerToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Server::fromString("Server: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Server("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/SetCookieTest.php b/test/Header/SetCookieTest.php index e60790d50d..0d6b9663d9 100644 --- a/test/Header/SetCookieTest.php +++ b/test/Header/SetCookieTest.php @@ -436,7 +436,7 @@ public function testSetJsonValue() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); SetCookie::fromString("Set-Cookie: leo_auth_token=example;\r\n\r\nevilContent"); } @@ -478,7 +478,7 @@ public function setterInjections() public function testPreventsCRLFAttackViaSetters($method, $value) { $header = new SetCookie(); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header->{$method}($value); } diff --git a/test/Header/TETest.php b/test/Header/TETest.php index 0da30812e4..7a6958dc93 100644 --- a/test/Header/TETest.php +++ b/test/Header/TETest.php @@ -53,7 +53,7 @@ public function testTEToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); TE::fromString("TE: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new TE("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/TrailerTest.php b/test/Header/TrailerTest.php index 600acdbd4f..3f829b0002 100644 --- a/test/Header/TrailerTest.php +++ b/test/Header/TrailerTest.php @@ -53,7 +53,7 @@ public function testTrailerToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Trailer::fromString("Trailer: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Trailer("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/TransferEncodingTest.php b/test/Header/TransferEncodingTest.php index 15b29f1f53..35f57a4909 100644 --- a/test/Header/TransferEncodingTest.php +++ b/test/Header/TransferEncodingTest.php @@ -53,7 +53,7 @@ public function testTransferEncodingToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); TransferEncoding::fromString("Transfer-Encoding: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new TransferEncoding("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/UpgradeTest.php b/test/Header/UpgradeTest.php index c91ea1cdbc..917716aac4 100644 --- a/test/Header/UpgradeTest.php +++ b/test/Header/UpgradeTest.php @@ -53,7 +53,7 @@ public function testUpgradeToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Upgrade::fromString("Upgrade: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Upgrade("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/UserAgentTest.php b/test/Header/UserAgentTest.php index 6d448a844e..43680651fe 100644 --- a/test/Header/UserAgentTest.php +++ b/test/Header/UserAgentTest.php @@ -53,7 +53,7 @@ public function testUserAgentToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); UserAgent::fromString("User-Agent: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new UserAgent("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/VaryTest.php b/test/Header/VaryTest.php index 06db126238..68836ba861 100644 --- a/test/Header/VaryTest.php +++ b/test/Header/VaryTest.php @@ -53,7 +53,7 @@ public function testVaryToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Vary::fromString("Vary: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Vary("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/ViaTest.php b/test/Header/ViaTest.php index 63e23bbbf2..d503a47c23 100644 --- a/test/Header/ViaTest.php +++ b/test/Header/ViaTest.php @@ -53,7 +53,7 @@ public function testViaToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Via::fromString("Via: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Via("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/WWWAuthenticateTest.php b/test/Header/WWWAuthenticateTest.php index 353fd253be..e27cd3215a 100644 --- a/test/Header/WWWAuthenticateTest.php +++ b/test/Header/WWWAuthenticateTest.php @@ -53,7 +53,7 @@ public function testWWWAuthenticateToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = WWWAuthenticate::fromString("WWW-Authenticate: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $header = new WWWAuthenticate("xxx\r\n\r\nevilContent"); } } diff --git a/test/Header/WarningTest.php b/test/Header/WarningTest.php index a764b95c99..48208b8795 100644 --- a/test/Header/WarningTest.php +++ b/test/Header/WarningTest.php @@ -53,7 +53,7 @@ public function testWarningToStringReturnsHeaderFormattedString() */ public function testPreventsCRLFAttackViaFromString() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); Warning::fromString("Warning: xxx\r\n\r\nevilContent"); } @@ -63,7 +63,7 @@ public function testPreventsCRLFAttackViaFromString() */ public function testPreventsCRLFAttackViaConstructor() { - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); new Warning("xxx\r\n\r\nevilContent"); } } diff --git a/test/HeadersTest.php b/test/HeadersTest.php index 3b31b4b675..d47a309435 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -69,8 +69,7 @@ public function testHeadersFromStringFactoryCreatesSingleObjectWithHeaderFolding public function testHeadersFromStringFactoryThrowsExceptionOnMalformedHeaderLine() { - $this->expectException(RuntimeException::class); - $this->expectExceptionMessage('does not match'); + $this->setExpectedException(RuntimeException::class, 'does not match'); Headers::fromString("Fake = foo-bar\r\n\r\n"); } @@ -140,8 +139,7 @@ public function testHeadersAggregatesHeaderThroughAddHeaderLine() public function testHeadersAddHeaderLineThrowsExceptionOnMissingFieldValue() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('without a field'); + $this->setExpectedException(InvalidArgumentException::class, 'without a field'); $headers = new Headers(); $headers->addHeaderLine('Foo'); } @@ -186,8 +184,7 @@ public function testHeadersAggregatesHeadersThroughAddHeaders() public function testHeadersAddHeadersThrowsExceptionOnInvalidArguments() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Expected array or Trav'); + $this->setExpectedException(InvalidArgumentException::class, 'Expected array or Trav'); $headers = new Headers(); $headers->addHeaders('foo'); } @@ -295,7 +292,7 @@ public function testZeroIsAValidHeaderValue() */ public function testCRLFAttack() { - $this->expectException(RuntimeException::class); + $this->setExpectedException(RuntimeException::class); Headers::fromString("Fake: foo-bar\r\n\r\nevilContent"); } } diff --git a/test/PhpEnvironment/RequestTest.php b/test/PhpEnvironment/RequestTest.php index fc74943c22..722f184ed9 100644 --- a/test/PhpEnvironment/RequestTest.php +++ b/test/PhpEnvironment/RequestTest.php @@ -765,8 +765,7 @@ public function testAllowCustomMethodsFlagCanBeSetWithConstructor() { $_SERVER['REQUEST_METHOD'] = 'xcustomx'; - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid HTTP method passed'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid HTTP method passed'); new Request(false); } diff --git a/test/PhpEnvironment/ResponseTest.php b/test/PhpEnvironment/ResponseTest.php index 123f114af3..53c17819e7 100644 --- a/test/PhpEnvironment/ResponseTest.php +++ b/test/PhpEnvironment/ResponseTest.php @@ -96,7 +96,7 @@ public function testCanExplicitlySetVersion() $response->setVersion(Response::VERSION_10); $this->assertSame(Response::VERSION_10, $response->getVersion()); - $this->expectException(InvalidArgumentException::class); + $this->setExpectedException(InvalidArgumentException::class); $response->setVersion('zf/2.0'); } } diff --git a/test/RequestTest.php b/test/RequestTest.php index 0f977f08fa..975283e391 100644 --- a/test/RequestTest.php +++ b/test/RequestTest.php @@ -164,8 +164,7 @@ public function testRequestSetUriWillThrowExceptionOnInvalidArgument() { $request = new Request(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('must be an instance of'); + $this->setExpectedException(InvalidArgumentException::class, 'must be an instance of'); $request->setUri(new stdClass()); } @@ -181,8 +180,7 @@ public function testRequestSetVersionWillThrowExceptionOnInvalidArgument() { $request = new Request(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Not valid or not supported HTTP version'); + $this->setExpectedException(InvalidArgumentException::class, 'Not valid or not supported HTTP version'); $request->setVersion('1.2'); } @@ -283,8 +281,7 @@ public function testDisallowCustomMethods() $request = new Request(); $request->setAllowCustomMethods(false); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid HTTP method passed'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid HTTP method passed'); $request->setMethod('xcustom'); } @@ -299,8 +296,10 @@ public function testCustomMethodsFromString() public function testDisallowCustomMethodsFromString() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('A valid request line was not found in the provided string'); + $this->setExpectedException( + InvalidArgumentException::class, + 'A valid request line was not found in the provided string' + ); Request::fromString('X-CUS_TOM someurl', false); } @@ -329,7 +328,7 @@ public function testFromStringFactoryCreatesSingleObjectWithHeaderFolding() */ public function testCRLFAttack() { - $this->expectException(RuntimeException::class); + $this->setExpectedException(RuntimeException::class); Request::fromString( "GET /foo HTTP/1.1\r\nHost: example.com\r\nX-Foo: This\ris\r\n\r\nCRLF\nInjection" ); diff --git a/test/ResponseTest.php b/test/ResponseTest.php index bd6f36abb4..14b43b15d8 100644 --- a/test/ResponseTest.php +++ b/test/ResponseTest.php @@ -62,8 +62,7 @@ public function testResponseCanSetStatusCode() public function testResponseSetStatusCodeThrowsExceptionOnInvalidCode() { $response = new Response(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid status code'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid status code'); $response->setStatusCode(606); } @@ -85,8 +84,7 @@ public function testResponseCanSetCustomStatusCode() public function testResponseSetCustomStatusCodeThrowsExceptionOnInvalidCode() { $response = new Response(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid status code provided: "foo"'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid status code provided: "foo"'); $response->setStatusCode('foo'); } @@ -379,8 +377,7 @@ public function testGetVersion() public function testUnknownCode() { $responseStr = $this->readResponse('response_unknown'); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Invalid status code provided: "550"'); + $this->setExpectedException(InvalidArgumentException::class, 'Invalid status code provided: "550"'); $response = Response::fromString($responseStr); $this->assertEquals(550, $response->getStatusCode()); } @@ -445,12 +442,22 @@ public function testromStringFactoryCreatesSingleObjectWithHeaderFolding() */ public function testPreventsCRLFAttackWhenDeserializing() { - $this->expectException(RuntimeException::class); + $this->setExpectedException(RuntimeException::class); Response::fromString( "HTTP/1.1 200 OK\r\nAllow: POST\r\nX-Foo: This\ris\r\n\r\nCRLF\nInjection" ); } + public function test100ContinueFromString() + { + $fixture = 'TOKEN=EC%XXXXXXXXXXXXX&TIMESTAMP=2017%2d10%2d10T09%3a02%3a55Z' + ."&CORRELATIONID=XXXXXXXXXX&ACK=Success&VERSION=65%2e1&BUILD=XXXXXXXXXX\r\n"; + + $request = Response::fromString($this->readResponse('response_100_continue')); + $this->assertEquals(Response::STATUS_CODE_200, $request->getStatusCode()); + $this->assertEquals($fixture, $request->getBody()); + } + /** * Helper function: read test response from file * diff --git a/test/_files/response_100_continue b/test/_files/response_100_continue new file mode 100644 index 0000000000..690927766f --- /dev/null +++ b/test/_files/response_100_continue @@ -0,0 +1,17 @@ +HTTP/1.1 100 Continue + +HTTP/1.1 200 OK +Date: Tue, 10 Oct 2017 09:02:53 GMT +Server: Apache +X-SLR-RETRY-API: SetExpressCheckout +X-PAYPAL-OPERATION-NAME: SetExpressCheckout +X-PAYPAL-API-RC: +Connection: close +HTTP_X_PP_AZ_LOCATOR: sandbox.slc +Paypal-Debug-Id: e8abe44ddc3bd +Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dappdispatcher_apit%26TIME%3D3196902489%26HTTP_X_PP_AZ_LOCATOR%3Dsandbox.slc; Expires=Tue, 10 Oct 2017 09:32:55 GMT; domain=.paypal.com; path=/; Secure; HttpOnly +Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT +Content-Length: 137 +Content-Type: text/plain; charset=utf-8 + +TOKEN=EC%XXXXXXXXXXXXX&TIMESTAMP=2017%2d10%2d10T09%3a02%3a55Z&CORRELATIONID=XXXXXXXXXX&ACK=Success&VERSION=65%2e1&BUILD=XXXXXXXXXX