use of com.amazonaws.services.secretsmanager.model.DescribeSecretResult in project fernet-java8 by l0s.
the class SimpleFernetKeyRotatorTest method verifyHandleRequestTestsValidKey.
@Test
public final void verifyHandleRequestTestsValidKey() throws IOException {
// given
final Context context = mock(Context.class);
final String clientRequestToken = "clientRequestToken";
final String secretId = "secretId";
final DescribeSecretResult secretDescription = new DescribeSecretResult();
secretDescription.setRotationEnabled(true);
secretDescription.addVersionIdsToStagesEntry(clientRequestToken, singletonList("AWSPENDING"));
given(secretsManager.describeSecret(secretId)).willReturn(secretDescription);
final Key key = Key.generateKey(random);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32)) {
key.writeTo(outputStream);
given(secretsManager.getSecretVersion(secretId, clientRequestToken)).willReturn(ByteBuffer.wrap(outputStream.toByteArray()));
}
final RotationRequest testRequest = new RotationRequest();
testRequest.setClientRequestToken(clientRequestToken);
testRequest.setSecretId(secretId);
testRequest.setStep(Step.TEST_SECRET);
final byte[] testRequestBytes = mapper.writeValueAsBytes(testRequest);
try (InputStream input = new ByteArrayInputStream(testRequestBytes)) {
try (OutputStream output = new ByteArrayOutputStream()) {
// when
rotator.handleRequest(input, output, context);
// then (nothing)
}
}
}
use of com.amazonaws.services.secretsmanager.model.DescribeSecretResult in project fernet-java8 by l0s.
the class SimpleFernetKeyRotatorTest method verifyHandleRequestTestsInsufficientBytes.
@Test
public final void verifyHandleRequestTestsInsufficientBytes() throws IOException {
// given
final Context context = mock(Context.class);
final String clientRequestToken = "clientRequestToken";
final String secretId = "secretId";
final DescribeSecretResult secretDescription = new DescribeSecretResult();
secretDescription.setRotationEnabled(true);
secretDescription.addVersionIdsToStagesEntry(clientRequestToken, singletonList("AWSPENDING"));
given(secretsManager.describeSecret(secretId)).willReturn(secretDescription);
given(secretsManager.getSecretVersion(secretId, clientRequestToken)).willReturn(ByteBuffer.allocateDirect(31));
final RotationRequest testRequest = new RotationRequest();
testRequest.setClientRequestToken(clientRequestToken);
testRequest.setSecretId(secretId);
testRequest.setStep(Step.TEST_SECRET);
final byte[] testRequestBytes = mapper.writeValueAsBytes(testRequest);
try (InputStream input = new ByteArrayInputStream(testRequestBytes)) {
try (OutputStream output = new ByteArrayOutputStream()) {
// when / then (exception thrown)
assertThrows(RuntimeException.class, () -> rotator.handleRequest(input, output, context));
}
}
}
Aggregations