From 0d5ea695c2d6b3bcca850aa7c5940ae60816a04d Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 2 Dec 2026 08:20:12 +0530 Subject: [PATCH 1/2] test(redirect): cover the www redirect of a www site whose next label starts with w The scenario creates www.w..test and expects the redirect from w..test. It fails until the www counterpart strips only the `www.` prefix. --- features/COVERAGE.md | 6 +++--- features/redirect.feature | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/features/COVERAGE.md b/features/COVERAGE.md index d7233e5e..c5cac08b 100644 --- a/features/COVERAGE.md +++ b/features/COVERAGE.md @@ -1,12 +1,12 @@ # site-command Behat coverage -Suite for `easyengine/site-command` (the `ee site` command and the html site type, plus `ee site php-compat` on php and wp sites). 20 features, 258 scenarios (298 with outlines expanded): main lane 262, `@wp` 25, `@le` 11. Run it the CI way (`.github/workflows/behat.yml`): the files are copied into a core checkout's `features/` and core's `vendor/bin/behat` runs from the core root as root. +Suite for `easyengine/site-command` (the `ee site` command and the html site type, plus `ee site php-compat` on php and wp sites). 20 features, 259 scenarios (299 with outlines expanded): main lane 263, `@wp` 25, `@le` 11. Run it the CI way (`.github/workflows/behat.yml`): the files are copied into a core checkout's `features/` and core's `vendor/bin/behat` runs from the core root as root. ## Tags | Tag | Scenarios | Meaning | |---|---|---| -| (none of the tags below) | 176 | Local only: `*.test` sites, no public DNS, no remote storage, no global restarts. This is the default safe run. The php-compat scenarios pull the scanner image from Docker Hub when it isn't present. | +| (none of the tags below) | 177 | Local only: `*.test` sites, no public DNS, no remote storage, no global restarts. This is the default safe run. The php-compat scenarios pull the scanner image from Docker Hub when it isn't present. | | `@known-bug` | 0 | Scenarios that expose open bugs are kept outside this suite and come back with their fixes. The CI lanes still exclude the tag. | | `@destructive` | 12 | Restarts the GLOBAL nginx-proxy (proxy cache) or runs `ssl-renew --all` (refuses to start when an enabled LE site that isn't the suite's exists). Every scenario leaves the proxy running. | | `@remote` | 10 | Uses the REAL rclone remote (`rclone-path` in config.yml). Touches only `/bh-site-command-*`: the rclone path is listed first and only listed suite directories are purged (per site before a scenario, all of them after the feature). | @@ -264,6 +264,6 @@ Counting the rows above as items: 149 items, 114 covered, 1 partial, 34 not cove ## Known bugs left out -13 scenarios that expose open bugs are not part of this suite; each comes back with the PR that fixes its bug. They cover: the www redirect of a site whose next label starts with `w`, and the redirect after re-enabling a site when the www check fails; the owner lookup of an alias that contains another alias; `update --ssl=inherit` skipping the parent check; the inherit error message dumping the parent site object; the self-signed certificate leaving out alias domains; `ssl-info --get-dns-records` on self-signed sites; `ssl-verify` on a valid Let's Encrypt site; `site reload` exiting 0 when `nginx -t` fails; `site clean` without flags on html sites; invalid `--proxy-cache` values; the removed EE v3 cache flags message; and `update --php` on html sites failing late. +12 scenarios that expose open bugs are not part of this suite; each comes back with the PR that fixes its bug. They cover: the redirect after re-enabling a site when the www check fails; the owner lookup of an alias that contains another alias; `update --ssl=inherit` skipping the parent check; the inherit error message dumping the parent site object; the self-signed certificate leaving out alias domains; `ssl-info --get-dns-records` on self-signed sites; `ssl-verify` on a valid Let's Encrypt site; `site reload` exiting 0 when `nginx -t` fails; `site clean` without flags on html sites; invalid `--proxy-cache` values; the removed EE v3 cache flags message; and `update --php` on html sites failing late. PRs that change what passing scenarios assert, to revisit when they merge: EasyEngine/site-command#480 keeps `.lock` after a successful backup/restore (drop the two "lock should not exist" lines in backup). diff --git a/features/redirect.feature b/features/redirect.feature index cdb34faa..5afb533a 100644 --- a/features/redirect.feature +++ b/features/redirect.feature @@ -18,6 +18,15 @@ Feature: Site Redirection When I wait up to 60 seconds for "http://bh-site-command-121.test/" to return 301 Then the response header "Location" should be "http://www.bh-site-command-121.test/" + Scenario: A www site whose next label starts with w redirects the right name + Given the hosts file contains an entry for "w.bh-site-command-125.test" + And the site "www.w.bh-site-command-125.test" does not exist + When I run 'bin/ee site create www.w.bh-site-command-125.test' + Then the command should succeed + And the file "{PROXY_DIR}/conf.d/www.w.bh-site-command-125.test-redirect.conf" should contain "server_name w.bh-site-command-125.test;" + When I wait up to 60 seconds for "http://w.bh-site-command-125.test/" to return 301 + Then the response header "Location" should be "http://www.w.bh-site-command-125.test/" + Scenario: No redirect is written when the www name does not resolve here Given the site "bh-site-command-122.test" does not exist And the hosts file should not contain an entry for "www.bh-site-command-122.test" From 1907ef9dda19f8bbd126320e9ee03ef7f2575138 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 2 Dec 2026 08:22:12 +0530 Subject: [PATCH 2/2] fix(site): strip only the www. prefix for the www counterpart of a site `ltrim( $site_url, 'www.' )` (and `'.www'` in the redirect conf) strips a set of characters, not the prefix, so `www.w.x.test` became `x.test` and `www.web.test` became `eb.test`. The redirect conf got the wrong server_name, the www check requested the wrong host (so the redirect was dropped), and with the DNS challenge the Let's Encrypt order included a domain the site doesn't own. All three now use get_www_counterpart(), which drops exactly one leading `www.` or adds one. --- src/helper/class-ee-site.php | 15 ++------------- src/helper/site-utils.php | 9 +-------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 1a9ab13d..27d4d72f 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -2209,12 +2209,7 @@ private function get_cert_domains( string $site_url, $wildcard, $www_or_non_www if ( ! empty( $wildcard ) ) { $domains[] = "*.{$site_url}"; } elseif ( $www_or_non_www || $is_solver_dns ) { - if ( 0 === strpos( $site_url, 'www.' ) ) { - $www_or_non_www_site_url = ltrim( $site_url, 'www.' ); - } else { - $www_or_non_www_site_url = 'www.' . $site_url; - } - $domains[] = $www_or_non_www_site_url; + $domains[] = \EE\Site\Utils\get_www_counterpart( $site_url ); } return $domains; @@ -2255,13 +2250,7 @@ protected function check_www_or_non_www_domain( $site_url, $site_path, $site_con fwrite( $handle, $random_string ); fclose( $handle ); - if ( 0 === strpos( $site_url, 'www.' ) ) { - $site_url = ltrim( $site_url, 'www.' ); - } else { - $site_url = 'www.' . $site_url; - } - - $site_url .= '/' . $check_file; + $site_url = \EE\Site\Utils\get_www_counterpart( $site_url ) . '/' . $check_file; $curl = curl_init(); curl_setopt( $curl, CURLOPT_URL, $site_url ); diff --git a/src/helper/site-utils.php b/src/helper/site-utils.php index 887f058e..6a4614bb 100644 --- a/src/helper/site-utils.php +++ b/src/helper/site-utils.php @@ -588,7 +588,6 @@ function add_site_redirects( string $site_url, bool $ssl, bool $inherit ) { $fs = new Filesystem(); $confd_path = EE_ROOT_DIR . '/services/nginx-proxy/conf.d/'; $config_file_path = $confd_path . $site_url . '-redirect.conf'; - $has_www = strpos( $site_url, 'www.' ) === 0; $cert_site_name = $site_url; $ssl_policy = get_ssl_policy(); @@ -604,16 +603,10 @@ function add_site_redirects( string $site_url, bool $ssl, bool $inherit ) { $key_file = $certs_dir . $cert_site_name . '.key'; if ( ( $ssl && file_exists( $crt_file ) && file_exists( $key_file ) ) || ! $ssl ) { - if ( $has_www ) { - $server_name = ltrim( $site_url, '.www' ); - } else { - $server_name = 'www.' . $site_url; - } - $conf_data = [ 'site_name' => $site_url, 'cert_site_name' => $cert_site_name, - 'server_name' => $server_name, + 'server_name' => get_www_counterpart( $site_url ), 'ssl' => $ssl, $conf_ssl_policy => true, ];