Skip to content

Commit

Permalink
Merge pull request #3973 from codeigniter4/redundant-http-keys
Browse files Browse the repository at this point in the history
Deprecate redundant HTTP keys
  • Loading branch information
MGatner authored Jan 5, 2021
2 parents 5ad1235 + 92bfe95 commit 034e0c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion system/HTTP/Exceptions/HTTPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,6 @@ public static function forMoveFailed(string $source, string $target, string $err
*/
public static function forInvalidSameSiteSetting(string $samesite)
{
return new static(lang('HTTP.invalidSameSiteSetting', [$samesite]));
return new static(lang('Security.invalidSameSiteSetting', [$samesite]));
}
}
2 changes: 2 additions & 0 deletions system/Language/en/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'methodNotFound' => 'Controller method is not found: {0}',

// CSRF
// @deprecated use `Security.disallowedAction`
'disallowedAction' => 'The action you requested is not allowed.',

// Uploaded file moving
Expand All @@ -72,5 +73,6 @@
'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.',

// SameSite setting
// @deprecated use `Security.invalidSameSiteSetting`
'invalidSameSiteSetting' => 'The SameSite setting must be None, Lax, Strict, or a blank string. Given: {0}',
];
2 changes: 1 addition & 1 deletion tests/system/HTTP/ResponseCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function testCookieInvalidSameSite()
$response = new Response($config);

$this->expectException(HTTPException::class);
$this->expectExceptionMessage(lang('HTTP.invalidSameSiteSetting', ['Invalid']));
$this->expectExceptionMessage(lang('Security.invalidSameSiteSetting', ['Invalid']));

$response->setCookie([
'name' => 'bar',
Expand Down
22 changes: 11 additions & 11 deletions tests/system/HTTP/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace CodeIgniter\HTTP;

use CodeIgniter\Config\Config;
use CodeIgniter\Config\Factories;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockResponse;
use Config\App;
use Config\Services;
use DateTime;
use DateTimeZone;

class ResponseTest extends \CodeIgniter\Test\CIUnitTestCase
class ResponseTest extends CIUnitTestCase
{

protected $server;

protected function setUp(): void
Expand All @@ -24,7 +24,7 @@ protected function setUp(): void
public function tearDown(): void
{
$_SERVER = $this->server;
Config::reset();
Factories::reset('config');
}

public function testCanSetStatusCode()
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testSetStatusCodeSetsReason()

$response->setStatusCode(200);

$this->assertEquals('OK', $response->getReason());
$this->assertEquals('OK', $response->getReasonPhrase());
}

//--------------------------------------------------------------------
Expand All @@ -76,7 +76,7 @@ public function testCanSetCustomReasonCode()

$response->setStatusCode(200, 'Not the mama');

$this->assertEquals('Not the mama', $response->getReason());
$this->assertEquals('Not the mama', $response->getReasonPhrase());
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testSetStatusCodeInterpretsReason()

$response->setStatusCode(300);

$this->assertEquals('Multiple Choices', $response->getReason());
$this->assertEquals('Multiple Choices', $response->getReasonPhrase());
}

//--------------------------------------------------------------------
Expand All @@ -131,7 +131,7 @@ public function testSetStatusCodeSavesCustomReason()

$response->setStatusCode(300, 'My Little Pony');

$this->assertEquals('My Little Pony', $response->getReason());
$this->assertEquals('My Little Pony', $response->getReasonPhrase());
}

//--------------------------------------------------------------------
Expand All @@ -140,7 +140,7 @@ public function testGetReasonDefaultsToOK()
{
$response = new Response(new App());

$this->assertEquals('OK', $response->getReason());
$this->assertEquals('OK', $response->getReasonPhrase());
}

//--------------------------------------------------------------------
Expand All @@ -166,7 +166,7 @@ public function testSetLink()
// Ensure our URL is not getting overridden
$config = new App();
$config->baseURL = 'http://example.com/test/';
Config::injectMock('App', $config);
Factories::injectMock('config', 'App', $config);

$response = new Response($config);
$pager = \Config\Services::pager();
Expand Down Expand Up @@ -552,7 +552,7 @@ public function testInvalidSameSiteCookie()
$config->cookieSameSite = 'Invalid';

$this->expectException(HTTPException::class);
$this->expectExceptionMessage(lang('HTTP.invalidSameSiteSetting', ['Invalid']));
$this->expectExceptionMessage(lang('Security.invalidSameSiteSetting', ['Invalid']));
new Response($config);
}
}
2 changes: 1 addition & 1 deletion tests/system/Helpers/CookieHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testSameSiteInvalid()
];

$this->expectException(HTTPException::class);
$this->expectExceptionMessage(lang('HTTP.invalidSameSiteSetting', ['Invalid']));
$this->expectExceptionMessage(lang('Security.invalidSameSiteSetting', ['Invalid']));

set_cookie($cookieAttr);
}
Expand Down

0 comments on commit 034e0c4

Please sign in to comment.