Skip to content

Commit daa8811

Browse files
authored
Merge pull request #7890 from kenjis/fix-test-forceGlobalSecureRequests
fix: FeatureTest fails when forceGlobalSecureRequests is true
2 parents 398e44b + c8fc3d8 commit daa8811

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

system/Test/FeatureTestTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ protected function setupRequest(string $method, ?string $path = null): IncomingR
296296

297297
if ($config->forceGlobalSecureRequests) {
298298
$_SERVER['HTTPS'] = 'test';
299+
$server = $request->getServer();
300+
$server['HTTPS'] = 'test';
301+
$request->setGlobal('server', $server);
299302
}
300303

301304
return $request;

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use CodeIgniter\Events\Events;
1616
use CodeIgniter\Exceptions\PageNotFoundException;
1717
use CodeIgniter\HTTP\Response;
18+
use CodeIgniter\Test\Mock\MockCodeIgniter;
19+
use Config\App;
1820
use Config\Routing;
1921
use Config\Services;
2022

@@ -644,4 +646,19 @@ public function testAutoRoutingLegacy()
644646

645647
$response->assertOK();
646648
}
649+
650+
public function testForceGlobalSecureRequests()
651+
{
652+
$config = config(App::class);
653+
$config->forceGlobalSecureRequests = true;
654+
Factories::injectMock('config', App::class, $config);
655+
656+
$this->app = new MockCodeIgniter($config);
657+
$this->app->initialize();
658+
659+
$response = $this->get('/');
660+
661+
// Do not redirect.
662+
$response->assertStatus(200);
663+
}
647664
}

0 commit comments

Comments
 (0)