Skip to content

Commit

Permalink
Upddates line end characters to use System.lineSeparator()
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Nov 30, 2023
1 parent 2c54f63 commit fb9768d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public void restoreStreams() {
public void testPrintScriptHeaders() {
printScriptHeaders();

String expectedOutput = "### OpenSearch Security Demo Installer\n"
+ "### ** Warning: Do not use on production or public reachable systems **\n";
String expectedOutput = "### OpenSearch Security Demo Installer" + System.lineSeparator()
+ "### ** Warning: Do not use on production or public reachable systems **" + System.lineSeparator();
assertThat(expectedOutput, equalTo(outContent.toString()));
}

Expand Down Expand Up @@ -144,13 +144,13 @@ public void testGatherUserInputs_withoutAssumeYes() {
assertThat(cluster_mode, is(false));

// set initsecurity and cluster_mode to no
readInputStream("y\nn\nn\n"); // pass all 3 inputs as y
readInputStream("y\nn\nn" + System.lineSeparator()); // pass all 3 inputs as y
gatherUserInputs();

assertThat(outContent.toString(), containsString("Install demo certificates?"));
assertThat(outContent.toString(), containsString("Initialize Security Modules?"));
assertThat(outContent.toString(), containsString("Cluster mode requires additional setup of:"));
assertThat(outContent.toString(), containsString(" - Virtual memory (vm.max_map_count)\n"));
assertThat(outContent.toString(), containsString(" - Virtual memory (vm.max_map_count)" + System.lineSeparator()));
assertThat(outContent.toString(), containsString("Enable cluster mode?"));

assertThat(initsecurity, is(false));
Expand All @@ -159,13 +159,13 @@ public void testGatherUserInputs_withoutAssumeYes() {
outContent.reset();

// set initsecurity and cluster_mode to no
readInputStream("y\ny\ny\n"); // pass all 3 inputs as y
readInputStream("y\ny\ny" + System.lineSeparator()); // pass all 3 inputs as y
gatherUserInputs();

assertThat(outContent.toString(), containsString("Install demo certificates?"));
assertThat(outContent.toString(), containsString("Initialize Security Modules?"));
assertThat(outContent.toString(), containsString("Cluster mode requires additional setup of:"));
assertThat(outContent.toString(), containsString(" - Virtual memory (vm.max_map_count)\n"));
assertThat(outContent.toString(), containsString(" - Virtual memory (vm.max_map_count)" + System.lineSeparator()));
assertThat(outContent.toString(), containsString("Enable cluster mode?"));

assertThat(initsecurity, is(true));
Expand All @@ -177,13 +177,13 @@ public void testGatherUserInputs_withoutAssumeYes() {
try {
System.setSecurityManager(new NoExitSecurityManager());

readInputStream("n\nn\nn\n");
readInputStream("n\nn\nn" + System.lineSeparator());
gatherUserInputs();

assertThat(outContent.toString(), containsString("Install demo certificates?"));
assertThat(outContent.toString(), not(containsString("Initialize Security Modules?")));
assertThat(outContent.toString(), not(containsString("Cluster mode requires additional setup of:")));
assertThat(outContent.toString(), not(containsString(" - Virtual memory (vm.max_map_count)\n")));
assertThat(outContent.toString(), not(containsString(" - Virtual memory (vm.max_map_count)" + System.lineSeparator())));
assertThat(outContent.toString(), not(containsString("Enable cluster mode?")));
} catch (SecurityException e) {
assertThat(e.getMessage(), equalTo("System.exit(0) blocked to allow print statement testing."));
Expand All @@ -200,7 +200,7 @@ public void testGatherUserInputs_withoutAssumeYes() {
assertThat(initsecurity, is(true));
assertThat(cluster_mode, is(true));

readInputStream("y\ny\ny\n"); // pass all 3 inputs as y
readInputStream("y\ny\ny" + System.lineSeparator()); // pass all 3 inputs as y
gatherUserInputs();

assertThat(outContent.toString(), containsString("Install demo certificates?"));
Expand Down Expand Up @@ -369,14 +369,14 @@ public void testPrintVariables() {

printVariables();

String expectedOutput = "OpenSearch install type: installType on OS\n"
+ "OpenSearch config dir: confDir\n"
+ "OpenSearch config file: confFile\n"
+ "OpenSearch bin dir: /bin\n"
+ "OpenSearch plugins dir: /plugins\n"
+ "OpenSearch lib dir: /lib\n"
+ "Detected OpenSearch Version: osVersion\n"
+ "Detected OpenSearch Security Version: version\n";
String expectedOutput = "OpenSearch install type: installType on OS" + System.lineSeparator()
+ "OpenSearch config dir: confDir" + System.lineSeparator()
+ "OpenSearch config file: confFile" + System.lineSeparator()
+ "OpenSearch bin dir: /bin" + System.lineSeparator()
+ "OpenSearch plugins dir: /plugins" + System.lineSeparator()
+ "OpenSearch lib dir: /lib" + System.lineSeparator()
+ "Detected OpenSearch Version: osVersion" + System.lineSeparator()
+ "Detected OpenSearch Security Version: version" + System.lineSeparator();

assertEquals(expectedOutput, outContent.toString());
}
Expand All @@ -400,19 +400,19 @@ public void testFinishScriptExecution() {

String lastLine = SecuritySettingsConfigurer.getSecurityAdminCommands(securityAdminScriptPath)[1];
// Verify the expected output
String expectedOutput = "### Success\n"
+ "### Execute this script now on all your nodes and then start all nodes\n"
+ "### After the whole cluster is up execute: \n"
String expectedOutput = "### Success" + System.lineSeparator()
+ "### Execute this script now on all your nodes and then start all nodes" + System.lineSeparator()
+ "### After the whole cluster is up execute: " + System.lineSeparator()
+ lastLine
+ "\n"
+ "" + System.lineSeparator()
+ "### or run ."
+ File.separator
+ "securityadmin_demo.sh\n"
+ "### After that you can also use the Security Plugin ConfigurationGUI\n"
+ "securityadmin_demo.sh" + System.lineSeparator()
+ "### After that you can also use the Security Plugin ConfigurationGUI" + System.lineSeparator()
+ "### To access your secured cluster open https://<hostname>:<HTTP port> and log in with admin/"
+ SecuritySettingsConfigurer.ADMIN_PASSWORD
+ ".\n"
+ "### (Ignore the SSL certificate warning because we installed self-signed demo certificates)\n";
+ "." + System.lineSeparator()
+ "### (Ignore the SSL certificate warning because we installed self-signed demo certificates)" + System.lineSeparator();

assertEquals(expectedOutput, outContent.toString());

Expand All @@ -438,10 +438,10 @@ public void testFinishScriptExecution_withInitSecurityEnabled() {
setWritePermissions(securityAdminDemoScriptPath);

String lastLine = SecuritySettingsConfigurer.getSecurityAdminCommands(securityAdminScriptPath)[1];
String expectedOutput = "### Success\n"
+ "### Execute this script now on all your nodes and then start all nodes\n"
+ "### OpenSearch Security will be automatically initialized.\n"
+ "### If you like to change the runtime configuration \n"
String expectedOutput = "### Success" + System.lineSeparator()
+ "### Execute this script now on all your nodes and then start all nodes" + System.lineSeparator()
+ "### OpenSearch Security will be automatically initialized." + System.lineSeparator()
+ "### If you like to change the runtime configuration " + System.lineSeparator()
+ "### change the files in .."
+ File.separator
+ ".."
Expand All @@ -450,17 +450,17 @@ public void testFinishScriptExecution_withInitSecurityEnabled() {
+ File.separator
+ "config"
+ File.separator
+ "opensearch-security and execute: \n"
+ "opensearch-security and execute: " + System.lineSeparator()
+ lastLine
+ "\n"
+ "" + System.lineSeparator()
+ "### or run ."
+ File.separator
+ "securityadmin_demo.sh\n"
+ "### To use the Security Plugin ConfigurationGUI\n"
+ "securityadmin_demo.sh" + System.lineSeparator()
+ "### To use the Security Plugin ConfigurationGUI" + System.lineSeparator()
+ "### To access your secured cluster open https://<hostname>:<HTTP port> and log in with admin/"
+ SecuritySettingsConfigurer.ADMIN_PASSWORD
+ ".\n"
+ "### (Ignore the SSL certificate warning because we installed self-signed demo certificates)\n";
+ "." + System.lineSeparator()
+ "### (Ignore the SSL certificate warning because we installed self-signed demo certificates)" + System.lineSeparator();

assertEquals(expectedOutput, outContent.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,40 +188,40 @@ public void testConfigFileDoesNotExist() {
public void testBuildSecurityConfigString() {
String actual = SecuritySettingsConfigurer.buildSecurityConfigString();

String expected = "\n"
+ "######## Start OpenSearch Security Demo Configuration ########\n"
+ "# WARNING: revise all the lines below before you go into production\n"
+ "plugins.security.ssl.transport.pemcert_filepath: esnode.pem\n"
+ "plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem\n"
+ "plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem\n"
+ "plugins.security.ssl.transport.enforce_hostname_verification: false\n"
+ "plugins.security.ssl.http.enabled: true\n"
+ "plugins.security.ssl.http.pemcert_filepath: esnode.pem\n"
+ "plugins.security.ssl.http.pemkey_filepath: esnode-key.pem\n"
+ "plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem\n"
+ "plugins.security.allow_unsafe_democertificates: true\n"
+ "plugins.security.authcz.admin_dn:\n"
+ " - CN=kirk,OU=client,O=client,L=test, C=de\n"
+ "\n"
+ "plugins.security.audit.type: internal_opensearch\n"
+ "plugins.security.enable_snapshot_restore_privilege: true\n"
+ "plugins.security.check_snapshot_restore_write_privileges: true\n"
+ "plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]\n"
+ "plugins.security.system_indices.enabled: true\n"
+ "plugins.security.system_indices.indices: [.plugins-ml-config, .plugins-ml-connector, .plugins-ml-model-group, .plugins-ml-model, .plugins-ml-task, .plugins-ml-conversation-meta, .plugins-ml-conversation-interactions, .opendistro-alerting-config, .opendistro-alerting-alert*, .opendistro-anomaly-results*, .opendistro-anomaly-detector*, .opendistro-anomaly-checkpoints, .opendistro-anomaly-detection-state, .opendistro-reports-*, .opensearch-notifications-*, .opensearch-notebooks, .opensearch-observability, .ql-datasources, .opendistro-asynchronous-search-response*, .replication-metadata-store, .opensearch-knn-models, .geospatial-ip2geo-data*]\n"
+ "node.max_local_storage_nodes: 3\n"
+ "######## End OpenSearch Security Demo Configuration ########\n";
String expected = "" + System.lineSeparator()
+ "######## Start OpenSearch Security Demo Configuration ########" + System.lineSeparator()
+ "# WARNING: revise all the lines below before you go into productionSystem.lineSeparator()"
+ "plugins.security.ssl.transport.pemcert_filepath: esnode.pem" + System.lineSeparator()
+ "plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem" + System.lineSeparator()
+ "plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem" + System.lineSeparator()
+ "plugins.security.ssl.transport.enforce_hostname_verification: false" + System.lineSeparator()
+ "plugins.security.ssl.http.enabled: true" + System.lineSeparator()
+ "plugins.security.ssl.http.pemcert_filepath: esnode.pem" + System.lineSeparator()
+ "plugins.security.ssl.http.pemkey_filepath: esnode-key.pem" + System.lineSeparator()
+ "plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem" + System.lineSeparator()
+ "plugins.security.allow_unsafe_democertificates: true" + System.lineSeparator()
+ "plugins.security.authcz.admin_dn:" + System.lineSeparator()
+ " - CN=kirk,OU=client,O=client,L=test, C=de" + System.lineSeparator()
+ "" + System.lineSeparator()
+ "plugins.security.audit.type: internal_opensearch" + System.lineSeparator()
+ "plugins.security.enable_snapshot_restore_privilege: true" + System.lineSeparator()
+ "plugins.security.check_snapshot_restore_write_privileges: true" + System.lineSeparator()
+ "plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]" + System.lineSeparator()
+ "plugins.security.system_indices.enabled: true" + System.lineSeparator()
+ "plugins.security.system_indices.indices: [.plugins-ml-config, .plugins-ml-connector, .plugins-ml-model-group, .plugins-ml-model, .plugins-ml-task, .plugins-ml-conversation-meta, .plugins-ml-conversation-interactions, .opendistro-alerting-config, .opendistro-alerting-alert*, .opendistro-anomaly-results*, .opendistro-anomaly-detector*, .opendistro-anomaly-checkpoints, .opendistro-anomaly-detection-state, .opendistro-reports-*, .opensearch-notifications-*, .opensearch-notebooks, .opensearch-observability, .ql-datasources, .opendistro-asynchronous-search-response*, .replication-metadata-store, .opensearch-knn-models, .geospatial-ip2geo-data*]" + System.lineSeparator()
+ "node.max_local_storage_nodes: 3" + System.lineSeparator()
+ "######## End OpenSearch Security Demo Configuration ########" + System.lineSeparator();
assertThat(actual, is(equalTo(expected)));

Installer.initsecurity = true;
actual = SecuritySettingsConfigurer.buildSecurityConfigString();
assertThat(actual, containsString("plugins.security.allow_default_init_securityindex: true\n"));
assertThat(actual, containsString("plugins.security.allow_default_init_securityindex: true" + System.lineSeparator()));

Installer.cluster_mode = true;
actual = SecuritySettingsConfigurer.buildSecurityConfigString();
assertThat(actual, containsString("network.host: 0.0.0.0\n"));
assertThat(actual, containsString("node.name: smoketestnode\n"));
assertThat(actual, containsString("cluster.initial_cluster_manager_nodes: smoketestnode\n"));
assertThat(actual, containsString("network.host: 0.0.0.0" + System.lineSeparator()));
assertThat(actual, containsString("node.name: smoketestnode" + System.lineSeparator()));
assertThat(actual, containsString("cluster.initial_cluster_manager_nodes: smoketestnode" + System.lineSeparator()));
}

@Test
Expand Down

0 comments on commit fb9768d

Please sign in to comment.