From ab5f712f19306c3f6c9b9d62f26bf1a813df6d99 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Thu, 11 Nov 2021 20:57:03 +0000 Subject: [PATCH 1/4] Update phpunit.xml to 9.3 schema --- .gitignore | 1 + phpunit.xml | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 05ab16b..42a2b0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build vendor composer.lock +.phpunit.result.cache diff --git a/phpunit.xml b/phpunit.xml index fb5fbdc..adb3c4a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ ./tests/ - - + + ./src - - - \ No newline at end of file + + + From e8c60a9d02b321e31b753c3c6d05131cf7d5cfc1 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Thu, 11 Nov 2021 20:57:32 +0000 Subject: [PATCH 2/4] Add PHP 8.1 to GitHub Actions --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ef382a3..e0c7c4e 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ jobs: - "7.3" - "7.4" - "8.0" + - "8.1" operating-system: - "ubuntu-latest" From a01faa8eca046252e7b173cb1d23970f359560ba Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Thu, 11 Nov 2021 20:57:49 +0000 Subject: [PATCH 3/4] Use a string for $ipAddress PHP 8.1 gets upset if we pass a null to strpos(), etc. However, to avoid a BC break, we return a null if it's an empty string at the end of determineClientIpAddress(). --- src/IpAddress.php | 6 +++++- tests/IpAddressTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/IpAddress.php b/src/IpAddress.php index 93a0808..409366d 100644 --- a/src/IpAddress.php +++ b/src/IpAddress.php @@ -162,7 +162,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res */ protected function determineClientIpAddress($request) { - $ipAddress = null; + $ipAddress = ''; $serverParams = $request->getServerParams(); if (isset($serverParams['REMOTE_ADDR'])) { @@ -234,6 +234,10 @@ protected function determineClientIpAddress($request) } } + if (empty($ipAddress)) { + $ipAddress = null; + } + return $ipAddress; } diff --git a/tests/IpAddressTest.php b/tests/IpAddressTest.php index 88e4a2b..9a185a4 100644 --- a/tests/IpAddressTest.php +++ b/tests/IpAddressTest.php @@ -128,6 +128,17 @@ public function testIpIsNullIfMissing() $this->assertNull($ipAddress); } + public function testIpIsNullIfMissingAndProxiesAreConfigured() + { + error_reporting(-1); + $middleware = new IPAddress(true, ['*'], 'IP'); + $env = []; + $ipAddress = $this->simpleRequest($middleware, $env, 'IP'); + + $this->assertSame(null, $ipAddress); + } + + public function testXForwardedForIp() { $middleware = new IPAddress(true, []); From b935f5d6fdae5ae68d845f68ef34b58ebd89b092 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Thu, 11 Nov 2021 21:04:39 +0000 Subject: [PATCH 4/4] Simplify CI unit test matrix --- .github/workflows/unit-tests.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e0c7c4e..a4ee0f2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -12,9 +12,6 @@ jobs: strategy: matrix: - dependencies: - - "lowest" - - "highest" php-version: - "7.2" - "7.3" @@ -44,15 +41,10 @@ jobs: path: | ~/.composer/cache vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" + key: "php-${{ matrix.php-version }}" + restore-keys: "php-${{ matrix.php-version }}" - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} run: "composer update --no-interaction --no-progress --no-suggest" - name: "Tests"