diff --git a/CHANGELOG.md b/CHANGELOG.md index 6930800..51c7c40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ As far as possible, we try to adhere to [Symfony guidelines](https://symfony.com ### Added -- Add App Sec requests support +- Add AppSec requests support --- diff --git a/src/Client/HttpMessage/AppSecRequest.php b/src/Client/HttpMessage/AppSecRequest.php index b3f9630..c3d7497 100644 --- a/src/Client/HttpMessage/AppSecRequest.php +++ b/src/Client/HttpMessage/AppSecRequest.php @@ -4,6 +4,8 @@ namespace CrowdSec\Common\Client\HttpMessage; +use CrowdSec\Common\Constants; + /** * Request that will be sent to CrowdSec AppSec component. * @@ -24,12 +26,12 @@ class AppSecRequest extends Request * @var string[] */ protected $requiredHeaders = [ - 'X-Crowdsec-Appsec-Ip', - 'X-Crowdsec-Appsec-User-Agent', - 'X-Crowdsec-Appsec-Verb', - 'X-Crowdsec-Appsec-Uri', - 'X-Crowdsec-Appsec-Host', - 'X-Crowdsec-Appsec-Api-Key', + Constants::HEADER_APPSEC_IP, + Constants::HEADER_APPSEC_USER_AGENT, + Constants::HEADER_APPSEC_VERB, + Constants::HEADER_APPSEC_URI, + Constants::HEADER_APPSEC_HOST, + Constants::HEADER_APPSEC_API_KEY, ]; /** * @var string diff --git a/src/Client/HttpMessage/Request.php b/src/Client/HttpMessage/Request.php index e04332a..0b984bf 100644 --- a/src/Client/HttpMessage/Request.php +++ b/src/Client/HttpMessage/Request.php @@ -5,6 +5,7 @@ namespace CrowdSec\Common\Client\HttpMessage; use CrowdSec\Common\Client\ClientException; +use CrowdSec\Common\Constants; /** * Request that will be sent to CrowdSec. @@ -29,7 +30,7 @@ class Request extends AbstractMessage * @var string[] */ protected $requiredHeaders = [ - 'User-Agent', + Constants::HEADER_LAPI_USER_AGENT, ]; /** * @var string diff --git a/src/Constants.php b/src/Constants.php index 918ad4a..7cabb57 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -40,6 +40,38 @@ class Constants * @var int The CrowdSec TTL for decisions (in seconds) */ public const DURATION = 86400; + /** + * @var string The AppSec API key header name + */ + public const HEADER_APPSEC_API_KEY = 'X-Crowdsec-Appsec-Api-Key'; + /** + * @var string The AppSec host header name + */ + public const HEADER_APPSEC_HOST = 'X-Crowdsec-Appsec-Host'; + /** + * @var string The AppSec IP header name + */ + public const HEADER_APPSEC_IP = 'X-Crowdsec-Appsec-Ip'; + /** + * @var string The AppSec URI header name + */ + public const HEADER_APPSEC_URI = 'X-Crowdsec-Appsec-Uri'; + /** + * @var string The AppSec User-Agent header name + */ + public const HEADER_APPSEC_USER_AGENT = 'X-Crowdsec-Appsec-User-Agent'; + /** + * @var string The AppSec verb header name + */ + public const HEADER_APPSEC_VERB = 'X-Crowdsec-Appsec-Verb'; + /** + * @var string The LAPI API key header name + */ + public const HEADER_LAPI_API_KEY = 'X-Api-Key'; + /** + * @var string The LAPI User-Agent header name + */ + public const HEADER_LAPI_USER_AGENT = 'User-Agent'; /** * @var string The ISO8601 date regex */ diff --git a/tests/MockedData.php b/tests/MockedData.php index a768368..016eeab 100644 --- a/tests/MockedData.php +++ b/tests/MockedData.php @@ -35,6 +35,6 @@ class MockedData EOT; public const APPSEC_ALLOWED = <<assertEquals( Constants::APPSEC_URL . '/', $appSecUrl, - 'App Sec Url should be ok' + 'AppSec Url should be ok' ); // formatResponseBody $jsonBody = json_encode(['message' => 'ok']);