Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ concurrency:

jobs:
mutation:
uses: yiisoft/actions/.github/workflows/roave-infection.yml@master
uses: yiisoft/actions/.github/workflows/infection.yml@master
with:
min-covered-msi: 100
os: >-
['ubuntu-latest']
php: >-
['8.3']
infection-args: --ignore-msi-with-no-mutations
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"bamarni/composer-bin-plugin": "^1.9.1",
"friendsofphp/php-cs-fixer": "^3.95",
"httpsoft/http-message": "^1.1.6",
"infection/infection": "^0.26.6 || ^0.27.10 || ^0.29.8 || ^0.35.8",
"phpunit/phpunit": "^9.6.22",
"rector/rector": "^2.5.8",
"roave/infection-static-analysis-plugin": "^1.25",
"shipmonk/composer-dependency-analyser": "^1.8",
"spatie/phpunit-watcher": "^1.23.6",
"vimeo/psalm": "^4.30 || ^5.26.1 || ^6.20.5",
Expand Down
5 changes: 2 additions & 3 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

## Mutation testing

The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:
The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:

```shell
./vendor/bin/roave-infection-static-analysis-plugin
./vendor/bin/infection
```

## Static analysis
Expand Down
40 changes: 40 additions & 0 deletions tests/TrustedHostsNetworkResolver/ConfigurationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,46 @@ public function dataWithForwardedHeaderGroupsException(): array
'Value in mapping for protocol header must be a valid protocol. Allowed values are: "http", "https" '
. '(case-sensitive).',
],
'protocol, array, resolving: array, value is not a string' => [
[
TrustedHostsNetworkResolver::FORWARDED_HEADER_RFC,
[
'ip' => 'y-forwarded-for',
'protocol' => [
'y-forwarded-proto',
[
'on1' => 'https',
'on2' => 1,
'on3' => 'https',
],
],
'host' => 'y-forwarded-host',
'port' => 'y-forwarded-port',
],
TrustedHostsNetworkResolver::FORWARDED_HEADER_GROUP_X_PREFIX,
],
'Value in mapping for protocol header must be non-empty string.',
],
'protocol, array, resolving: array, value is an empty string' => [
[
TrustedHostsNetworkResolver::FORWARDED_HEADER_RFC,
[
'ip' => 'y-forwarded-for',
'protocol' => [
'y-forwarded-proto',
[
'on1' => 'https',
'on2' => '',
'on3' => 'https',
],
],
'host' => 'y-forwarded-host',
'port' => 'y-forwarded-port',
],
TrustedHostsNetworkResolver::FORWARDED_HEADER_GROUP_X_PREFIX,
],
'Value in mapping for protocol header must be non-empty string.',
],
];
}

Expand Down
37 changes: 37 additions & 0 deletions tests/TrustedHostsNetworkResolver/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1529,4 +1529,41 @@ public function testProcess(
$this->assertSame($expectedData['host'] ?? '', $uri->getHost());
$this->assertSame($expectedData['port'] ?? null, $uri->getPort());
}

public function testRemoteAddrNotSetResetsConnectionChainItemsAttribute(): void
{
$middleware = $this
->createMiddleware()
->withTrustedIps(['8.8.8.8'])
->withConnectionChainItemsAttribute('connectionChainItems');
$request = $this
->createRequest()
->withAttribute('connectionChainItems', ['test']);
$requestHandler = new MockRequestHandler();

$middleware->process($request, $requestHandler);

$processedRequest = $requestHandler->processedRequest;
$this->assertNull($processedRequest->getAttribute('connectionChainItems', 'not-null'));
$this->assertNull(
$processedRequest->getAttribute(TrustedHostsNetworkResolver::ATTRIBUTE_REQUEST_CLIENT_IP, 'not-null'),
);
}

public function testRemoteAddrNotSetWithoutConnectionChainItemsAttribute(): void
{
$middleware = $this
->createMiddleware()
->withTrustedIps(['8.8.8.8']);
$request = $this->createRequest();
$requestHandler = new MockRequestHandler();

$response = $middleware->process($request, $requestHandler);

$this->assertSame(Status::OK, $response->getStatusCode());
$this->assertSame(
[TrustedHostsNetworkResolver::ATTRIBUTE_REQUEST_CLIENT_IP => null],
$requestHandler->processedRequest->getAttributes(),
);
}
}
Loading