Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 320056b3 authored by Yan Yan's avatar Yan Yan Committed by Gerrit Code Review
Browse files

Merge "Include IkeTunnelConnectionParams in #hashCode and #equals"

parents c9885f1f 16006a61
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -352,6 +352,7 @@ public final class VcnGatewayConnectionConfig {
    public int hashCode() {
        return Objects.hash(
                mGatewayConnectionName,
                mTunnelConnectionParams,
                mExposedCapabilities,
                Arrays.hashCode(mRetryIntervalsMs),
                mMaxMtu);
@@ -365,6 +366,7 @@ public final class VcnGatewayConnectionConfig {

        final VcnGatewayConnectionConfig rhs = (VcnGatewayConnectionConfig) other;
        return mGatewayConnectionName.equals(rhs.mGatewayConnectionName)
                && mTunnelConnectionParams.equals(rhs.mTunnelConnectionParams)
                && mExposedCapabilities.equals(rhs.mExposedCapabilities)
                && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
                && mMaxMtu == rhs.mMaxMtu;
+60 −4
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@@ -70,6 +72,14 @@ public class VcnGatewayConnectionConfigTest {
    public static final String GATEWAY_CONNECTION_NAME_PREFIX = "gatewayConnectionName-";
    private static int sGatewayConnectionConfigCount = 0;

    private static VcnGatewayConnectionConfig buildTestConfig(
            String gatewayConnectionName, IkeTunnelConnectionParams tunnelConnectionParams) {
        return buildTestConfigWithExposedCaps(
                new VcnGatewayConnectionConfig.Builder(
                        gatewayConnectionName, tunnelConnectionParams),
                EXPOSED_CAPS);
    }

    // Public for use in VcnGatewayConnectionTest
    public static VcnGatewayConnectionConfig buildTestConfig() {
        return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
@@ -83,10 +93,9 @@ public class VcnGatewayConnectionConfigTest {
                TUNNEL_CONNECTION_PARAMS);
    }

    // Public for use in VcnGatewayConnectionTest
    public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
        final VcnGatewayConnectionConfig.Builder builder =
                newBuilder().setRetryIntervalsMillis(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(
            VcnGatewayConnectionConfig.Builder builder, int... exposedCaps) {
        builder.setRetryIntervalsMillis(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);

        for (int caps : exposedCaps) {
            builder.addExposedCapability(caps);
@@ -95,6 +104,11 @@ public class VcnGatewayConnectionConfigTest {
        return builder.build();
    }

    // Public for use in VcnGatewayConnectionTest
    public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
        return buildTestConfigWithExposedCaps(newBuilder(), exposedCaps);
    }

    @Test
    public void testBuilderRequiresNonNullGatewayConnectionName() {
        try {
@@ -193,4 +207,46 @@ public class VcnGatewayConnectionConfigTest {

        assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
    }

    private static IkeTunnelConnectionParams buildTunnelConnectionParams(String ikePsk) {
        final IkeSessionParams ikeParams =
                IkeSessionParamsUtilsTest.createBuilderMinimum()
                        .setAuthPsk(ikePsk.getBytes())
                        .build();
        return TunnelConnectionParamsUtilsTest.buildTestParams(ikeParams);
    }

    @Test
    public void testTunnelConnectionParamsEquals() throws Exception {
        final String connectionName = "testTunnelConnectionParamsEquals.connectionName";
        final String psk = "testTunnelConnectionParamsEquals.psk";

        final IkeTunnelConnectionParams tunnelParams = buildTunnelConnectionParams(psk);
        final VcnGatewayConnectionConfig config = buildTestConfig(connectionName, tunnelParams);

        final IkeTunnelConnectionParams anotherTunnelParams = buildTunnelConnectionParams(psk);
        final VcnGatewayConnectionConfig anotherConfig =
                buildTestConfig(connectionName, anotherTunnelParams);

        assertNotSame(tunnelParams, anotherTunnelParams);
        assertEquals(tunnelParams, anotherTunnelParams);
        assertEquals(config, anotherConfig);
    }

    @Test
    public void testTunnelConnectionParamsNotEquals() throws Exception {
        final String connectionName = "testTunnelConnectionParamsNotEquals.connectionName";

        final IkeTunnelConnectionParams tunnelParams =
                buildTunnelConnectionParams("testTunnelConnectionParamsNotEquals.pskA");
        final VcnGatewayConnectionConfig config = buildTestConfig(connectionName, tunnelParams);

        final IkeTunnelConnectionParams anotherTunnelParams =
                buildTunnelConnectionParams("testTunnelConnectionParamsNotEquals.pskB");
        final VcnGatewayConnectionConfig anotherConfig =
                buildTestConfig(connectionName, anotherTunnelParams);

        assertNotEquals(tunnelParams, anotherTunnelParams);
        assertNotEquals(config, anotherConfig);
    }
}