use of org.apache.kafka.connect.runtime.rest.InternalRequestSignature in project kafka by apache.
the class DistributedHerderTest method testPutTaskConfigsInvalidSignature.
@Test
public void testPutTaskConfigsInvalidSignature() {
Callback<Void> taskConfigCb = EasyMock.mock(Callback.class);
Capture<Throwable> errorCapture = Capture.newInstance();
taskConfigCb.onCompletion(capture(errorCapture), EasyMock.eq(null));
EasyMock.expectLastCall().once();
EasyMock.expect(member.currentProtocolVersion()).andReturn(CONNECT_PROTOCOL_V2).anyTimes();
InternalRequestSignature signature = EasyMock.mock(InternalRequestSignature.class);
EasyMock.expect(signature.keyAlgorithm()).andReturn("HmacSHA256").anyTimes();
EasyMock.expect(signature.isValid(EasyMock.anyObject())).andReturn(false).anyTimes();
PowerMock.replayAll(taskConfigCb, signature);
herder.putTaskConfigs(CONN1, TASK_CONFIGS, taskConfigCb, signature);
PowerMock.verifyAll();
assertTrue(errorCapture.getValue() instanceof ConnectRestException);
assertEquals(FORBIDDEN.getStatusCode(), ((ConnectRestException) errorCapture.getValue()).statusCode());
}
use of org.apache.kafka.connect.runtime.rest.InternalRequestSignature in project kafka by apache.
the class DistributedHerderTest method testPutTaskConfigsValidRequiredSignature.
@Test
public void testPutTaskConfigsValidRequiredSignature() {
Callback<Void> taskConfigCb = EasyMock.mock(Callback.class);
member.wakeup();
EasyMock.expectLastCall().once();
EasyMock.expect(member.currentProtocolVersion()).andReturn(CONNECT_PROTOCOL_V2).anyTimes();
InternalRequestSignature signature = EasyMock.mock(InternalRequestSignature.class);
EasyMock.expect(signature.keyAlgorithm()).andReturn("HmacSHA256").anyTimes();
EasyMock.expect(signature.isValid(EasyMock.anyObject())).andReturn(true).anyTimes();
PowerMock.replayAll(taskConfigCb, signature);
herder.putTaskConfigs(CONN1, TASK_CONFIGS, taskConfigCb, signature);
PowerMock.verifyAll();
}
use of org.apache.kafka.connect.runtime.rest.InternalRequestSignature in project kafka by apache.
the class ConnectorsResourceTest method testPutConnectorTaskConfigsWithInternalRequestSignature.
@Test
public void testPutConnectorTaskConfigsWithInternalRequestSignature() throws Throwable {
final String signatureAlgorithm = "HmacSHA256";
final String encodedSignature = "Kv1/OSsxzdVIwvZ4e30avyRIVrngDfhzVUm/kAZEKc4=";
final Capture<Callback<Void>> cb = Capture.newInstance();
final Capture<InternalRequestSignature> signatureCapture = Capture.newInstance();
herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb), EasyMock.capture(signatureCapture));
expectAndCallbackResult(cb, null);
HttpHeaders headers = EasyMock.mock(HttpHeaders.class);
EasyMock.expect(headers.getHeaderString(InternalRequestSignature.SIGNATURE_ALGORITHM_HEADER)).andReturn(signatureAlgorithm).once();
EasyMock.expect(headers.getHeaderString(InternalRequestSignature.SIGNATURE_HEADER)).andReturn(encodedSignature).once();
PowerMock.replayAll(headers);
connectorsResource.putTaskConfigs(CONNECTOR_NAME, headers, FORWARD, serializeAsBytes(TASK_CONFIGS));
PowerMock.verifyAll();
InternalRequestSignature expectedSignature = new InternalRequestSignature(serializeAsBytes(TASK_CONFIGS), Mac.getInstance(signatureAlgorithm), Base64.getDecoder().decode(encodedSignature));
assertEquals(expectedSignature, signatureCapture.getValue());
}
use of org.apache.kafka.connect.runtime.rest.InternalRequestSignature in project kafka by apache.
the class DistributedHerderTest method testPutTaskConfigsDisallowedSignatureAlgorithm.
@Test
public void testPutTaskConfigsDisallowedSignatureAlgorithm() {
Callback<Void> taskConfigCb = EasyMock.mock(Callback.class);
Capture<Throwable> errorCapture = Capture.newInstance();
taskConfigCb.onCompletion(capture(errorCapture), EasyMock.eq(null));
EasyMock.expectLastCall().once();
EasyMock.expect(member.currentProtocolVersion()).andReturn(CONNECT_PROTOCOL_V2).anyTimes();
InternalRequestSignature signature = EasyMock.mock(InternalRequestSignature.class);
EasyMock.expect(signature.keyAlgorithm()).andReturn("HmacSHA489").anyTimes();
PowerMock.replayAll(taskConfigCb, signature);
herder.putTaskConfigs(CONN1, TASK_CONFIGS, taskConfigCb, signature);
PowerMock.verifyAll();
assertTrue(errorCapture.getValue() instanceof BadRequestException);
}
Aggregations