-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: validate index size when transforming #422
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import javax.crypto.spec.GCMParameterSpec; | ||
import javax.crypto.spec.SecretKeySpec; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
@@ -55,6 +56,8 @@ | |
|
||
import io.aiven.kafka.tieredstorage.chunkmanager.cache.DiskBasedChunkCache; | ||
import io.aiven.kafka.tieredstorage.chunkmanager.cache.InMemoryChunkCache; | ||
import io.aiven.kafka.tieredstorage.manifest.SegmentEncryptionMetadataV1; | ||
import io.aiven.kafka.tieredstorage.manifest.SegmentIndexesV1Builder; | ||
import io.aiven.kafka.tieredstorage.manifest.index.ChunkIndex; | ||
import io.aiven.kafka.tieredstorage.manifest.serde.EncryptionSerdeModule; | ||
import io.aiven.kafka.tieredstorage.manifest.serde.KafkaTypeSerdeModule; | ||
|
@@ -79,6 +82,7 @@ | |
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
@@ -465,6 +469,79 @@ void testRequiresCompression(final CompressionType compressionType, final boolea | |
assertThat(requires).isEqualTo(expectedResult); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(booleans = {true, false}) | ||
void testTransformingIndexes(final boolean encryption) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say these tests should not be in this class but somewhere in |
||
final var config = new HashMap<>(Map.of( | ||
"chunk.size", "10", | ||
"storage.backend.class", "io.aiven.kafka.tieredstorage.storage.filesystem.FileSystemStorage", | ||
"storage.root", targetDir.toString(), | ||
"encryption.enabled", Boolean.toString(encryption) | ||
)); | ||
final SegmentEncryptionMetadataV1 encryptionMetadata; | ||
if (encryption) { | ||
config.put("encryption.key.pair.id", KEY_ENCRYPTION_KEY_ID); | ||
config.put("encryption.key.pairs", KEY_ENCRYPTION_KEY_ID); | ||
config.put("encryption.key.pairs." + KEY_ENCRYPTION_KEY_ID + ".public.key.file", publicKeyPem.toString()); | ||
config.put("encryption.key.pairs." + KEY_ENCRYPTION_KEY_ID + ".private.key.file", privateKeyPem.toString()); | ||
final var dataKeyAndAAD = aesEncryptionProvider.createDataKeyAndAAD(); | ||
encryptionMetadata = new SegmentEncryptionMetadataV1(dataKeyAndAAD.dataKey, dataKeyAndAAD.aad); | ||
} else { | ||
encryptionMetadata = null; | ||
} | ||
rsm.configure(config); | ||
|
||
final var segmentIndexBuilder = new SegmentIndexesV1Builder(); | ||
final var bytes = "test".getBytes(); | ||
final var is = rsm.transformIndex( | ||
IndexType.OFFSET, | ||
new ByteArrayInputStream(bytes), | ||
bytes.length, | ||
encryptionMetadata, | ||
segmentIndexBuilder | ||
); | ||
assertThat(is).isNotEmpty(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(booleans = {true, false}) | ||
void testTransformingEmptyIndexes(final boolean encryption) { | ||
final var config = new HashMap<>(Map.of( | ||
"chunk.size", "10", | ||
"storage.backend.class", "io.aiven.kafka.tieredstorage.storage.filesystem.FileSystemStorage", | ||
"storage.root", targetDir.toString(), | ||
"encryption.enabled", Boolean.toString(encryption) | ||
)); | ||
SegmentEncryptionMetadataV1 encryptionMetadata = null; | ||
if (encryption) { | ||
config.put("encryption.key.pair.id", KEY_ENCRYPTION_KEY_ID); | ||
config.put("encryption.key.pairs", KEY_ENCRYPTION_KEY_ID); | ||
config.put("encryption.key.pairs." + KEY_ENCRYPTION_KEY_ID + ".public.key.file", publicKeyPem.toString()); | ||
config.put("encryption.key.pairs." + KEY_ENCRYPTION_KEY_ID + ".private.key.file", privateKeyPem.toString()); | ||
final var dataKeyAndAAD = aesEncryptionProvider.createDataKeyAndAAD(); | ||
encryptionMetadata = new SegmentEncryptionMetadataV1(dataKeyAndAAD.dataKey, dataKeyAndAAD.aad); | ||
} | ||
rsm.configure(config); | ||
|
||
final var segmentIndexBuilder = new SegmentIndexesV1Builder(); | ||
final var is = rsm.transformIndex( | ||
IndexType.OFFSET, | ||
InputStream.nullInputStream(), | ||
0, | ||
encryptionMetadata, | ||
segmentIndexBuilder | ||
); | ||
assertThat(is).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testGetIndexSizeWithInvalidPaths() { | ||
// non existing file | ||
assertThatThrownBy(() -> RemoteStorageManager.indexSize(Path.of("non-exist"))) | ||
.hasMessage("Error while getting index path size") | ||
.isInstanceOf(RemoteStorageException.class); | ||
} | ||
|
||
@Test | ||
void testFetchingSegmentFileNonExistent() throws IOException { | ||
final var config = Map.of( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if statements based on parameterized tests arguments is no the best approach and raise a question about overall feasibility of the tests being parameterized but since we had it here earlier let's address it later altogether.