Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "Full-Page Caching for 404s" feature requires ssl #77

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public function boot(): void {
* Only boot feature if external object cache is being used.
*
* We don't want to store the cached 404 page in the database.
*
* And only boot feature if the site is using SSL.
*/
if ( ! (bool) wp_using_ext_object_cache() ) {
if ( ! (bool) wp_using_ext_object_cache() || ! is_ssl() ) {
return;
}

Expand Down Expand Up @@ -116,6 +118,7 @@ public static function action__template_redirect(): void {

echo self::get_cached_response_with_headers(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

// If we're testing, don't exit, die instead.
if ( \defined( 'MANTLE_IS_TESTING' ) && MANTLE_IS_TESTING ) {
wp_die( '', '', [ 'response' => 404 ] );
}
Expand Down
27 changes: 25 additions & 2 deletions tests/alley/wp/alleyvate/features/test-full-page-cache-404.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ protected function setUp(): void {

$this->prevent_stray_requests();

// Turn SSL on.
$_SERVER['HTTPS'] = 'on';

$this->feature = new Full_Page_Cache_404();
}

Expand All @@ -53,7 +56,28 @@ public function tearDown(): void {
}

/**
* Test that the feature is disabled if the object cache is not in use.
* Test that the feature is disabled if SSL is off.
*/
public function test_feature_is_disabled_if_ssl_is_off(): void {
$this->assertTrue( is_ssl() );

$_SERVER['HTTPS'] = 'off';

$this->assertFalse( is_ssl() );

$this->feature->boot();

$response = $this->get( '/this-is-a-404-page' );
$response->assertStatus( 404 );

$this->assertFalse(
wp_next_scheduled( 'alleyvate_404_cache_single' ),
'Cron job to generate cached 404 page is scheduled and should not be.'
);
}

/**
* Test the feature is disabled if the object cache is not in use.
*/
public function test_feature_is_disabled_if_object_cache_is_not_in_use(): void {

Expand All @@ -71,7 +95,6 @@ public function test_feature_is_disabled_if_object_cache_is_not_in_use(): void {
$this->assertFalse( (bool) wp_using_ext_object_cache() );

$response = $this->get( '/this-is-a-404-page' );
$response->assertDontSee( $this->feature::prepare_response( $this->get_404_html() ) );
$response->assertStatus( 404 );

$this->assertFalse(
Expand Down
Loading