forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement missing methods for EncryptedBlobStore and EncryptedBlobCon…
…tainer (opensearch-project#14030) Signed-off-by: Sandeep Kumawat <[email protected]>
- Loading branch information
1 parent
b0513dd
commit 270054c
Showing
5 changed files
with
58 additions
and
3 deletions.
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
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
41 changes: 41 additions & 0 deletions
41
server/src/test/java/org/opensearch/common/blobstore/EncryptedBlobContainerTests.java
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore; | ||
|
||
import org.opensearch.common.crypto.CryptoHandler; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class EncryptedBlobContainerTests extends OpenSearchTestCase { | ||
|
||
public void testBlobContainerReadBlobWithMetadata() throws IOException { | ||
BlobContainer blobContainer = mock(BlobContainer.class); | ||
CryptoHandler cryptoHandler = mock(CryptoHandler.class); | ||
EncryptedBlobContainer encryptedBlobContainer = new EncryptedBlobContainer(blobContainer, cryptoHandler); | ||
InputStreamWithMetadata inputStreamWithMetadata = new InputStreamWithMetadata( | ||
new ByteArrayInputStream(new byte[0]), | ||
new HashMap<>() | ||
); | ||
when(blobContainer.readBlobWithMetadata("test")).thenReturn(inputStreamWithMetadata); | ||
InputStream decrypt = new ByteArrayInputStream(new byte[2]); | ||
when(cryptoHandler.createDecryptingStream(inputStreamWithMetadata.getInputStream())).thenReturn(decrypt); | ||
InputStreamWithMetadata result = encryptedBlobContainer.readBlobWithMetadata("test"); | ||
assertEquals(result.getInputStream(), decrypt); | ||
assertEquals(result.getMetadata(), inputStreamWithMetadata.getMetadata()); | ||
} | ||
|
||
} |
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
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