Skip to content

Commit

Permalink
Format all *.java files tests under test/security (opensearch-project…
Browse files Browse the repository at this point in the history
…#2837)

* Update test/security/s* java files

Signed-off-by: Stephen Crawford <steecraw@amazon.com>

* Update test/security/s* java files

Signed-off-by: Stephen Crawford <steecraw@amazon.com>

* Update all tests under security

Signed-off-by: Stephen Crawford <steecraw@amazon.com>

---------

Signed-off-by: Stephen Crawford <steecraw@amazon.com>
  • Loading branch information
stephen-crawford authored Jun 5, 2023
1 parent bfc8a6b commit ceb5ad2
Show file tree
Hide file tree
Showing 167 changed files with 14,803 additions and 9,161 deletions.
18 changes: 2 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,7 @@ spotless {
// non-standard places
target '**/com/amazon/dlic/**/*.java'
target '**/com/amazon/security/**/*.java'
target '**/test/java/org/opensearch/security/a*/**/*.java'
target '**/test/java/org/opensearch/security/b*/**/*.java'
target '**/test/java/org/opensearch/security/c*/**/*.java'
target '**/test/java/org/opensearch/security/d*/**/*.java'
target '**/test/java/org/opensearch/security/f*/**/*.java'
target '**/test/java/org/opensearch/security/h*/**/*.java'
target '**/test/java/org/opensearch/security/m*/**/*.java'
target '**/test/java/org/opensearch/security/s*/**/*.java'
target '**/test/java/org/opensearch/security/**/*.java'

removeUnusedImports()
eclipse().configFile rootProject.file('formatter/formatterConfig.xml')
Expand Down Expand Up @@ -119,14 +112,7 @@ spotless {
target '**/*.java'
targetExclude '**/com/amazon/dlic/**/*.java'
targetExclude '**/com/amazon/security/**/*.java'
targetExclude '**/test/java/org/opensearch/security/a*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/b*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/c*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/d*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/f*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/h*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/m*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/s*/**/*.java'
targetExclude '**/test/java/org/opensearch/security/**/*.java'
targetExclude 'src/integrationTest/**'

trimTrailingWhitespace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public void testPluginEnabledDataNodeWithSSlOnlyClusterManagerNode_ReqOnSSLNode(
final Settings advSecSettings = getAdvSecSettings().build();
final Settings sslOnlySettings = getSSLOnlyModeSettings().build();

setupGenericNodes(Arrays.asList(sslOnlySettings, advSecSettings, advSecSettings, sslOnlySettings),
Arrays.asList(true, false, false, true), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(sslOnlySettings, advSecSettings, advSecSettings, sslOnlySettings),
Arrays.asList(true, false, false, true),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), null);
Expand All @@ -67,8 +70,11 @@ public void testPluginEnabledDataNodeWithSSlOnlyClusterManagerNode_ReqOnAdvSecNo
final Settings advSecSettings = getAdvSecSettings().build();
final Settings sslOnlySettings = getSSLOnlyModeSettings().build();

setupGenericNodes(Arrays.asList(advSecSettings, sslOnlySettings, advSecSettings, sslOnlySettings),
Arrays.asList(false, true, false, true), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(advSecSettings, sslOnlySettings, advSecSettings, sslOnlySettings),
Arrays.asList(false, true, false, true),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), encodeBasicHeader("admin", "admin"));
Expand All @@ -84,11 +90,14 @@ public void testPluginEnabledClusterManagerNodeWithSSlOnlyDataNode_ReqOnSSLNode(
final Settings advSecSettings = getAdvSecSettings().build();
final Settings sslOnlySettings = getSSLOnlyModeSettings().build();

setupGenericNodes(Arrays.asList(sslOnlySettings, sslOnlySettings, advSecSettings, advSecSettings),
Arrays.asList(true, true, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(sslOnlySettings, sslOnlySettings, advSecSettings, advSecSettings),
Arrays.asList(true, true, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(),null);
commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), null);
}

/**
Expand All @@ -101,8 +110,11 @@ public void testPluginEnabledClusterManagerNodeWithSSlOnlyDataNode_ReqOnAdvSecNo
final Settings advSecSettings = getAdvSecSettings().build();
final Settings sslOnlySettings = getSSLOnlyModeSettings().build();

setupGenericNodes(Arrays.asList(advSecSettings, sslOnlySettings, sslOnlySettings, advSecSettings),
Arrays.asList(false, true, true, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(advSecSettings, sslOnlySettings, sslOnlySettings, advSecSettings),
Arrays.asList(false, true, true, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), encodeBasicHeader("admin", "admin"));
Expand All @@ -118,11 +130,14 @@ public void testPluginEnabledDataNodeWithDisabledClusterManagerNode_ReqOnDisable
final Settings advSecSettings = getAdvSecSettingsDualMode().build();
final Settings disabledSettings = getDisabledSettings().build();

setupGenericNodes(Arrays.asList(disabledSettings, advSecSettings, advSecSettings, disabledSettings),
Arrays.asList(false, false, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(disabledSettings, advSecSettings, advSecSettings, disabledSettings),
Arrays.asList(false, false, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(),null);
commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), null);
}

/**
Expand All @@ -135,8 +150,11 @@ public void testPluginEnabledDataNodeWithDisabledClusterManagerNode_ReqOnAdvSecN
final Settings advSecSettings = getAdvSecSettingsDualMode().build();
final Settings disabledSettings = getDisabledSettings().build();

setupGenericNodes(Arrays.asList(advSecSettings, disabledSettings, advSecSettings, disabledSettings),
Arrays.asList(false, false, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(advSecSettings, disabledSettings, advSecSettings, disabledSettings),
Arrays.asList(false, false, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), encodeBasicHeader("admin", "admin"));
Expand All @@ -152,8 +170,11 @@ public void testPluginEnabledClusterManagerNodeWithDisabledDataNode_ReqOnDisable
final Settings advSecSettings = getAdvSecSettingsDualMode().build();
final Settings disabledSettings = getDisabledSettings().build();

setupGenericNodes(Arrays.asList(disabledSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(disabledSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), null);
Expand All @@ -169,22 +190,29 @@ public void testPluginEnabledClusterManagerNodeWithDisabledDataNode_ReqOnAdvSecN
final Settings advSecSettings = getAdvSecSettingsDualMode().build();
final Settings disabledSettings = getDisabledSettings().build();

setupGenericNodes(Arrays.asList(advSecSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(advSecSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

commonTestsForAdvancedSecurityMigration(nonSslRestHelper(), encodeBasicHeader("admin", "admin"));
}

@Test
public void testWithPassiveAuthDisabled() throws Exception {
final Settings advSecSettings = getAdvSecSettings()
.put(ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY, false)
.build();
final Settings advSecSettings = getAdvSecSettings().put(
ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY,
false
).build();
final Settings sslOnlySettings = getSSLOnlyModeSettings().build();

setupGenericNodes(Arrays.asList(sslOnlySettings, sslOnlySettings, advSecSettings, advSecSettings),
Arrays.asList(true, true, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(sslOnlySettings, sslOnlySettings, advSecSettings, advSecSettings),
Arrays.asList(true, true, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);
Thread.sleep(10000);

RestHelper.HttpResponse res;
Expand All @@ -196,15 +224,19 @@ public void testWithPassiveAuthDisabled() throws Exception {
@Test
public void testWithPassiveAuthDisabledDynamic() throws Exception {

final Settings advSecSettings = getAdvSecSettingsDualMode()
.put(ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY, false)
.build();
final Settings advSecSettings = getAdvSecSettingsDualMode().put(
ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY,
false
).build();
final Settings disabledSettings = getDisabledSettings().build();

setupGenericNodes(Arrays.asList(disabledSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false), ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA);
setupGenericNodes(
Arrays.asList(disabledSettings, disabledSettings, advSecSettings, advSecSettings),
Arrays.asList(false, false, false, false),
ClusterConfiguration.ONE_CLUSTER_MANAGER_THREE_DATA
);

Thread.sleep(5*1000);
Thread.sleep(5 * 1000);

RestHelper.HttpResponse res;
RestHelper rh = nonSslRestHelper();
Expand All @@ -214,7 +246,7 @@ public void testWithPassiveAuthDisabledDynamic() throws Exception {
}

private void commonTestsForAdvancedSecurityMigration(final RestHelper rh, final Header basicHeaders) throws Exception {
Thread.sleep(5*1000);
Thread.sleep(5 * 1000);

RestHelper.HttpResponse res;
res = rh.executePutRequest("testindex", getIndexSettingsForAdvSec(), basicHeaders);
Expand Down Expand Up @@ -250,50 +282,47 @@ private void commonTestsForAnIndex(final RestHelper rh, final String index, fina

private Settings.Builder getAdvSecSettings() {
return Settings.builder()
.put(ConfigConstants.SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX, true)
.put(ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY, true)
.put(ConfigConstants.SECURITY_UNSUPPORTED_RESTAPI_ALLOW_SECURITYCONFIG_MODIFICATION, true)
.put("node.attr.custom_node", true);
.put(ConfigConstants.SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX, true)
.put(ConfigConstants.SECURITY_UNSUPPORTED_PASSIVE_INTERTRANSPORT_AUTH_INITIALLY, true)
.put(ConfigConstants.SECURITY_UNSUPPORTED_RESTAPI_ALLOW_SECURITYCONFIG_MODIFICATION, true)
.put("node.attr.custom_node", true);
}

private Settings.Builder getAdvSecSettingsDualMode() {
return getAdvSecSettings()
.put(ConfigConstants.SECURITY_CONFIG_SSL_DUAL_MODE_ENABLED, true);
return getAdvSecSettings().put(ConfigConstants.SECURITY_CONFIG_SSL_DUAL_MODE_ENABLED, true);
}

private Settings.Builder getSSLOnlyModeSettings() {
return Settings.builder()
.put(ConfigConstants.SECURITY_SSL_ONLY, true);
return Settings.builder().put(ConfigConstants.SECURITY_SSL_ONLY, true);
}

private Settings.Builder getDisabledSettings() {
return Settings.builder()
.put(ConfigConstants.SECURITY_DISABLED, true);
return Settings.builder().put(ConfigConstants.SECURITY_DISABLED, true);
}

// Create index with shards only in adv sec nodes
private String getIndexSettingsForAdvSec() {
return "{\n" +
" \"settings\" : {\n" +
" \"index\" : {\n" +
" \"number_of_shards\" : 2, \n" +
" \"number_of_replicas\" : 1, \n" +
" \"routing.allocation.include.custom_node\" : true \n" +
" }\n" +
" }\n" +
"}";
return "{\n"
+ " \"settings\" : {\n"
+ " \"index\" : {\n"
+ " \"number_of_shards\" : 2, \n"
+ " \"number_of_replicas\" : 1, \n"
+ " \"routing.allocation.include.custom_node\" : true \n"
+ " }\n"
+ " }\n"
+ "}";
}

// Create index with shards only in non adv sec nodes
private String getIndexSettingForSSLOnlyNode() {
return "{\n" +
" \"settings\" : {\n" +
" \"index\" : {\n" +
" \"number_of_shards\" : 2, \n" +
" \"number_of_replicas\" : 1, \n" +
" \"routing.allocation.exclude.custom_node\" : true \n" +
" }\n" +
" }\n" +
"}";
return "{\n"
+ " \"settings\" : {\n"
+ " \"index\" : {\n"
+ " \"number_of_shards\" : 2, \n"
+ " \"number_of_replicas\" : 1, \n"
+ " \"routing.allocation.exclude.custom_node\" : true \n"
+ " }\n"
+ " }\n"
+ "}";
}
}
Loading

0 comments on commit ceb5ad2

Please sign in to comment.