-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the first iteration of a new framework for integration tests. The main focus is on conciseness and self-contained test. The framework offers: A programmatic way of defining the cluster setup A programmatic way of defining users and roles A programmatic way of defining indices A REST client with methods tailored for testing This is now all part of the test class, so you do not need to jump around in various configuration files to get an overview on the test setup. There are of course still a lot of features missing, like setting up test data. I propose to add these features in increments. Signed-off-by: Nils Bandener <[email protected]> Signed-off-by: Jochen Kressin <[email protected]> Signed-off-by: Lukasz Soszynski <[email protected]> Signed-off-by: Kacper Trochimiak <[email protected]> Signed-off-by: Nils Bandener <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Jochen Kressin <[email protected]> Co-authored-by: Lukasz Soszynski <[email protected]> Co-authored-by: Kacper Trochimiak <[email protected]> Co-authored-by: Peter Nied <[email protected]>
- Loading branch information
1 parent
7f992eb
commit f591af6
Showing
28 changed files
with
3,632 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
33 changes: 33 additions & 0 deletions
33
src/integrationTest/java/org/opensearch/common/logging/NodeAndClusterIdConverter.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,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.logging; | ||
|
||
/** | ||
* Class uses to override OpenSearch NodeAndClusterIdConverter Log4j2 plugin in order to disable plugin and limit number of | ||
* warn messages like "...ApplierService#updateTask][T#1] WARN ClusterApplierService:628 - failed to notify ClusterStateListener..." | ||
* during tests execution. | ||
* | ||
* The class is rather a temporary solution and the real one should be developed in scope of: | ||
* https://github.com/opensearch-project/OpenSearch/pull/4322 | ||
*/ | ||
import org.apache.logging.log4j.core.LogEvent; | ||
|
||
class NodeAndClusterIdConverter { | ||
|
||
|
||
public NodeAndClusterIdConverter() { | ||
} | ||
|
||
public static void setNodeIdAndClusterId(String nodeId, String clusterUUID) { | ||
} | ||
|
||
public void format(LogEvent event, StringBuilder toAppendTo) { | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/integrationTest/java/org/opensearch/node/PluginAwareNode.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,49 @@ | ||
/* | ||
* Copyright 2015-2018 _floragunn_ GmbH | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* 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. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.node; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.plugins.Plugin; | ||
|
||
public class PluginAwareNode extends Node { | ||
|
||
private final boolean clusterManagerEligible; | ||
|
||
@SafeVarargs | ||
public PluginAwareNode(boolean clusterManagerEligible, final Settings preparedSettings, final Class<? extends Plugin>... plugins) { | ||
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")), Arrays.asList(plugins), true); | ||
this.clusterManagerEligible = clusterManagerEligible; | ||
} | ||
|
||
|
||
public boolean isClusterManagerEligible() { | ||
return clusterManagerEligible; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/integrationTest/java/org/opensearch/security/SecurityRolesTests.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,60 @@ | ||
/* | ||
* 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. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
import org.apache.http.HttpStatus; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.opensearch.test.framework.TestSecurityConfig; | ||
import org.opensearch.test.framework.TestSecurityConfig.Role; | ||
import org.opensearch.test.framework.cluster.ClusterManager; | ||
import org.opensearch.test.framework.cluster.LocalCluster; | ||
import org.opensearch.test.framework.cluster.TestRestClient; | ||
import org.opensearch.test.framework.cluster.TestRestClient.HttpResponse; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
|
||
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
@ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
public class SecurityRolesTests { | ||
|
||
protected final static TestSecurityConfig.User USER_SR = new TestSecurityConfig.User("sr_user").roles( | ||
new Role("abc_ber").indexPermissions("*").on("*").clusterPermissions("*"), | ||
new Role("def_efg").indexPermissions("*").on("*").clusterPermissions("*")); | ||
|
||
@ClassRule | ||
public static LocalCluster cluster = new LocalCluster.Builder() | ||
.clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS).anonymousAuth(true) | ||
.authc(AUTHC_HTTPBASIC_INTERNAL).users(USER_SR).build(); | ||
|
||
@Test | ||
public void testSecurityRoles() throws Exception { | ||
try (TestRestClient client = cluster.getRestClient(USER_SR)) { | ||
HttpResponse response = client.getAuthInfo(); | ||
assertThat(response.getStatusCode(), equalTo(HttpStatus.SC_OK)); | ||
|
||
// Check username | ||
assertThat(response.getTextFromJsonBody("/user_name"), equalTo("sr_user")); | ||
|
||
// Check security roles | ||
assertThat(response.getTextFromJsonBody("/roles/0"), equalTo("user_sr_user__abc_ber")); | ||
assertThat(response.getTextFromJsonBody("/roles/1"), equalTo("user_sr_user__def_efg")); | ||
|
||
} | ||
} | ||
|
||
} |
Oops, something went wrong.