Skip to content

Commit

Permalink
Remove and refactor console statements
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Apr 2, 2024
1 parent 09032ad commit dc33dc7
Show file tree
Hide file tree
Showing 55 changed files with 579 additions and 1,108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ protected String getResourceFolder() {
public void testIntegLdapAuthenticationSSL() throws Exception {
String securityConfigAsYamlString = FileHelper.loadFile("ldap/config.yml");
securityConfigAsYamlString = securityConfigAsYamlString.replace("${ldapsPort}", String.valueOf(ldapsPort));
System.out.println(securityConfigAsYamlString);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("", encodeBasicHeader("jacksonm", "secret")).getStatusCode());
}
Expand All @@ -66,8 +65,7 @@ public void testIntegLdapAuthenticationSSL() throws Exception {
public void testIntegLdapAuthenticationSSLFail() throws Exception {
String securityConfigAsYamlString = FileHelper.loadFile("ldap/config.yml");
securityConfigAsYamlString = securityConfigAsYamlString.replace("${ldapsPort}", String.valueOf(ldapsPort));
System.out.println(securityConfigAsYamlString);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
final RestHelper rh = nonSslRestHelper();
final HttpResponse response = rh.executeGetRequest("", encodeBasicHeader("wrong", "wrong"));
Assert.assertEquals(response.getBody(), HttpStatus.SC_UNAUTHORIZED, response.getStatusCode());
Expand All @@ -85,8 +83,7 @@ public void testAttributesWithImpersonation() throws Exception {
HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res=rh.executeGetRequest("_opendistro/_security/authinfo", new BasicHeader("opendistro_security_impersonate_as", "jacksonm")
,encodeBasicHeader("spock", "spocksecret"))).getStatusCode());
System.out.println(res.getBody());
Assert.assertTrue(res.getBody().contains("ldap.dn"));
Assert.assertTrue(res.getBody().contains("ldap.dn"));
Assert.assertTrue(res.getBody().contains("attr.ldap.entryDN"));
Assert.assertTrue(res.getBody().contains("attr.ldap.subschemaSubentry"));

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/amazon/dlic/auth/ldap/LdapBackendTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,7 @@ public void testMultiCn() throws Exception {
.getBytes(StandardCharsets.UTF_8)));
Assert.assertNotNull(user);
Assert.assertEquals("cn=cabc,ou=people,o=TEST", user.getName());
System.out.println(user.getUserEntry().getAttribute("cn"));
}
}


@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ protected String getResourceFolder() {
public void testIntegLdapAuthenticationSSL() throws Exception {
String securityConfigAsYamlString = FileHelper.loadFile("ldap/config_ldap2.yml");
securityConfigAsYamlString = securityConfigAsYamlString.replace("${ldapsPort}", String.valueOf(ldapsPort));
System.out.println(securityConfigAsYamlString);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("", encodeBasicHeader("jacksonm", "secret")).getStatusCode());
}
Expand All @@ -66,8 +65,7 @@ public void testIntegLdapAuthenticationSSL() throws Exception {
public void testIntegLdapAuthenticationSSLFail() throws Exception {
String securityConfigAsYamlString = FileHelper.loadFile("ldap/config_ldap2.yml");
securityConfigAsYamlString = securityConfigAsYamlString.replace("${ldapsPort}", String.valueOf(ldapsPort));
System.out.println(securityConfigAsYamlString);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
setup(Settings.EMPTY, new DynamicSecurityConfig().setConfigAsYamlString(securityConfigAsYamlString), Settings.EMPTY);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, rh.executeGetRequest("", encodeBasicHeader("wrong", "wrong")).getStatusCode());
}
Expand All @@ -84,8 +82,7 @@ public void testAttributesWithImpersonation() throws Exception {
HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res=rh.executeGetRequest("_opendistro/_security/authinfo", new BasicHeader("opendistro_security_impersonate_as", "jacksonm")
,encodeBasicHeader("spock", "spocksecret"))).getStatusCode());
System.out.println(res.getBody());
Assert.assertTrue(res.getBody().contains("ldap.dn"));
Assert.assertTrue(res.getBody().contains("ldap.dn"));
Assert.assertTrue(res.getBody().contains("attr.ldap.entryDN"));
Assert.assertTrue(res.getBody().contains("attr.ldap.subschemaSubentry"));

