Skip to content

Commit

Permalink
Merge pull request #10 from julienloizelet/fix/no-scenarios-should-th…
Browse files Browse the repository at this point in the history
…row-exception

fix(watcher): Missing scenarios key in config should throw an exception
  • Loading branch information
julienloizelet authored Oct 28, 2022
2 parents da647ab + db69f46 commit bba8a7e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).



## [0.2.0](https://github.com/crowdsecurity/php-capi-client/releases/tag/v0.2.0) - 2022-10-28
[_Compare with previous release_](https://github.com/crowdsecurity/php-capi-client/compare/v0.1.0...v0.2.0)

### Changed
- *Breaking change*: Missing `scenarios` key in `configs` will throw an exception

---

## [0.1.0](https://github.com/crowdsecurity/php-capi-client/releases/tag/v0.1.0) - 2022-10-21
[_Compare with previous release_](https://github.com/crowdsecurity/php-capi-client/compare/v0.0.1...v0.1.0)

Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->thenInvalid('Invalid user agent suffix. Length must be <= 16. Allowed chars are A-Za-z0-9')
->end()
->end()
->arrayNode('scenarios')->cannotBeEmpty()
->arrayNode('scenarios')->isRequired()->cannotBeEmpty()
->validate()
->ifArray()
->then(function (array $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ class Constants
/**
* @var string The current version of this library
*/
public const VERSION = 'v0.1.0';
public const VERSION = 'v0.2.0';
}
2 changes: 1 addition & 1 deletion tests/Unit/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function testOptions()
$url = Constants::URL_DEV . 'watchers';
$method = 'POST';
$parameters = ['machine_id' => 'test', 'password' => 'test'];
$configs = [];
$configs = ['scenarios' => TestConstants::SCENARIOS];

$client = new Watcher($configs, new FileStorage());
$curlRequester = $client->getRequestHandler();
Expand Down
18 changes: 16 additions & 2 deletions tests/Unit/WatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ public function testConfigure()
'Scenarios should be indexed array'
);

$error = '';
try {
new Watcher([], new FileStorage());
} catch (Exception $e) {
$error = $e->getMessage();
}

PHPUnitUtil::assertRegExp(
$this,
'/The child config "scenarios" under "config" must be configured./',
$error,
'Scenarios key must be in configs'
);

$error = '';
try {
new Watcher(['scenarios' => []], new FileStorage());
Expand Down Expand Up @@ -412,7 +426,7 @@ public function testConfigure()
'machine_id_prefix should contain allowed chars'
);

$client = new Watcher(['machine_id_prefix' => ''], new FileStorage());
$client = new Watcher(['scenarios' => TestConstants::SCENARIOS, 'machine_id_prefix' => ''], new FileStorage());

$this->assertEquals(
'',
Expand Down Expand Up @@ -448,7 +462,7 @@ public function testConfigure()
'user_agent_suffix should contain allowed chars'
);

$client = new Watcher(['user_agent_suffix' => ''], new FileStorage());
$client = new Watcher(['scenarios' => TestConstants::SCENARIOS, 'user_agent_suffix' => ''], new FileStorage());

$this->assertEquals(
'',
Expand Down

0 comments on commit bba8a7e

Please sign in to comment.