From a12579e534c5c0f0f02b7dce9c8c7167e2329d25 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Thu, 6 Oct 2022 15:34:50 -0500 Subject: [PATCH] KAFKA-14283; Fix connector creation Auth tests not correctly testing Currently the testCreateConnectorWithoutHeaderAuthorization and testCreateConnectorWithHeaderAuthorization tests within ConnectorsResourceTest aren't actually anything. This is because in reality the requests should be forwarded to a leader and tests aren't actually testing that a leader RestClient request is made. --- .../rest/resources/ConnectorsResourceTest.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java index ba89a21c89fef..e3048684c2c04 100644 --- a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java +++ b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java @@ -334,8 +334,11 @@ public void testCreateConnectorWithHeaderAuthorization() throws Throwable { EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn("Basic YWxhZGRpbjpvcGVuc2VzYW1l").times(1); EasyMock.replay(httpHeaders); herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb)); - expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, - CONNECTOR_TASK_NAMES, ConnectorType.SOURCE))); + expectAndCallbackNotLeaderException(cb); + + EasyMock.expect(RestClient.httpRequest(EasyMock.eq(LEADER_URL + "connectors?forward=false"), + EasyMock.eq("POST"), EasyMock.eq(httpHeaders), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(WorkerConfig.class))) + .andReturn(new RestClient.HttpResponse<>(202, new HashMap<>(), null)); PowerMock.replayAll(); @@ -354,8 +357,11 @@ public void testCreateConnectorWithoutHeaderAuthorization() throws Throwable { EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn(null).times(1); EasyMock.replay(httpHeaders); herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb)); - expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, - CONNECTOR_TASK_NAMES, ConnectorType.SOURCE))); + expectAndCallbackNotLeaderException(cb); + + EasyMock.expect(RestClient.httpRequest(EasyMock.eq(LEADER_URL + "connectors?forward=false"), + EasyMock.eq("POST"), EasyMock.eq(httpHeaders), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(WorkerConfig.class))) + .andReturn(new RestClient.HttpResponse<>(202, new HashMap<>(), null)); PowerMock.replayAll();