Expand Down
9 changes: 3 additions & 6 deletions src/test/java/org/opensearch/security/AggregationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public void testBasicAggregations() throws Exception {

HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executePostRequest("_search?pretty", "{\"size\":0,\"aggs\":{\"indices\":{\"terms\":{\"field\":\"_index\",\"size\":40}}}}",encodeBasicHeader("nagilum", "nagilum"))).getStatusCode());
System.out.println(res.getBody());
assertNotContains(res, "*xception*");
assertNotContains(res, "*xception*");
assertNotContains(res, "*erial*");
assertNotContains(res, "*mpty*");
assertNotContains(res, "*pendistro_security*");
Expand All @@ -94,8 +93,7 @@ public void testBasicAggregations() throws Exception {
assertContains(res, "*\"failed\" : 0*");

Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executePostRequest("*/_search?pretty", "{\"size\":0,\"aggs\":{\"indices\":{\"terms\":{\"field\":\"_index\",\"size\":40}}}}",encodeBasicHeader("nagilum", "nagilum"))).getStatusCode());
System.out.println(res.getBody());
assertNotContains(res, "*xception*");
assertNotContains(res, "*xception*");
assertNotContains(res, "*erial*");
assertNotContains(res, "*mpty*");
assertNotContains(res, "*pendistro_security*");
Expand All @@ -107,8 +105,7 @@ public void testBasicAggregations() throws Exception {
assertContains(res, "*\"failed\" : 0*");

Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executePostRequest("_search?pretty", "{\"size\":0,\"aggs\":{\"indices\":{\"terms\":{\"field\":\"_index\",\"size\":40}}}}",encodeBasicHeader("worf", "worf"))).getStatusCode());
System.out.println(res.getBody());
assertNotContains(res, "*xception*");
assertNotContains(res, "*xception*");
assertNotContains(res, "*erial*");
assertNotContains(res, "*mpty*");
assertNotContains(res, "*pendistro_security*");
Expand Down
28 changes: 9 additions & 19 deletions src/test/java/org/opensearch/security/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@ public void testMigrate() throws Exception {
Tuple<SecurityDynamicConfiguration<RoleV7>, SecurityDynamicConfiguration<TenantV7>> rolesResult = Migration.migrateRoles((SecurityDynamicConfiguration<RoleV6>)load("./legacy/securityconfig_v6/roles.yml", CType.ROLES),
(SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));

System.out.println(Strings.toString(rolesResult.v2(), true, false));
System.out.println(Strings.toString(rolesResult.v1(), true, false));



SecurityDynamicConfiguration<ActionGroupsV7> actionGroupsResult = Migration.migrateActionGroups((SecurityDynamicConfiguration<ActionGroupsV6>)load("./legacy/securityconfig_v6/action_groups.yml", CType.ACTIONGROUPS));
System.out.println(Strings.toString(actionGroupsResult, true, false));
SecurityDynamicConfiguration<ConfigV7> configResult =Migration.migrateConfig((SecurityDynamicConfiguration<ConfigV6>)load("./legacy/securityconfig_v6/config.yml", CType.CONFIG));
System.out.println(Strings.toString(configResult, true, false));
SecurityDynamicConfiguration<InternalUserV7> internalUsersResult = Migration.migrateInternalUsers((SecurityDynamicConfiguration<InternalUserV6>)load("./legacy/securityconfig_v6/internal_users.yml", CType.INTERNALUSERS));
System.out.println(Strings.toString(internalUsersResult, true, false));
SecurityDynamicConfiguration<RoleMappingsV7> rolemappingsResult = Migration.migrateRoleMappings((SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));
System.out.println(Strings.toString(rolemappingsResult, true, false));
}
SecurityDynamicConfiguration<ConfigV7> configResult =Migration.migrateConfig((SecurityDynamicConfiguration<ConfigV6>)load("./legacy/securityconfig_v6/config.yml", CType.CONFIG));
SecurityDynamicConfiguration<InternalUserV7> internalUsersResult = Migration.migrateInternalUsers((SecurityDynamicConfiguration<InternalUserV6>)load("./legacy/securityconfig_v6/internal_users.yml", CType.INTERNALUSERS));
SecurityDynamicConfiguration<RoleMappingsV7> rolemappingsResult = Migration.migrateRoleMappings((SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));
}

