Skip to content

Commit

Permalink
Moved tests into integration tests
Browse files Browse the repository at this point in the history
Added test:
 - DefaultApiAvailabilityIntegrationTest
Moved tests:
 - FlushCacheApiTest part of DefaultApiAvailabilityIntegrationTest
 - AccountApiTest as AccountRestApiIntegrationTest

Tests with the Legacy prefix removed since new tests use randomization for paths

Signed-off-by: Andrey Pleskach <[email protected]>
  • Loading branch information
willyborankin committed Apr 7, 2024
1 parent 4e8297a commit 2fdaf28
Show file tree
Hide file tree
Showing 14 changed files with 797 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;

class ConfigurationFiles {
import org.opensearch.core.common.Strings;
import org.opensearch.security.securityconf.impl.CType;

public static void createRoleMappingFile(File destination) {
String resource = "roles_mapping.yml";
copyResourceToFile(resource, destination);
}
public class ConfigurationFiles {

public static Path createConfigurationDirectory() {
try {
Path tempDirectory = Files.createTempDirectory("test-security-config");
Path tempDirectory = Files.createTempDirectory("test-security-config-");
String[] configurationFiles = {
"config.yml",
"action_groups.yml",
Expand All @@ -48,6 +48,35 @@ public static Path createConfigurationDirectory() {
}
}

public static void writeToConfig(final CType cType, final Path configFolder, final String content) throws IOException {
if (Strings.isNullOrEmpty(content)) return;
final Path configFile = resolveFileFor(cType, configFolder);
try (final var out = Files.newOutputStream(configFile, StandardOpenOption.APPEND)) {
out.write(content.getBytes(StandardCharsets.UTF_8));
out.flush();
}
}

private static Path resolveFileFor(final CType cType, final Path configFolder) {
switch (cType) {
case ACTIONGROUPS:
return configFolder.resolve("action_groups.yml");
case INTERNALUSERS:
return configFolder.resolve("internal_users.yml");
case ROLES:
return configFolder.resolve("roles.yml");
case ROLESMAPPING:
return configFolder.resolve("roles_mapping.yml");
default:
throw new IllegalArgumentException("Unsupported configuration type: " + cType);
}
}

public static void createRoleMappingFile(File destination) {
String resource = "roles_mapping.yml";
copyResourceToFile(resource, destination);
}

private static void copyResourceToFile(String resource, File destination) {
try (InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) {
Objects.requireNonNull(input, "Cannot find source resource " + resource);
Expand Down
Loading

0 comments on commit 2fdaf28

Please sign in to comment.