Skip to content

Commit

Permalink
Updates the tests related to yml fieldName lookup
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 12, 2023
1 parent 13e7e11 commit c7ae735
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static org.hamcrest.Matchers.is;
import static org.opensearch.security.tools.democonfig.SecuritySettingsConfigurer.REST_ENABLED_ROLES;
import static org.opensearch.security.tools.democonfig.SecuritySettingsConfigurer.SYSTEM_INDICES;
import static org.opensearch.security.tools.democonfig.SecuritySettingsConfigurer.isStringAlreadyPresentInFile;
import static org.opensearch.security.tools.democonfig.SecuritySettingsConfigurer.isStringAlreadyPresentInYMLFile;
import static org.opensearch.security.tools.democonfig.util.DemoConfigHelperUtil.createDirectory;
import static org.opensearch.security.tools.democonfig.util.DemoConfigHelperUtil.createFile;
import static org.opensearch.security.tools.democonfig.util.DemoConfigHelperUtil.deleteDirectoryRecursive;
Expand Down Expand Up @@ -74,7 +74,6 @@ public void tearDown() throws NoSuchFieldException, IllegalAccessException {
System.setOut(originalOut);
System.setIn(originalIn);
deleteDirectoryRecursive(installer.OPENSEARCH_CONF_DIR);
// installer.environment = ExecutionEnvironment.DEMO;
unsetEnv(adminPasswordKey);
Installer.resetInstance();
}
Expand Down Expand Up @@ -230,21 +229,28 @@ public void testBuildSecurityConfigMap() {
}

@Test
public void testIsStringAlreadyPresentInFile() throws IOException {
public void testIsStringAlreadyPresentInFile_isNotPresent() throws IOException {
String str1 = "network.host";
String str2 = "some.random.config";

installer.initsecurity = true;
securitySettingsConfigurer.writeSecurityConfigToOpenSearchYML();

assertThat(isStringAlreadyPresentInFile(installer.OPENSEARCH_CONF_FILE, str1), is(equalTo(false)));
assertThat(isStringAlreadyPresentInFile(installer.OPENSEARCH_CONF_FILE, str2), is(equalTo(false)));
assertThat(isStringAlreadyPresentInYMLFile(installer.OPENSEARCH_CONF_FILE, str1), is(equalTo(false)));
assertThat(isStringAlreadyPresentInYMLFile(installer.OPENSEARCH_CONF_FILE, str2), is(equalTo(false)));
}

@Test
public void testIsStringAlreadyPresentInFile_isPresent() throws IOException {
String str1 = "network.host";
String str2 = "some.random.config";

installer.initsecurity = true;
installer.cluster_mode = true;
securitySettingsConfigurer.writeSecurityConfigToOpenSearchYML();

assertThat(isStringAlreadyPresentInFile(installer.OPENSEARCH_CONF_FILE, str1), is(equalTo(true)));
assertThat(isStringAlreadyPresentInFile(installer.OPENSEARCH_CONF_FILE, str2), is(equalTo(false)));
assertThat(isStringAlreadyPresentInYMLFile(installer.OPENSEARCH_CONF_FILE, str1), is(equalTo(true)));
assertThat(isStringAlreadyPresentInYMLFile(installer.OPENSEARCH_CONF_FILE, str2), is(equalTo(false)));
}

@Test
Expand Down

0 comments on commit c7ae735

Please sign in to comment.