@Test
public void testParseSg67Config() throws Exception {
Expand All @@ -97,15 +91,13 @@ public void testParseSg67Config() throws Exception {
private void check(String file, CType cType) throws Exception {
JsonNode jsonNode = YAML.readTree(FileUtils.readFileToString(new File(file), "UTF-8"));
int configVersion = 1;
System.out.println("%%%%%%%% THIS IS A LINE OF INTEREST %%%%%%%");
if(jsonNode.get("_meta") != null) {
if(jsonNode.get("_meta") != null) {
Assert.assertEquals(jsonNode.get("_meta").get("type").asText(), cType.toLCString());
configVersion = jsonNode.get("_meta").get("config_version").asInt();
}


System.out.println("%%%%%%%% THIS IS A LINE OF INTEREST: CONFIG VERSION: "+ configVersion + "%%%%%%%");


SecurityDynamicConfiguration<?> dc = load(file, cType);
Assert.assertNotNull(dc);
//Assert.assertTrue(dc.getCEntries().size() > 0);
Expand All @@ -119,12 +111,10 @@ private SecurityDynamicConfiguration<?> load(String file, CType cType) throws Ex
JsonNode jsonNode = YAML.readTree(FileUtils.readFileToString(new File(file), "UTF-8"));
int configVersion = 1;

System.out.println("%%%%%%%% THIS IS A LINE OF INTEREST LOAD: CONFIG VERSION: %%%%%%%");
if(jsonNode.get("_meta") != null) {
if(jsonNode.get("_meta") != null) {
Assert.assertEquals(jsonNode.get("_meta").get("type").asText(), cType.toLCString());
configVersion = jsonNode.get("_meta").get("config_version").asInt();
}
System.out.println("%%%%%%%% THIS IS A LINE OF INTEREST: CONFIG VERSION: "+ configVersion + "%%%%%%%");
return SecurityDynamicConfiguration.fromNode(jsonNode, cType, configVersion, 0, 0);
return SecurityDynamicConfiguration.fromNode(jsonNode, cType, configVersion, 0, 0);
}
}
12 changes: 4 additions & 8 deletions src/test/java/org/opensearch/security/HealthTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ public void testHealth() throws Exception {
RestHelper rh = nonSslRestHelper();
HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executeGetRequest("_opendistro/_security/health?pretty&mode=lenient")).getStatusCode());
System.out.println(res.getBody());
assertContains(res, "*UP*");
assertContains(res, "*UP*");
assertNotContains(res, "*DOWN*");
assertNotContains(res, "*strict*");

Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executeGetRequest("_opendistro/_security/health?pretty")).getStatusCode());
System.out.println(res.getBody());
assertContains(res, "*UP*");
assertContains(res, "*UP*");
assertContains(res, "*strict*");
assertNotContains(res, "*DOWN*");
}
Expand All @@ -68,14 +66,12 @@ public void testHealthUnitialized() throws Exception {
RestHelper rh = nonSslRestHelper();
HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executeGetRequest("_opendistro/_security/health?pretty&mode=lenient")).getStatusCode());
System.out.println(res.getBody());
assertContains(res, "*UP*");
assertContains(res, "*UP*");
assertNotContains(res, "*DOWN*");
assertNotContains(res, "*strict*");

Assert.assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, (res = rh.executeGetRequest("_opendistro/_security/health?pretty")).getStatusCode());
System.out.println(res.getBody());
assertContains(res, "*DOWN*");
assertContains(res, "*DOWN*");
assertContains(res, "*strict*");
assertNotContains(res, "*UP*");
}
Expand Down
Loading

0 comments on commit dc33dc7

Please sign in to comment.