diff --git a/composer.json b/composer.json index 3490b52..f513cad 100644 --- a/composer.json +++ b/composer.json @@ -28,16 +28,16 @@ "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^3.0", - "tiny-blocks/http": "^7.1", + "tiny-blocks/http": "^7.2", "tiny-blocks/http-correlation-id": "^2.1" }, "require-dev": { - "ergebnis/composer-normalize": "^2.52", - "guzzlehttp/psr7": "^3.0", - "infection/infection": "^0.34", - "phpstan/phpstan": "^2.2", - "phpunit/phpunit": "^13.2", - "sentry/sentry": "^4.0", + "ergebnis/composer-normalize": "^2.54", + "guzzlehttp/psr7": "^3.2", + "infection/infection": "^0.35", + "phpstan/phpstan": "^2.3", + "phpunit/phpunit": "^13.4", + "sentry/sentry": "^4.34", "slevomat/coding-standard": "^8.31", "slim/slim": "^4.15", "squizlabs/php_codesniffer": "^4.0" @@ -82,7 +82,7 @@ "test-file": "@php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage --filter", "tests": [ "@php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests", - "@php ./vendor/bin/infection --threads=max --logger-html=reports/coverage/mutation-report.html --coverage=reports/coverage" + "@php ./vendor/bin/infection --threads=max --logger-html=reports/coverage/mutation-report.html" ] } } diff --git a/tests/Unit/Reporters/SentryReporterTest.php b/tests/Unit/Reporters/SentryReporterTest.php index 15e14ca..5c058b0 100644 --- a/tests/Unit/Reporters/SentryReporterTest.php +++ b/tests/Unit/Reporters/SentryReporterTest.php @@ -96,6 +96,21 @@ public function testReportWhenClientErrorThenNothingReachesSentry(): void self::assertNull($sentry->sent); } + public function testInitializedWithThenTheSdkNeverReadsTheRequestBody(): void + { + /** @Given the deployment values an application resolves from its environment */ + $dsn = 'https://examplePublicKey@o0.ingest.sentry.io/1'; + + /** @When a reporter is built from them */ + SentryReporter::initializedWith(dsn: $dsn, release: 'client-gateway@1.0.0', environment: 'development'); + + /** @Then the SDK is told never to read a body, so a password in one is never gathered */ + $options = SentrySdk::getCurrentHub()->getClient()?->getOptions(); + self::assertNotNull($options); + self::assertSame('never', $options->getMaxRequestBodySize()); + self::assertFalse($options->shouldSendDefaultPii()); + } + public function testInitializedWithWhenDsnIsEmptyThenTheSdkStaysDisabled(): void { /** @Given an environment with reporting switched off */ @@ -431,55 +446,6 @@ public function testInitializedWithThenTheCurrentHubCarriesTheDeploymentValues() self::assertSame('1', $options->getDsn()?->getProjectId()); } - public function testInitializedWithThenTheSdkNeverReadsTheRequestBody(): void - { - /** @Given the deployment values an application resolves from its environment */ - $dsn = 'https://examplePublicKey@o0.ingest.sentry.io/1'; - - /** @When a reporter is built from them */ - SentryReporter::initializedWith(dsn: $dsn, release: 'client-gateway@1.0.0', environment: 'development'); - - /** @Then the SDK is told never to read a body, so a password in one is never gathered */ - $options = SentrySdk::getCurrentHub()->getClient()?->getOptions(); - self::assertNotNull($options); - self::assertSame('never', $options->getMaxRequestBodySize()); - self::assertFalse($options->shouldSendDefaultPii()); - } - - public function testInitializedWithWhenTheSdkGathersTheRequestAndTheUserThenNeitherIsSent(): void - { - /** @Given a reporter built from the deployment values */ - SentryReporter::initializedWith( - dsn: 'https://examplePublicKey@o0.ingest.sentry.io/1', - release: 'client-gateway@1.0.0', - environment: 'development' - ); - - /** @And an event carrying what the SDK gathers on its own while a login fails */ - $user = UserDataBag::createFromUserIdentifier(id: '0199a1b2-7c3d-7e4f-8a5b-6c7d8e9f0a1b') - ->setEmail(email: 'ana@example.com'); - - $event = Event::createEvent() - ->setUser(user: $user) - ->setRequest(request: [ - 'url' => 'https://api.example.com/v1/sessions?phone=5511999999999', - 'data' => ['email' => 'ana@example.com', 'password' => 'correct horse'], - 'method' => 'POST', - 'headers' => ['Authorization' => ['Bearer token']], - 'query_string' => 'phone=5511999999999' - ]); - - /** @When the SDK runs the hook it calls before sending */ - $options = SentrySdk::getCurrentHub()->getClient()?->getOptions(); - self::assertNotNull($options); - $sent = ($options->getBeforeSendCallback())($event, null); - - /** @Then the event leaves without the request and without the user */ - self::assertNotNull($sent); - self::assertNull($sent->getUser()); - self::assertSame([], $sent->getRequest()); - } - public function testReportWhenTheConsumerReplacesTheRuleThenItsPriorityDecides(): void { /** @Given a request */ @@ -716,6 +682,40 @@ public function testReportWhenContextOverridesPriorityThenSeverityFollowsTheOver self::assertEquals(Severity::info(), $sentry->sent->getLevel()); } + public function testInitializedWithWhenTheSdkGathersTheRequestAndTheUserThenNeitherIsSent(): void + { + /** @Given a reporter built from the deployment values */ + SentryReporter::initializedWith( + dsn: 'https://examplePublicKey@o0.ingest.sentry.io/1', + release: 'client-gateway@1.0.0', + environment: 'development' + ); + + /** @And an event carrying what the SDK gathers on its own while a login fails */ + $user = UserDataBag::createFromUserIdentifier(id: '0199a1b2-7c3d-7e4f-8a5b-6c7d8e9f0a1b') + ->setEmail(email: 'ana@example.com'); + + $event = Event::createEvent() + ->setUser(user: $user) + ->setRequest(request: [ + 'url' => 'https://api.example.com/v1/sessions?phone=5511999999999', + 'data' => ['email' => 'ana@example.com', 'password' => 'correct horse'], + 'method' => 'POST', + 'headers' => ['Authorization' => ['Bearer token']], + 'query_string' => 'phone=5511999999999' + ]); + + /** @When the SDK runs the hook it calls before sending */ + $options = SentrySdk::getCurrentHub()->getClient()?->getOptions(); + self::assertNotNull($options); + $sent = ($options->getBeforeSendCallback())($event, null); + + /** @Then the event leaves without the request and without the user */ + self::assertNotNull($sent); + self::assertNull($sent->getUser()); + self::assertSame([], $sent->getRequest()); + } + public function testReportWhenBothTheRequestAndTheExceptionTagTheSameNameThenTheExceptionWins(): void { /** @Given a request */