Loading data/nginx/server.conf +5 −0 Original line number Diff line number Diff line Loading @@ -120,4 +120,9 @@ server { include safe.types; default_type application/octet-stream; } # Disable serving directly from any page cache in /wp-content/cache location /wp-content/cache/ { return 404; } } scripts/entrypoint.sh +12 −16 Original line number Diff line number Diff line Loading @@ -167,24 +167,20 @@ setup_components() { return 0 } get_media_dir() get_writable_dirs() { [[ -v MEDIA ]] && return MEDIA=$( [[ -v MEDIA && -v CACHE ]] && return local content=$( wp config get WP_CONTENT_DIR --type=constant || echo wp-content ) local media=$( wp config get UPLOADS --type=constant || wp option get upload_path ) [[ -n "${MEDIA}" ]] && return local _wp_content=$(wp config get WP_CONTENT_DIR --type=constant) MEDIA=${_wp_content:-wp-content}/uploads } setup_media() { # UID values change on every run, ensure the owner and group are set # correctly on the media directory/volume. get_media_dir chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" MEDIA=${media:-${content}/uploads} CACHE=${content}/cache mkdir -p "${MEDIA}" "${CACHE}" chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" "${CACHE}" } setup_sandbox() Loading Loading @@ -233,7 +229,7 @@ setup_debug() collect_static() { get_media_dir get_writable_dirs local IFS=, declare -a flags=(flist stats remove del) test -t 1 && flags+=(progress2) Loading @@ -244,6 +240,7 @@ collect_static() --exclude-from=- \ --exclude='*.php' \ --exclude="${MEDIA}" \ --exclude="${CACHE}" \ --exclude=/static/ \ --exclude=/vendor/ \ --force \ Loading Loading @@ -349,7 +346,6 @@ case "$1" in create_config setup_components setup_debug setup_media collect_static generate_static setup_sandbox Loading tests/configs/test-cache.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php /* Plugin Name: Test Plugin Description: Assists in the testing of some scenarios */ add_action( 'rest_api_init', function() { register_rest_route( 'test/v1', '/write-cache', array( 'methods' => WP_REST_Server::READABLE, 'callback' => function($request) { if ( !isset($request['file']) ) { return new WP_Error('Missing param file'); } $file = WP_CONTENT_DIR . "/cache/{$request['file']}"; file_put_contents($file, "Generated file"); return rest_ensure_response( "Cache file created" ); }, 'args' => array( 'file' => array( 'description' => 'File to touch on the server host', 'type' => 'string', ) ) )); }); /* register_activation_hook( __FILE__, function() { */ /* if ( !defined('WP_CLI') && $_SERVER['REQUEST_URI'] == '/test-cache' ) { */ /* $file = WP_CONTENT_DIR . "/cache/${_GET['file']}"; */ /* file_put_contents($file, "Generated file"); */ /* wp_die("Cache file created", 200); */ /* } */ /* }); */ tests/regression-28.feature 0 → 100644 +17 −0 Original line number Diff line number Diff line @wip Feature: Page cache directory Ensure that the page cache directory at WP_CONTENT_DIR/cache is writable for plugins, but is not served by the server. Scenario: After the entrypoint has completed, there is a writable cache dir Given the site is not running And test-cache.php is mounted in /app/wp-content/mu-plugins/ When the site is started And /wp-json/test/v1/write-cache?file=foo.txt is requested Then OK is returned And /app/wp-content/cache/foo.txt exists in the backend Scenario: The contents of the cache dir are not served by the proxy Given /app/wp-content/cache/foo exists in the backend When /wp-content/cache/foo is requested Then Not Found is returned tests/steps/site.py +11 −0 Original line number Diff line number Diff line Loading @@ -231,6 +231,17 @@ def is_plugin_installed( assert site.backend.cli(addon.value, "is-active", name, query=True) == status.value @then("{path:Path} exists in the {container_name}") def check_file_exists(context: Context, path: Path, container_name: str) -> None: """ Check a file exists in the named container """ site = use_fixture(site_fixture, context) container = getattr(site, container_name) assert container.run(["sh", "-c", f"test -e {path}"]).returncode == 0, \ f"{path} not found in the {container_name}" @then("the email address of {user} is \"{value}\"") @then("the email address of {user} is '{value}'") def is_user_email(context: Context, user: str, value: str) -> None: Loading Loading
data/nginx/server.conf +5 −0 Original line number Diff line number Diff line Loading @@ -120,4 +120,9 @@ server { include safe.types; default_type application/octet-stream; } # Disable serving directly from any page cache in /wp-content/cache location /wp-content/cache/ { return 404; } }
scripts/entrypoint.sh +12 −16 Original line number Diff line number Diff line Loading @@ -167,24 +167,20 @@ setup_components() { return 0 } get_media_dir() get_writable_dirs() { [[ -v MEDIA ]] && return MEDIA=$( [[ -v MEDIA && -v CACHE ]] && return local content=$( wp config get WP_CONTENT_DIR --type=constant || echo wp-content ) local media=$( wp config get UPLOADS --type=constant || wp option get upload_path ) [[ -n "${MEDIA}" ]] && return local _wp_content=$(wp config get WP_CONTENT_DIR --type=constant) MEDIA=${_wp_content:-wp-content}/uploads } setup_media() { # UID values change on every run, ensure the owner and group are set # correctly on the media directory/volume. get_media_dir chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" MEDIA=${media:-${content}/uploads} CACHE=${content}/cache mkdir -p "${MEDIA}" "${CACHE}" chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" "${CACHE}" } setup_sandbox() Loading Loading @@ -233,7 +229,7 @@ setup_debug() collect_static() { get_media_dir get_writable_dirs local IFS=, declare -a flags=(flist stats remove del) test -t 1 && flags+=(progress2) Loading @@ -244,6 +240,7 @@ collect_static() --exclude-from=- \ --exclude='*.php' \ --exclude="${MEDIA}" \ --exclude="${CACHE}" \ --exclude=/static/ \ --exclude=/vendor/ \ --force \ Loading Loading @@ -349,7 +346,6 @@ case "$1" in create_config setup_components setup_debug setup_media collect_static generate_static setup_sandbox Loading
tests/configs/test-cache.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php /* Plugin Name: Test Plugin Description: Assists in the testing of some scenarios */ add_action( 'rest_api_init', function() { register_rest_route( 'test/v1', '/write-cache', array( 'methods' => WP_REST_Server::READABLE, 'callback' => function($request) { if ( !isset($request['file']) ) { return new WP_Error('Missing param file'); } $file = WP_CONTENT_DIR . "/cache/{$request['file']}"; file_put_contents($file, "Generated file"); return rest_ensure_response( "Cache file created" ); }, 'args' => array( 'file' => array( 'description' => 'File to touch on the server host', 'type' => 'string', ) ) )); }); /* register_activation_hook( __FILE__, function() { */ /* if ( !defined('WP_CLI') && $_SERVER['REQUEST_URI'] == '/test-cache' ) { */ /* $file = WP_CONTENT_DIR . "/cache/${_GET['file']}"; */ /* file_put_contents($file, "Generated file"); */ /* wp_die("Cache file created", 200); */ /* } */ /* }); */
tests/regression-28.feature 0 → 100644 +17 −0 Original line number Diff line number Diff line @wip Feature: Page cache directory Ensure that the page cache directory at WP_CONTENT_DIR/cache is writable for plugins, but is not served by the server. Scenario: After the entrypoint has completed, there is a writable cache dir Given the site is not running And test-cache.php is mounted in /app/wp-content/mu-plugins/ When the site is started And /wp-json/test/v1/write-cache?file=foo.txt is requested Then OK is returned And /app/wp-content/cache/foo.txt exists in the backend Scenario: The contents of the cache dir are not served by the proxy Given /app/wp-content/cache/foo exists in the backend When /wp-content/cache/foo is requested Then Not Found is returned
tests/steps/site.py +11 −0 Original line number Diff line number Diff line Loading @@ -231,6 +231,17 @@ def is_plugin_installed( assert site.backend.cli(addon.value, "is-active", name, query=True) == status.value @then("{path:Path} exists in the {container_name}") def check_file_exists(context: Context, path: Path, container_name: str) -> None: """ Check a file exists in the named container """ site = use_fixture(site_fixture, context) container = getattr(site, container_name) assert container.run(["sh", "-c", f"test -e {path}"]).returncode == 0, \ f"{path} not found in the {container_name}" @then("the email address of {user} is \"{value}\"") @then("the email address of {user} is '{value}'") def is_user_email(context: Context, user: str, value: str) -> None: Loading