Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up after TestAuthValidator -- fix TestClusterAccessor #2097

Merged
merged 3 commits into from May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -29,6 +29,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.helix.TestHelper;
import org.apache.helix.rest.common.HelixRestNamespace;
import org.apache.helix.rest.common.HttpConstants;
import org.apache.helix.rest.server.authValidator.AuthValidator;
Expand All @@ -44,6 +45,7 @@
import org.apache.http.impl.client.HttpClients;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import static org.mockito.ArgumentMatchers.any;
Expand All @@ -54,20 +56,27 @@ public class TestAuthValidator extends AbstractTestClass {
private String _mockBaseUri;
private CloseableHttpClient _httpClient;

private static String CLASSNAME_TEST_DEFAULT_AUTH = "testDefaultAuthValidator";
private static String CLASSNAME_TEST_CST_AUTH = "testCustomAuthValidator";

@AfterClass
public void afterClass() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for my ignorance, but shouldn't we be deleting Helix Cluster, rather than directly using zkclient to delete znodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments...I updated.

TestHelper.dropCluster(CLASSNAME_TEST_DEFAULT_AUTH, _gZkClient);
TestHelper.dropCluster(CLASSNAME_TEST_CST_AUTH, _gZkClient);
}

@Test
public void testDefaultAuthValidator() throws JsonProcessingException {
String testClusterName = "testDefaultAuthValidator";
put("clusters/" + testClusterName, null, Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
put("clusters/" + CLASSNAME_TEST_DEFAULT_AUTH, null, Entity.entity("", MediaType.APPLICATION_JSON_TYPE),
Response.Status.CREATED.getStatusCode());
String body = get("clusters/", null, Response.Status.OK.getStatusCode(), true);
JsonNode node = OBJECT_MAPPER.readTree(body);
String clustersStr = node.get(ClusterAccessor.ClusterProperties.clusters.name()).toString();
Assert.assertTrue(clustersStr.contains(testClusterName));
Assert.assertTrue(clustersStr.contains(CLASSNAME_TEST_DEFAULT_AUTH));
}

@Test(dependsOnMethods = "testDefaultAuthValidator")
public void testCustomAuthValidator() throws IOException, InterruptedException {
String testClusterName = "testCustomAuthValidator";
int newPort = getBaseUri().getPort() + 1;

// Start a second server for testing Distributed Leader Election for writes
Expand All @@ -91,9 +100,9 @@ public void testCustomAuthValidator() throws IOException, InterruptedException {
server.start();

HttpUriRequest request =
buildRequest("/clusters/" + testClusterName, HttpConstants.RestVerbs.PUT, "");
buildRequest("/clusters/" + CLASSNAME_TEST_CST_AUTH, HttpConstants.RestVerbs.PUT, "");
sendRequestAndValidate(request, Response.Status.CREATED.getStatusCode());
request = buildRequest("/clusters/" + testClusterName, HttpConstants.RestVerbs.GET, "");
request = buildRequest("/clusters/" + CLASSNAME_TEST_CST_AUTH, HttpConstants.RestVerbs.GET, "");
sendRequestAndValidate(request, Response.Status.FORBIDDEN.getStatusCode());

server.shutdown();
Expand All @@ -107,7 +116,7 @@ public void testCustomAuthValidator() throws IOException, InterruptedException {
server.start();
_httpClient = HttpClients.createDefault();

request = buildRequest("/clusters/" + testClusterName, HttpConstants.RestVerbs.GET, "");
request = buildRequest("/clusters/" + CLASSNAME_TEST_CST_AUTH, HttpConstants.RestVerbs.GET, "");
sendRequestAndValidate(request, Response.Status.OK.getStatusCode());
request = buildRequest("/clusters", HttpConstants.RestVerbs.GET, "");
sendRequestAndValidate(request, Response.Status.FORBIDDEN.getStatusCode());
Expand Down