From 5335710daf05fb5067b0e784363b651d7e166656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Zaj=C4=85c?= Date: Sat, 7 Feb 2026 21:16:49 +0100 Subject: [PATCH] data protection follow-up - remove Sensitive and WithEncryptionKey attributes from methods to force sensible API on the parameter and class level --- .../src/Attribute/Sensitive.php | 2 +- .../src/Attribute/WithEncryptionKey.php | 2 +- .../Configuration/DataProtectionModule.php | 12 +- .../CommandHandlerCalledWithRoutingKey.php | 25 -- .../CommandHandlerWithAnnotatedEndpoint.php | 29 -- ...tedEndpointWithAlreadyAnnotatedMessage.php | 4 +- ...atedEndpointWithSecondaryEncryptionKey.php | 4 +- ...ndlerWithAnnotatedMethodWithoutPayload.php | 1 - .../EventHandlerCalledWithRoutingKey.php | 25 -- .../EventHandlerWithAnnotatedEndpoint.php | 29 -- ...tedEndpointWithAlreadyAnnotatedMessage.php | 4 +- ...atedEndpointWithSecondaryEncryptionKey.php | 4 +- ...ndlerWithAnnotatedMethodWithoutPayload.php | 1 - .../Integration/ObfuscateEndpointsTest.php | 254 ------------------ 14 files changed, 10 insertions(+), 386 deletions(-) delete mode 100644 packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerCalledWithRoutingKey.php delete mode 100644 packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpoint.php delete mode 100644 packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerCalledWithRoutingKey.php delete mode 100644 packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpoint.php diff --git a/packages/DataProtection/src/Attribute/Sensitive.php b/packages/DataProtection/src/Attribute/Sensitive.php index 5c5a91682..b4dd1f2bd 100644 --- a/packages/DataProtection/src/Attribute/Sensitive.php +++ b/packages/DataProtection/src/Attribute/Sensitive.php @@ -8,7 +8,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::TARGET_PARAMETER)] +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PARAMETER)] class Sensitive { } diff --git a/packages/DataProtection/src/Attribute/WithEncryptionKey.php b/packages/DataProtection/src/Attribute/WithEncryptionKey.php index 78c57a086..55c991974 100644 --- a/packages/DataProtection/src/Attribute/WithEncryptionKey.php +++ b/packages/DataProtection/src/Attribute/WithEncryptionKey.php @@ -9,7 +9,7 @@ use Attribute; -#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::TARGET_PARAMETER)] +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PARAMETER)] class WithEncryptionKey { public function __construct(private ?string $encryptionKey = null) diff --git a/packages/DataProtection/src/Configuration/DataProtectionModule.php b/packages/DataProtection/src/Configuration/DataProtectionModule.php index 32ed18673..1dd8470eb 100644 --- a/packages/DataProtection/src/Configuration/DataProtectionModule.php +++ b/packages/DataProtection/src/Configuration/DataProtectionModule.php @@ -61,7 +61,7 @@ public function prepare(Configuration $messagingConfiguration, array $extensionO return; } - $this->verifyLicense($messagingConfiguration, $extensionObjects); + $this->verifyLicense($messagingConfiguration); Assert::isTrue(ExtensionObjectResolver::contains(JMSConverterConfiguration::class, $extensionObjects), sprintf('%s package require %s package to be enabled. Did you forget to define %s?', ModulePackageList::DATA_PROTECTION_PACKAGE, ModulePackageList::JMS_CONVERTER_PACKAGE, JMSConverterConfiguration::class)); @@ -180,30 +180,26 @@ private static function resolveObfuscatorConfigsFromAnnotatedMethods(array $anno continue; } - $isPayloadSensitive = $payload->hasAnnotation(Sensitive::class) || $methodDefinition->hasAnnotation(Sensitive::class); + $isPayloadSensitive = $payload->hasAnnotation(Sensitive::class); if (! $isPayloadSensitive) { continue; } $encryptionKey = $payload->findSingleAnnotation(Type::create(WithEncryptionKey::class))?->encryptionKey(); - if ($encryptionKey === null) { - $encryptionKey = $methodDefinition->findSingleMethodAnnotation(Type::create(WithEncryptionKey::class))?->encryptionKey(); - } $sensitiveHeaders = array_map(static fn (WithSensitiveHeader $annotation) => $annotation->header, $methodDefinition->getMethodAnnotationsOf(Type::create(WithSensitiveHeader::class)) ?? []); - foreach ($methodDefinition->getInterfaceParameters() as $parameter) { if ($parameter->hasAnnotation(Header::class) && $parameter->hasAnnotation(Sensitive::class)) { $sensitiveHeaders[] = $parameter->getName(); } } - $obfuscatorConfigs[$payload->getTypeHint()] = new ObfuscatorConfig($encryptionKey, $isPayloadSensitive, $sensitiveHeaders); + $obfuscatorConfigs[$payload->getTypeHint()] = new ObfuscatorConfig(encryptionKey: $encryptionKey, isPayloadSensitive: true, sensitiveHeaders: $sensitiveHeaders); } return $obfuscatorConfigs; } - private function verifyLicense(Configuration $messagingConfiguration, array $extensionObjects): void + private function verifyLicense(Configuration $messagingConfiguration): void { if ($messagingConfiguration->isRunningForEnterpriseLicence()) { return; diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerCalledWithRoutingKey.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerCalledWithRoutingKey.php deleted file mode 100644 index 5dbc61b3a..000000000 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerCalledWithRoutingKey.php +++ /dev/null @@ -1,25 +0,0 @@ -withReceived(null, $headers); - } -} diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpoint.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpoint.php deleted file mode 100644 index e22ad7429..000000000 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpoint.php +++ /dev/null @@ -1,29 +0,0 @@ -withReceived($message, $headers); - } -} diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php index e09c759d6..c197692ce 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php @@ -15,14 +15,12 @@ #[Asynchronous('test')] class CommandHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage { - #[Sensitive] - #[WithEncryptionKey('secondary')] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[WithSensitiveHeader('fos')] #[CommandHandler(endpointId: 'test.obfuscateAnnotatedEndpoints.commandHandler.annotatedMethod')] public function annotatedMethod( - AnnotatedMessage $message, + #[Sensitive] #[WithEncryptionKey('secondary')] AnnotatedMessage $message, #[Headers] array $headers, #[Reference] MessageReceiver $messageReceiver, ): void { diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php index f382eff34..0fdf25d39 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php @@ -15,13 +15,11 @@ #[Asynchronous('test')] class CommandHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey { - #[Sensitive] - #[WithEncryptionKey('secondary')] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[CommandHandler(endpointId: 'test.commandHandler.obfuscateAnnotatedEndpoints.annotatedMethodWithSecondaryEncryptionKey')] public function annotatedMethodWithSecondaryEncryptionKey( - SomeMessage $message, + #[Sensitive] #[WithEncryptionKey('secondary')] SomeMessage $message, #[Headers] array $headers, #[Reference] MessageReceiver $messageReceiver, ): void { diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedMethodWithoutPayload.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedMethodWithoutPayload.php index e43565a06..eb61625ec 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedMethodWithoutPayload.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/CommandHandlerWithAnnotatedMethodWithoutPayload.php @@ -13,7 +13,6 @@ #[Asynchronous('test')] class CommandHandlerWithAnnotatedMethodWithoutPayload { - #[Sensitive] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[WithSensitiveHeader('fos')] diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerCalledWithRoutingKey.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerCalledWithRoutingKey.php deleted file mode 100644 index 84291a1e3..000000000 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerCalledWithRoutingKey.php +++ /dev/null @@ -1,25 +0,0 @@ -withReceived(null, $headers); - } -} diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpoint.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpoint.php deleted file mode 100644 index a994e5df0..000000000 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpoint.php +++ /dev/null @@ -1,29 +0,0 @@ -withReceived($message, $headers); - } -} diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php index f0ef48803..c6c714ceb 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage.php @@ -15,14 +15,12 @@ #[Asynchronous('test')] class EventHandlerWithAnnotatedEndpointWithAlreadyAnnotatedMessage { - #[Sensitive] - #[WithEncryptionKey('secondary')] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[WithSensitiveHeader('fos')] #[EventHandler(endpointId: 'test.obfuscateAnnotatedEndpoints.eventHandler.annotatedMethod')] public function annotatedMethod( - AnnotatedMessage $message, + #[Sensitive] #[WithEncryptionKey('secondary')] AnnotatedMessage $message, #[Headers] array $headers, #[Reference] MessageReceiver $messageReceiver, ): void { diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php index daa20b722..d3e147682 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey.php @@ -15,13 +15,11 @@ #[Asynchronous('test')] class EventHandlerWithAnnotatedEndpointWithSecondaryEncryptionKey { - #[Sensitive] - #[WithEncryptionKey('secondary')] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[EventHandler(endpointId: 'test.obfuscateAnnotatedEndpoints.eventHandler.annotatedMethodWithSecondaryEncryptionKey')] public function annotatedMethodWithSecondaryEncryptionKey( - SomeMessage $message, + #[Sensitive] #[WithEncryptionKey('secondary')] SomeMessage $message, #[Headers] array $headers, #[Reference] MessageReceiver $messageReceiver, ): void { diff --git a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedMethodWithoutPayload.php b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedMethodWithoutPayload.php index 58a213433..573855812 100644 --- a/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedMethodWithoutPayload.php +++ b/packages/DataProtection/tests/Fixture/ObfuscateEndpoints/EventHandlerWithAnnotatedMethodWithoutPayload.php @@ -13,7 +13,6 @@ #[Asynchronous('test')] class EventHandlerWithAnnotatedMethodWithoutPayload { - #[Sensitive] #[WithSensitiveHeader('foo')] #[WithSensitiveHeader('bar')] #[WithSensitiveHeader('fos')] diff --git a/packages/DataProtection/tests/Integration/ObfuscateEndpointsTest.php b/packages/DataProtection/tests/Integration/ObfuscateEndpointsTest.php index 97c0ed4eb..4d9c3db40 100644 --- a/packages/DataProtection/tests/Integration/ObfuscateEndpointsTest.php +++ b/packages/DataProtection/tests/Integration/ObfuscateEndpointsTest.php @@ -49,51 +49,6 @@ protected function setUp(): void $this->secondaryKey = Key::createNewRandomKey(); } - public function test_command_handler_with_annotated_endpoint(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - CommandHandlerWithAnnotatedEndpoint::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new CommandHandlerWithAnnotatedEndpoint(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - ); - - $ecotone - ->sendCommand( - $messageSent = new SomeMessage( - class: new TestClass('value', TestEnum::FIRST), - enum: TestEnum::FIRST, - argument: 'value', - ), - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($messageSent, $messageReceiver->receivedMessage()); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messagePayload = Crypto::decrypt(base64_decode($channelMessage->getPayload()), $this->primaryKey); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('{"class":{"argument":"value","enum":"first"},"enum":"first","argument":"value"}', $messagePayload); - self::assertEquals($metadataSent['foo'], Crypto::decrypt(base64_decode($messageHeaders->get('foo')), $this->primaryKey)); - self::assertEquals($metadataSent['bar'], Crypto::decrypt(base64_decode($messageHeaders->get('bar')), $this->primaryKey)); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - public function test_command_handler_with_annotated_endpoint_with_already_annotated_message(): void { $ecotone = $this->bootstrapEcotone( @@ -185,88 +140,6 @@ enum: TestEnum::FIRST, self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); } - public function test_command_handler_called_with_routing_key(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - CommandHandlerCalledWithRoutingKey::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new CommandHandlerCalledWithRoutingKey(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - ); - - $ecotone - ->sendCommandWithRoutingKey( - routingKey: 'command', - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('[]', $channelMessage->getPayload()); - self::assertEquals($metadataSent['foo'], $messageHeaders->get('foo')); - self::assertEquals($metadataSent['bar'], $messageHeaders->get('bar')); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - - public function test_command_handler_called_with_routing_key_will_use_channel_obfuscator(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - CommandHandlerCalledWithRoutingKey::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new CommandHandlerCalledWithRoutingKey(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - extensionObjects: [ - ChannelProtectionConfiguration::create('test')->withSensitiveHeader('foo')->withSensitiveHeader('bar'), - ] - ); - - $ecotone - ->sendCommandWithRoutingKey( - routingKey: 'command', - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messagePayload = Crypto::decrypt(base64_decode($channelMessage->getPayload()), $this->primaryKey); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('[]', $messagePayload); - self::assertEquals($metadataSent['foo'], Crypto::decrypt(base64_decode($messageHeaders->get('foo')), $this->primaryKey)); - self::assertEquals($metadataSent['bar'], Crypto::decrypt(base64_decode($messageHeaders->get('bar')), $this->primaryKey)); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - public function test_command_handler_with_annotated_method_without_payload_will_use_channel_obfuscator(): void { $ecotone = $this->bootstrapEcotone( @@ -391,51 +264,6 @@ classesToResolve: [ self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); } - public function test_event_handler_with_annotated_endpoint(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - EventHandlerWithAnnotatedEndpoint::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new EventHandlerWithAnnotatedEndpoint(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - ); - - $ecotone - ->publishEvent( - $messageSent = new SomeMessage( - class: new TestClass('value', TestEnum::FIRST), - enum: TestEnum::FIRST, - argument: 'value', - ), - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($messageSent, $messageReceiver->receivedMessage()); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messagePayload = Crypto::decrypt(base64_decode($channelMessage->getPayload()), $this->primaryKey); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('{"class":{"argument":"value","enum":"first"},"enum":"first","argument":"value"}', $messagePayload); - self::assertEquals($metadataSent['foo'], Crypto::decrypt(base64_decode($messageHeaders->get('foo')), $this->primaryKey)); - self::assertEquals($metadataSent['bar'], Crypto::decrypt(base64_decode($messageHeaders->get('bar')), $this->primaryKey)); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - public function test_event_handler_with_annotated_endpoint_with_already_annotated_message(): void { $ecotone = $this->bootstrapEcotone( @@ -527,88 +355,6 @@ enum: TestEnum::FIRST, self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); } - public function test_event_handler_called_with_routing_key(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - EventHandlerCalledWithRoutingKey::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new EventHandlerCalledWithRoutingKey(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - ); - - $ecotone - ->publishEventWithRoutingKey( - routingKey: 'event', - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('[]', $channelMessage->getPayload()); - self::assertEquals($metadataSent['foo'], $messageHeaders->get('foo')); - self::assertEquals($metadataSent['bar'], $messageHeaders->get('bar')); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - - public function test_event_handler_called_with_routing_key_will_use_channel_obfuscator(): void - { - $ecotone = $this->bootstrapEcotone( - classesToResolve: [ - EventHandlerCalledWithRoutingKey::class, - ], - container: [ - $messageReceiver = new MessageReceiver(), - new EventHandlerCalledWithRoutingKey(), - ], - messageChannel: $channel = TestQueueChannel::create('test'), - extensionObjects: [ - ChannelProtectionConfiguration::create('test')->withSensitiveHeader('foo')->withSensitiveHeader('bar'), - ] - ); - - $ecotone - ->publishEventWithRoutingKey( - routingKey: 'event', - metadata: $metadataSent = [ - 'foo' => 'secret-value', - 'bar' => 'even-more-secret-value', - 'baz' => 'non-sensitive-value', - ] - ) - ->run('test', ExecutionPollingMetadata::createWithTestingSetup()) - ; - - $receivedHeaders = $messageReceiver->receivedHeaders(); - self::assertEquals($metadataSent['foo'], $receivedHeaders['foo']); - self::assertEquals($metadataSent['bar'], $receivedHeaders['bar']); - self::assertEquals($metadataSent['baz'], $receivedHeaders['baz']); - - $channelMessage = $channel->getLastSentMessage(); - $messagePayload = Crypto::decrypt(base64_decode($channelMessage->getPayload()), $this->primaryKey); - $messageHeaders = $channelMessage->getHeaders(); - - self::assertEquals('[]', $messagePayload); - self::assertEquals($metadataSent['foo'], Crypto::decrypt(base64_decode($messageHeaders->get('foo')), $this->primaryKey)); - self::assertEquals($metadataSent['bar'], Crypto::decrypt(base64_decode($messageHeaders->get('bar')), $this->primaryKey)); - self::assertEquals($metadataSent['baz'], $messageHeaders->get('baz')); - } - public function test_event_handler_with_annotated_method_without_payload_will_use_channel_obfuscator(): void { $ecotone = $this->bootstrapEcotone(