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 79156e9
Show file tree
Hide file tree
Showing 54 changed files with 90 additions and 613 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("", encodeBasicHeader("jacksonm", "secret")).getStatusCode());
Expand All @@ -66,7 +65,6 @@ 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);
final RestHelper rh = nonSslRestHelper();
final HttpResponse response = rh.executeGetRequest("", encodeBasicHeader("wrong", "wrong"));
Expand All @@ -85,7 +83,6 @@ 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("attr.ldap.entryDN"));
Assert.assertTrue(res.getBody().contains("attr.ldap.subschemaSubentry"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,6 @@ 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"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("", encodeBasicHeader("jacksonm", "secret")).getStatusCode());
Expand All @@ -66,7 +65,6 @@ 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);
final RestHelper rh = nonSslRestHelper();
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, rh.executeGetRequest("", encodeBasicHeader("wrong", "wrong")).getStatusCode());
Expand All @@ -84,7 +82,6 @@ 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("attr.ldap.entryDN"));
Assert.assertTrue(res.getBody().contains("attr.ldap.subschemaSubentry"));
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/org/opensearch/security/AggregationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ 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, "*erial*");
assertNotContains(res, "*mpty*");
Expand All @@ -94,7 +93,6 @@ 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, "*erial*");
assertNotContains(res, "*mpty*");
Expand All @@ -107,7 +105,6 @@ 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, "*erial*");
assertNotContains(res, "*mpty*");
Expand Down
10 changes: 0 additions & 10 deletions src/test/java/org/opensearch/security/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,12 @@ 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));
}

@Test
Expand Down Expand Up @@ -97,14 +91,12 @@ 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) {
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);
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) {
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);
}
}
4 changes: 0 additions & 4 deletions src/test/java/org/opensearch/security/HealthTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ 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*");
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, "*strict*");
assertNotContains(res, "*DOWN*");
Expand All @@ -68,13 +66,11 @@ 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*");
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, "*strict*");
assertNotContains(res, "*UP*");
Expand Down
20 changes: 0 additions & 20 deletions src/test/java/org/opensearch/security/HttpIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ public void testHTTPBasic() throws Exception {
Assert.assertFalse(res.getBody().contains("\"nodes\" : { }"));

res = rh.executePostRequest("*/_upgrade", "", encodeBasicHeader("nagilum", "nagilum"));
System.out.println(res.getBody());
System.out.println(res.getStatusReason());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());

