forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Nied <[email protected]>
- Loading branch information
Showing
156 changed files
with
13,875 additions
and
7 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
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
/* | ||
* 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) {} | ||
} |
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
/* | ||
* 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.Collection; | ||
import java.util.Collections; | ||
|
||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.plugins.Plugin; | ||
|
||
public class PluginAwareNode extends Node { | ||
|
||
private final boolean clusterManagerEligible; | ||
|
||
public PluginAwareNode( | ||
boolean clusterManagerEligible, | ||
final Settings preparedSettings, | ||
final Collection<Class<? extends Plugin>> plugins | ||
) { | ||
super( | ||
InternalSettingsPreparer.prepareEnvironment(preparedSettings, Collections.emptyMap(), null, () -> System.getenv("HOSTNAME")), | ||
plugins, | ||
true | ||
); | ||
this.clusterManagerEligible = clusterManagerEligible; | ||
} | ||
|
||
public boolean isClusterManagerEligible() { | ||
return clusterManagerEligible; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/integrationTest/java/org/opensearch/security/ConfigurationFiles.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 @@ | ||
/* | ||
* 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.security; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
class ConfigurationFiles { | ||
|
||
public static void createRoleMappingFile(File destination) { | ||
String resource = "roles_mapping.yml"; | ||
copyResourceToFile(resource, destination); | ||
} | ||
|
||
public static Path createConfigurationDirectory() { | ||
try { | ||
Path tempDirectory = Files.createTempDirectory("test-security-config"); | ||
String[] configurationFiles = { | ||
"config.yml", | ||
"action_groups.yml", | ||
"config.yml", | ||
"internal_users.yml", | ||
"roles.yml", | ||
"roles_mapping.yml", | ||
"security_tenants.yml", | ||
"tenants.yml" }; | ||
for (String fileName : configurationFiles) { | ||
Path configFileDestination = tempDirectory.resolve(fileName); | ||
copyResourceToFile(fileName, configFileDestination.toFile()); | ||
} | ||
return tempDirectory.toAbsolutePath(); | ||
} catch (IOException ex) { | ||
throw new RuntimeException("Cannot create directory with security plugin configuration.", ex); | ||
} | ||
} | ||
|
||
private static void copyResourceToFile(String resource, File destination) { | ||
try (InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) { | ||
Objects.requireNonNull(input, "Cannot find source resource " + resource); | ||
try (OutputStream output = new FileOutputStream(destination)) { | ||
input.transferTo(output); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException("Cannot create file with security plugin configuration", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.