-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sandeep Kumawat <[email protected]>
- Loading branch information
1 parent
a1b612b
commit 83035db
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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()); | ||
} | ||
|
||
} |