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: 1 addition & 2 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]

name: Coding standards test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -89,7 +89,6 @@ jobs:
run: ddev phpstan /var/www/html/${{env.EXTENSION_PATH}}/tools/coding-standards phpstan/phpstan.neon /var/www/html/${{env.EXTENSION_PATH}}/src

- name: Run PSALM
if: contains(fromJson('["7.4","8.0","8.1","8.2","8.3"]'),matrix.php-version)
run: ddev psalm ./${{env.EXTENSION_PATH}}/tools/coding-standards /var/www/html/${{env.EXTENSION_PATH}}/tools/coding-standards/psalm

- name: Run PHPUNIT Code Coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-sdk-development-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ]
php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5" ]

name: Unit and integration test
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ name: Create Release
# example: gh workflow run release.yml -f tag_name=v1.1.4
on:
workflow_dispatch:
branches:
- main
inputs:
tag_name:
type: string
required: true
description: Tag with v prefix

jobs:
prepare-release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-and-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ]
php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5" ]

name: Unit and integration test
runs-on: ubuntu-latest
Expand Down
10 changes: 8 additions & 2 deletions docs/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,18 @@ mkdir cfssl
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* cfssl
```

Delete existing decisions:

```bash
ddev exec -s crowdsec cscli alerts delete --all
```

Finally, run

In order to launch integration tests, we have to set some environment variables:

```bash
ddev exec BOUNCER_KEY=<BOUNCER_KEY> AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit ./my-code/lapi-client/tests/Integration --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testdox --exclude-group timeout
ddev exec BOUNCER_KEY=<BOUNCER_KEY> AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testsuite Integration-Watcher,Integration-Bouncer --testdox --exclude-group timeout,appsec
```

`<BOUNCER_KEY>` should have been created and retrieved before this test by running `ddev create-bouncer`.
Expand All @@ -143,7 +149,7 @@ If you need to test with a TLS authentication, you should launch:

```bash
ddev exec BOUNCER_TLS_PATH=/var/www/html/cfssl BOUNCER_KEY=<BOUNCER_KEY> AGENT_TLS_PATH=/var/www/html/cfssl
APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit ./my-code/lapi-client/tests/Integration --testdox --exclude-group timeout
APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testsuite Integration-Watcher,Integration-Bouncer --testdox --exclude-group timeout
```

#### Coding standards
Expand Down
2 changes: 2 additions & 0 deletions src/Bouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*
* @psalm-api
*
* @psalm-import-type TMetric from \CrowdSec\LapiClient\Metrics
* @psalm-import-type TOS from \CrowdSec\LapiClient\Metrics
* @psalm-import-type TMeta from \CrowdSec\LapiClient\Metrics
Expand Down
1 change: 1 addition & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Configuration extends AbstractConfiguration
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('config');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Alert extends AbstractConfiguration
'remediation',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('alert');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Alert/Decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Decision extends AbstractConfiguration
'scenario',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('decision');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Alert/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Event extends AbstractConfiguration
'timestamp',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('event');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Alert/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Meta extends AbstractConfiguration
'value',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('meta');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Alert/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Source extends AbstractConfiguration
'longitude',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('source');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Metrics extends AbstractConfiguration
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('metricsConfig');
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/Metrics/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Items extends AbstractConfiguration
* Keep only necessary configs
* Override because $configs is an array of array (metrics item) and we want to clean each item.
*/
#[\Override]
public function cleanConfigs(array $configs): array
{
$result = [];
Expand All @@ -46,6 +47,7 @@ public function cleanConfigs(array $configs): array
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('metricsItemsConfig');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Metrics/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Meta extends AbstractConfiguration
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('metricsMetaConfig');
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Watcher extends Configuration
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = parent::getConfigTreeBuilder();
Expand All @@ -88,6 +89,7 @@ public function getConfigTreeBuilder(): TreeBuilder
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
protected function validateApiKey($rootNode): void
{
$rootNode
Expand Down
2 changes: 2 additions & 0 deletions src/Payload/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function __construct(
}

/**
* @psalm-api
* @param TAlertFull $data
*/
public static function fromArray(array $data): self
Expand Down Expand Up @@ -186,6 +187,7 @@ public function toArray(): array
* @return array
*/
#[\ReturnTypeWillChange]
#[\Override]
public function jsonSerialize()
{
return $this->toArray();
Expand Down
3 changes: 3 additions & 0 deletions src/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
* If you use `auth_type = api_key` you must provide configs `machine_id` and `password`.
*
* @psalm-api
*
* @psalm-import-type TWatcherConfig from WatcherConfig
* @psalm-import-type TAlertFull from \CrowdSec\LapiClient\Payload\Alert
* @psalm-import-type TDecision from \CrowdSec\LapiClient\Payload\Alert
Expand Down Expand Up @@ -210,6 +212,7 @@ public function getAlertById(int $id): ?array
/**
* @inheritDoc
*/
#[\Override]
protected function getConfiguration(): Configuration
{
return new WatcherConfig();
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPUnitUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public static function callMethod($obj, $name, array $args)
{
$class = new \ReflectionClass($obj);
$method = $class->getMethod($name);
$method->setAccessible(true);
// setAccessible() is only needed for PHP < 8.1 and deprecated in PHP 8.5
if (PHP_VERSION_ID < 80100) {
$method->setAccessible(true);
}

return $method->invokeArgs($obj, $args);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/coding-standards/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"friendsofphp/php-cs-fixer": "^v3.8.0",
"phpstan/phpstan": "^1.8.0",
"phpmd/phpmd": "^2.12.0",
"squizlabs/php_codesniffer": "3.7.1",
"vimeo/psalm": "^4.24.0 || ^5.26",
"squizlabs/php_codesniffer": "3.7.1 || ^4.0.1",
"vimeo/psalm": "^4.24.0 || ^5.26 || ^6.13.1",
"phpunit/phpunit": "^9.3",
"phpunit/php-code-coverage": "^9.2.15",
"mikey179/vfsstream": "^1.6.11",
Expand Down
2 changes: 2 additions & 0 deletions tools/coding-standards/psalm/psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
findUnusedIssueHandlerSuppression="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down Expand Up @@ -28,6 +29,7 @@
<file name="../../../src/Payload/Alert.php"/>
</errorLevel>
</UndefinedMethod>
<UnusedMethodCall errorLevel="suppress"/>
<RiskyTruthyFalsyComparison>
<errorLevel type="suppress">
<file name="../../../src/Bouncer.php"/>
Expand Down
Loading