Skip to content

Commit

Permalink
Fix checkstyle/spotless issues
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
peternied committed Apr 17, 2024
1 parent 51e9d69 commit 7491446
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import org.opensearch.Version;
import org.opensearch.common.settings.Settings;
import org.opensearch.security.auditlog.impl.AuditCategory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.opensearch.Version;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsAction;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
Expand Down Expand Up @@ -272,10 +273,11 @@ && getThreadContext().getHeader(ConfigConstants.OPENDISTRO_SECURITY_INJECTED_ROL
private static final String USE_JDK_SERIALIZATION = "plugins.security.use_jdk_serialization";
private static final Version FIRST_CUSTOM_SERIALIZATION_SUPPORTED_OS_VERSION = Version.V_2_11_0;
private static final Version CUSTOM_SERIALIZATION_NO_LONGER_SUPPORTED_OS_VERSION = Version.V_2_14_0;

private SerializationFormat shouldUseJdkSerialization(final Connection connection) {
var version = connection.getVersion();
if (version.after(FIRST_CUSTOM_SERIALIZATION_SUPPORTED_OS_VERSION)
&& version.before(CUSTOM_SERIALIZATION_NO_LONGER_SUPPORTED_OS_VERSION)) {
&& version.before(CUSTOM_SERIALIZATION_NO_LONGER_SUPPORTED_OS_VERSION)) {
return SerializationFormat.CustomSerializer_2_11;
}
return SerializationFormat.JDK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
package org.opensearch.security.support;

import java.io.Serializable;
import java.util.HashMap;
import java.util.stream.IntStream;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.assertThat;
import static org.opensearch.security.support.Base64Helper.deserializeObject;
import static org.opensearch.security.support.Base64Helper.serializeObject;
import static org.hamcrest.Matchers.equalTo;

public class Base64HelperTest {

Expand Down Expand Up @@ -52,23 +48,4 @@ public void testEnsureJDKSerialized() {
Assert.assertEquals(jdkSerialized, Base64Helper.ensureJDKSerialized(jdkSerialized));
Assert.assertEquals(jdkSerialized, Base64Helper.ensureJDKSerialized(customSerialized));
}

@Test
public void testDifference() {
var largeObject = new HashMap<String, Object>();
var hm = new HashMap<>();
IntStream.range(0, 100).forEach(i -> {
hm.put("c" + i, "cvalue" + i);
});
IntStream.range(0, 100).forEach(i -> {
largeObject.put("a" + i, "value");
largeObject.put("a", "value" + 1);
largeObject.put("b" + i, hm);
});

String jdkSerialized = Base64Helper.serializeObject(largeObject, true);
String customSerialized = Base64Helper.serializeObject(largeObject, false);

assertThat(jdkSerialized.length(), equalTo(customSerialized.length()));
}
}

0 comments on commit 7491446

Please sign in to comment.