Skip to content

Commit

Permalink
Fix for Kafka buffer encryption with bytes serde_format by returning …
Browse files Browse the repository at this point in the history
…null for null input in EncryptionSerializer. (#3556)

Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable authored Oct 27, 2023
1 parent ca3d6ac commit cb765d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class EncryptionSerializer<T> implements Serializer<T> {

@Override
public byte[] serialize(String topic, T data) {
if(data == null)
return null;

byte[] unencryptedBytes = innerSerializer.serialize(topic, data);
try {
return cipher.doFinal(unencryptedBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.util.UUID;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -54,4 +56,12 @@ void serialize_performs_cipher_encryption_on_serialized_data() throws IllegalBlo
assertThat(createObjectUnderTest().serialize(topicName, input),
equalTo(encryptedData));
}

@Test
void serialize_returns_null_and_does_not_call_cipher_if_input_is_null() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
assertThat(createObjectUnderTest().serialize(topicName, null),
nullValue());

verifyNoInteractions(cipher);
}
}

0 comments on commit cb765d8

Please sign in to comment.