Skip to content

Commit 3636585

Browse files
committed
add more test CodeIgniter::forceSecureAccess() run force_https()
1 parent dc733a9 commit 3636585

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

system/Common.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function force_https(int $duration = 31536000, RequestInterface $request = null,
403403
$response = Services::response(null, true);
404404
}
405405

406-
if (is_cli() || $request->isSecure())
406+
if (ENVIRONMENT !== 'testing' && (is_cli() || $request->isSecure()))
407407
{
408408
return;
409409
}
@@ -433,7 +433,10 @@ function force_https(int $duration = 31536000, RequestInterface $request = null,
433433
$response->redirect($uri);
434434
$response->sendHeaders();
435435

436-
exit();
436+
if (ENVIRONMENT !== 'testing')
437+
{
438+
exit();
439+
}
437440
// @codeCoverageIgnoreEnd
438441
}
439442
}

tests/system/CodeIgniterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,26 @@ public function testIgnoringErrorSuppressedByAt()
273273

274274
$this->assertStringContainsString('Welcome to CodeIgniter', $output);
275275
}
276+
277+
//--------------------------------------------------------------------
278+
279+
public function testRunForceSecure()
280+
{
281+
$_SERVER['argv'] = [
282+
'index.php',
283+
'/',
284+
];
285+
$_SERVER['argc'] = 2;
286+
287+
$config = new App();
288+
$config->forceGlobalSecureRequests = true;
289+
$codeigniter = new MockCodeIgniter($config);
290+
291+
ob_start();
292+
$codeigniter->useSafeOutput(true)->run();
293+
$output = ob_get_clean();
294+
295+
$response = $this->getPrivateProperty($codeigniter, 'response');
296+
$this->assertEquals('https://example.com', $response->getHeader('Location')->getValue());
297+
}
276298
}

0 commit comments

Comments
 (0)