Skip to content

Commit 31f7850

Browse files
ebinniondereksmart
authored andcommitted
Sync: Add protocol to raw urls (#7984)
1 parent 544541a commit 31f7850

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

sync/class.jetpack-sync-functions.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public static function get_hosting_provider() {
8181
}
8282
if ( defined( 'MM_BASE_DIR' ) ) {
8383
return 'bh';
84-
}
84+
}
8585
if ( defined( 'IS_PRESSABLE' ) ) {
8686
return 'pressable';
87-
}
87+
}
8888
if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) {
8989
return 'wpe';
9090
}
@@ -151,20 +151,22 @@ public static function file_system_write_access() {
151151
* @return string
152152
*/
153153
public static function get_raw_or_filtered_url( $url_type ) {
154+
$url_function = ( 'home' == $url_type )
155+
? 'home_url'
156+
: 'site_url';
157+
154158
if (
155159
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
156160
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
157161
) {
162+
$scheme = is_ssl() ? 'https' : 'http';
158163
$url = self::get_raw_url( $url_type );
164+
$url = set_url_scheme( $url, $scheme );
159165
} else {
160-
$url_function = ( 'home' == $url_type )
161-
? 'home_url'
162-
: 'site_url';
163166
$url = self::normalize_www_in_url( $url_type, $url_function );
164-
$url = self::get_protocol_normalized_url( $url_function, $url );
165167
}
166168

167-
return $url;
169+
return self::get_protocol_normalized_url( $url_function, $url );
168170
}
169171

170172
public static function home_url() {

tests/php/sync/test_class.jetpack-sync-callables.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function test_sync_always_sync_changes_to_modules_right_away() {
146146
Jetpack::update_active_modules( array( 'stats' ) );
147147

148148
$this->sender->do_sync();
149-
149+
150150
$synced_value = $this->server_replica_storage->get_callable( 'active_modules' );
151151
$this->assertEquals( array( 'stats' ), $synced_value );
152152

@@ -394,7 +394,7 @@ function test_get_protocol_normalized_url_cleared_on_reset_data() {
394394
}
395395

396396
function test_subdomain_switching_to_www_does_not_cause_sync() {
397-
// a lot of sites accept www.domain.com or just domain.com, and we want to prevent lots of
397+
// a lot of sites accept www.domain.com or just domain.com, and we want to prevent lots of
398398
// switching back and forth, so we force the domain to be the one in the siteurl option
399399
$this->setSyncClientDefaults();
400400
delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME );
@@ -429,7 +429,7 @@ function test_only_syncs_if_is_admin_and_not_cron() {
429429

430430
$this->sender->do_sync();
431431
$this->assertEquals( null, $this->server_replica_storage->get_callable( 'site_url' ) );
432-
432+
433433
Jetpack_Sync_Settings::set_doing_cron( false );
434434
$this->sender->do_sync();
435435
$this->assertEquals( site_url(), $this->server_replica_storage->get_callable( 'site_url' ) );
@@ -481,7 +481,7 @@ function test_calling_taxonomies_do_not_modify_global() {
481481
}
482482

483483
function test_sanitize_sync_taxonomies_method() {
484-
484+
485485
$sanitized = Jetpack_Sync_Functions::sanitize_taxonomy( (object) array( 'meta_box_cb' => 'post_tags_meta_box' ) );
486486
$this->assertEquals( $sanitized->meta_box_cb, 'post_tags_meta_box' );
487487

@@ -536,6 +536,26 @@ function test_get_raw_url_returns_with_http_if_is_ssl() {
536536
unset( $_SERVER['HTTPS'] );
537537
}
538538

539+
function test_raw_home_url_is_https_when_is_ssl() {
540+
Jetpack_Constants::set_constant( 'JETPACK_SYNC_USE_RAW_URL', true );
541+
542+
$home_option = get_option( 'home' );
543+
544+
// Test without https first
545+
$this->assertEquals(
546+
$home_option,
547+
Jetpack_Sync_Functions::home_url()
548+
);
549+
550+
// Now, with https
551+
$_SERVER['HTTPS'] = 'on';
552+
$this->assertEquals(
553+
set_url_scheme( $home_option, 'https' ),
554+
Jetpack_Sync_Functions::home_url()
555+
);
556+
unset( $_SERVER['HTTPS'] );
557+
}
558+
539559
function test_user_can_stop_raw_urls() {
540560
add_filter( 'option_home', array( $this, '__return_filtered_url' ) );
541561
add_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );
@@ -601,7 +621,7 @@ function test_plugin_action_links_get_synced() {
601621
function __return_filtered_url() {
602622
return 'http://filteredurl.com';
603623
}
604-
624+
605625
function add_www_subdomain_to_siteurl( $url ) {
606626
$parsed_url = parse_url( $url );
607627

0 commit comments

Comments
 (0)