From 225629ee704d4365879ff1403c4f40bd7c8a7bb4 Mon Sep 17 00:00:00 2001 From: roquie Date: Tue, 6 Sep 2022 13:58:48 +0300 Subject: [PATCH] 1. User a human-readable header parser error message when user wants to use a `:` character in header values. 2. Fixed image building for M1 processor 3. Add a normal compatibility with PHP 8.1 --- CHANGELOG.md | 1 + Dockerfile | 6 +++--- Makefile | 8 ++++---- box.dockerfile | 4 ++-- src/Header/ConvertsHeader.php | 12 +++++++++--- test.dockerfile | 6 +++--- tests/Header/HeaderTest.php | 12 ++++++++++++ tests/configuration/headers_warning/server.yaml | 7 +++++++ tests/example_dist/head_link_not_exists/index.html | 4 ++-- tests/example_dist/vue/index.html | 4 ++-- 10 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 tests/configuration/headers_warning/server.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c58a2d..b19fb07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ None. ### Fixed * Fixes prerender host proxy (add nginx option `proxy_ssl_server_name on`). +* User a human-readable header parser error message when user wants to use a `:` character in header values. ## [4.0.0] - 2020-01-03 diff --git a/Dockerfile b/Dockerfile index c34cb9e..20eca83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ -FROM composer/composer:2 AS deps +FROM --platform=amd64 composer/composer:2 AS deps COPY . /app RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs -FROM spacetabio/box-php:1.0.0 AS build +FROM --platform=amd64 spacetabio/box-php:1.1.0 AS build WORKDIR /app COPY --from=deps /app /app RUN box compile -FROM php:8.1-cli-alpine +FROM --platform=amd64 php:8.1-cli-alpine ENV NGINX_VERSION 1.21.1 ENV NGX_BROTLI_COMMIT 9aec15e2aa6feea2113119ba06460af70ab3ea62 diff --git a/Makefile b/Makefile index 751c062..faf2ce3 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ FILE = Dockerfile image: sed "s/{{ version }}/$(VERSION)/g" $(FILE) > /tmp/$(FILE) - docker build -f /tmp/$(FILE) -t $(IMAGE):$(VERSION) . + docker build --platform linux/amd64 -f /tmp/$(FILE) -t $(IMAGE):$(VERSION) . push: docker push $(IMAGE):$(VERSION) @@ -17,13 +17,13 @@ test: $(IMAGE):4.1.0-xdebug -c "vendor/bin/phpunit" image_test: - docker build -t $(IMAGE):4.1.0-xdebug -f test.dockerfile . + docker build --platform linux/amd64 -t $(IMAGE):4.1.0-xdebug -f test.dockerfile . push_test: docker push $(IMAGE):4.1.0-xdebug image_box: - docker build -t spacetabio/box-php:1.0.0 -f box.dockerfile . + docker build --platform linux/amd64 -t spacetabio/box-php:1.1.0 -f box.dockerfile . push_box: - docker push spacetabio/box-php:1.0.0 + docker push spacetabio/box-php:1.1.0 diff --git a/box.dockerfile b/box.dockerfile index 0e57091..bce73e4 100644 --- a/box.dockerfile +++ b/box.dockerfile @@ -1,6 +1,6 @@ -FROM php:8.0-cli-alpine +FROM --platform=amd64 php:8.1-cli-alpine -RUN wget https://github.com/box-project/box/releases/download/3.11.1/box.phar \ +RUN wget https://github.com/box-project/box/releases/download/4.0.2/box.phar \ && mv box.phar /usr/local/bin/box \ && chmod +x /usr/local/bin/box diff --git a/src/Header/ConvertsHeader.php b/src/Header/ConvertsHeader.php index 23b48e3..4023bd2 100644 --- a/src/Header/ConvertsHeader.php +++ b/src/Header/ConvertsHeader.php @@ -4,8 +4,10 @@ namespace Spacetab\Server\Header; +use InvalidArgumentException; use Spacetab\Configuration\ConfigurationInterface; use Spacetab\Server\Exception\HeaderException; +use Throwable; final class ConvertsHeader implements HeaderInterface { @@ -42,7 +44,11 @@ public function convert(): array // Backward compatibility. if (!isset($values[0]['value'])) { - $results[$item] = join('; ', (array) $values); + try { + $results[$item] = implode('; ', (array) $values); + } catch (Throwable) { + throw new InvalidArgumentException('Headers parse error. Check : symbol or indentation (use "" for escaping :).'); + } } // Checks new extended format for sent headers from yaml values. @@ -53,10 +59,10 @@ public function convert(): array throw HeaderException::invalidHeaderFormat(); } - $array[] = join('; ', (array) $value['value']); + $array[] = implode('; ', (array) $value['value']); } - $results[$item] = join(', ', $array); + $results[$item] = implode(', ', $array); } } diff --git a/test.dockerfile b/test.dockerfile index 54452bf..a6d7a04 100644 --- a/test.dockerfile +++ b/test.dockerfile @@ -1,16 +1,16 @@ -FROM composer/composer:2 AS deps +FROM --platform=amd64 composer/composer:2 AS deps COPY . /app RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs -FROM spacetabio/box-php:1.0.0 AS build +FROM --platform=amd64 spacetabio/box-php:1.0.0 AS build WORKDIR /app COPY --from=deps /app /app RUN box compile -FROM php:8.1-cli-alpine +FROM --platform=amd64 php:8.1-cli-alpine ENV NGINX_VERSION 1.21.1 ENV NGX_BROTLI_COMMIT 9aec15e2aa6feea2113119ba06460af70ab3ea62 diff --git a/tests/Header/HeaderTest.php b/tests/Header/HeaderTest.php index 0093b9f..1d5d368 100644 --- a/tests/Header/HeaderTest.php +++ b/tests/Header/HeaderTest.php @@ -4,6 +4,7 @@ namespace Spacetab\Tests\Server\Header; +use InvalidArgumentException; use Spacetab\Configuration\Configuration; use Spacetab\Server\Exception\HeaderException; use Spacetab\Server\Header\ConvertsHeader; @@ -50,4 +51,15 @@ public function testHowInvalidHeaderValueCheckWorks() $h = new ConvertsHeader($conf); $h->convert(); } + + public function testInvalidToStringConversionWhenHeadersParsed() + { + $conf = new Configuration(__DIR__ . '/../configuration', 'headers_warning'); + $conf->load(); + + $this->expectException(InvalidArgumentException::class); + + $h = new ConvertsHeader($conf); + $h->convert(); + } } diff --git a/tests/configuration/headers_warning/server.yaml b/tests/configuration/headers_warning/server.yaml new file mode 100644 index 0000000..2cf9a07 --- /dev/null +++ b/tests/configuration/headers_warning/server.yaml @@ -0,0 +1,7 @@ +headers_warning: + server: + headers: + contentSecurityPolicy: + - "default-src 'self' data": 'https://*.teaworkshop.ru *.cdek.ru pickpoint.ru api-maps.yandex.ru maps.yandex.net https://*.jivosite.com https://*.dadata.ru sentry.io *.yandex.ru *.vk.com *.googletagmanager.com *.google-analytics.com https://*.facebook.net https://*.facebook.com' + port: 8081 + root: ./tests/example_dist/simple diff --git a/tests/example_dist/head_link_not_exists/index.html b/tests/example_dist/head_link_not_exists/index.html index 090d842..95ad5e2 100644 --- a/tests/example_dist/head_link_not_exists/index.html +++ b/tests/example_dist/head_link_not_exists/index.html @@ -5,10 +5,10 @@ Document - + hello stranger! - diff --git a/tests/example_dist/vue/index.html b/tests/example_dist/vue/index.html index 392bd0e..6eafa8f 100644 --- a/tests/example_dist/vue/index.html +++ b/tests/example_dist/vue/index.html @@ -4,7 +4,7 @@ - + example_dist @@ -16,7 +16,7 @@
- +