String bulkBody =
Expand All @@ -194,7 +192,6 @@ public void testHTTPBasic() throws Exception {
"{ \"field2\" : \"value2\" }"+System.lineSeparator();

res = rh.executePostRequest("_bulk", bulkBody, encodeBasicHeader("writer", "writer"));
System.out.println(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("\"errors\":false"));
Assert.assertTrue(res.getBody().contains("\"status\":201"));
Expand Down Expand Up @@ -272,11 +269,9 @@ public void testHTTPSCompressionEnabled() throws Exception {

HttpResponse res = rh.executeGetRequest("_opendistro/_security/sslinfo", encodeBasicHeader("nagilum", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println(res);
assertContains(res, "*ssl_protocol\":\"TLSv1.2*");
res = rh.executeGetRequest("_nodes", encodeBasicHeader("nagilum", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println(res);
assertNotContains(res, "*\"compression\":\"false\"*");
assertContains(res, "*\"compression\":\"true\"*");
}
Expand All @@ -293,11 +288,9 @@ public void testHTTPSCompression() throws Exception {

HttpResponse res = rh.executeGetRequest("_opendistro/_security/sslinfo", encodeBasicHeader("nagilum", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println(res);
assertContains(res, "*ssl_protocol\":\"TLSv1.2*");
res = rh.executeGetRequest("_nodes", encodeBasicHeader("nagilum", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println(res);
assertContains(res, "*\"compression\":\"false\"*");
assertNotContains(res, "*\"compression\":\"true\"*");
}
Expand All @@ -318,12 +311,10 @@ public void testHTTPAnon() throws Exception {
Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());

resc = rh.executeGetRequest("_opendistro/_security/authinfo?pretty=true");
System.out.println(resc.getBody());
Assert.assertTrue(resc.getBody().contains("\"remote_address\" : \"")); //check pretty print
Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());

resc = rh.executeGetRequest("_opendistro/_security/authinfo", encodeBasicHeader("nagilum", "nagilum"));
System.out.println(resc.getBody());
Assert.assertTrue(resc.getBody().contains("nagilum"));
Assert.assertFalse(resc.getBody().contains("opendistro_security_anonymous"));
Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());
Expand Down Expand Up @@ -380,7 +371,6 @@ public void testHTTPClientCert() throws Exception {
Assert.assertEquals(HttpStatus.SC_CREATED, rh.executePutRequest(".opendistro_security/"+getType()+"/y", "{}").getStatusCode());
HttpResponse res;
Assert.assertEquals(HttpStatus.SC_OK, (res = rh.executeGetRequest("_opendistro/_security/authinfo")).getStatusCode());
System.out.println(res.getBody());
}

@Test
Expand Down Expand Up @@ -512,7 +502,6 @@ public void testHTTPBasic2() throws Exception {
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, rh.executePutRequest(".opendistro_security/config/0","{}",encodeBasicHeader("worf", "worf")).getStatusCode());

HttpResponse resc = rh.executeGetRequest("_cat/indices/public",encodeBasicHeader("bug108", "nagilum"));
System.out.println(resc.getBody());
//Assert.assertTrue(resc.getBody().contains("green"));
Assert.assertEquals(HttpStatus.SC_OK, resc.getStatusCode());

Expand All @@ -523,7 +512,6 @@ public void testHTTPBasic2() throws Exception {
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, rh.executeGetRequest("spock/type01/_search?pretty",encodeBasicHeader("kirk", "kirk")).getStatusCode());
Assert.assertEquals(HttpStatus.SC_OK, rh.executeGetRequest("kirk/type01/_search?pretty",encodeBasicHeader("kirk", "kirk")).getStatusCode());

System.out.println("ok");
//all


Expand All @@ -544,7 +532,6 @@ public void testBulk() throws Exception {
"{ \"field2\" : \"value2\" }"+System.lineSeparator();

HttpResponse res = rh.executePostRequest("_bulk", bulkBody, encodeBasicHeader("bulk", "nagilum"));
System.out.println(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("\"errors\":false"));
Assert.assertTrue(res.getBody().contains("\"status\":201"));
Expand All @@ -565,7 +552,6 @@ public void testBulkWithOneIndexFailure() throws Exception {
"{ \"a\" : \"b\" }"+System.lineSeparator();

HttpResponse res = rh.executePostRequest("_bulk?refresh=true", bulkBody, encodeBasicHeader("bulk_test_user", "nagilum"));
System.out.println(res.getBody());
JsonNode jsonNode = readTree(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(jsonNode.get("errors").booleanValue());
Expand Down Expand Up @@ -595,11 +581,9 @@ public void test557() throws Exception {
final RestHelper rh = nonSslRestHelper();

HttpResponse res = rh.executePostRequest("/*/_search", "{\"size\":0,\"aggs\":{\"indices\":{\"terms\":{\"field\":\"_index\",\"size\":10}}}}", encodeBasicHeader("nagilum", "nagilum"));
System.out.println(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("starfleet_academy"));
res = rh.executePostRequest("/*/_search", "{\"size\":0,\"aggs\":{\"indices\":{\"terms\":{\"field\":\"_index\",\"size\":10}}}}", encodeBasicHeader("557", "nagilum"));
System.out.println(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("starfleet_academy"));
}
Expand Down Expand Up @@ -630,13 +614,10 @@ public void testITT1635() throws Exception {

final RestHelper rh = nonSslRestHelper();

System.out.println("###1");
HttpResponse res = rh.executeGetRequest("/esb-prod-*/_search?pretty", encodeBasicHeader("itt1635", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println("###2");
res = rh.executeGetRequest("/esb-alias-*/_search?pretty", encodeBasicHeader("itt1635", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
System.out.println("###3");
res = rh.executeGetRequest("/esb-prod-all/_search?pretty", encodeBasicHeader("itt1635", "nagilum"));
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
}
Expand Down Expand Up @@ -685,7 +666,6 @@ public void testTenantInfo() throws Exception {
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, res.getStatusCode());

res = rh.executeGetRequest("_opendistro/_security/tenantinfo?pretty", encodeBasicHeader("kibanaserver", "kibanaserver"));
System.out.println(res.getBody());
Assert.assertEquals(HttpStatus.SC_OK, res.getStatusCode());
Assert.assertTrue(res.getBody().contains("\".kibana_-1139640511_admin1\" : \"admin_1\""));
Assert.assertTrue(res.getBody().contains("\".kibana_-1386441176_praxisrw\" : \"praxisrw\""));
Expand Down
Loading

0 comments on commit 79156e9

Please sign in to comment.