Merge "DO NOT MERGE - Merge Android 10 into master"
This commit is contained in:
@@ -254,6 +254,39 @@ public class MacAddressTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatches() {
|
||||
// match 4 bytes prefix
|
||||
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("aa:bb:cc:dd:00:00"),
|
||||
MacAddress.fromString("ff:ff:ff:ff:00:00")));
|
||||
|
||||
// match bytes 0,1,2 and 5
|
||||
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("aa:bb:cc:00:00:11"),
|
||||
MacAddress.fromString("ff:ff:ff:00:00:ff")));
|
||||
|
||||
// match 34 bit prefix
|
||||
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("aa:bb:cc:dd:c0:00"),
|
||||
MacAddress.fromString("ff:ff:ff:ff:c0:00")));
|
||||
|
||||
// fail to match 36 bit prefix
|
||||
assertFalse(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("aa:bb:cc:dd:40:00"),
|
||||
MacAddress.fromString("ff:ff:ff:ff:f0:00")));
|
||||
|
||||
// match all 6 bytes
|
||||
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("aa:bb:cc:dd:ee:11"),
|
||||
MacAddress.fromString("ff:ff:ff:ff:ff:ff")));
|
||||
|
||||
// match none of 6 bytes
|
||||
assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
|
||||
MacAddress.fromString("00:00:00:00:00:00"),
|
||||
MacAddress.fromString("00:00:00:00:00:00")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that link-local address generation from MAC is valid.
|
||||
*/
|
||||
|
||||
@@ -3423,7 +3423,7 @@ public class ConnectivityServiceTest {
|
||||
testFactory.setScoreFilter(40);
|
||||
|
||||
// Register the factory and expect it to receive the default request.
|
||||
testFactory.expectAddRequestsWithScores(0); // default request score is 0, not served yet
|
||||
testFactory.expectAddRequestsWithScores(0);
|
||||
testFactory.register();
|
||||
SparseArray<NetworkRequest> requests = testFactory.waitForNetworkRequests(1);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.INetd;
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.IpSecConfig;
|
||||
@@ -57,6 +58,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -118,6 +120,11 @@ public class IpSecServiceParameterizedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageManager getPackageManager() {
|
||||
return mMockPkgMgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enforceCallingOrSelfPermission(String permission, String message) {
|
||||
if (permission == android.Manifest.permission.MANAGE_IPSEC_TUNNELS) {
|
||||
@@ -128,6 +135,7 @@ public class IpSecServiceParameterizedTest {
|
||||
};
|
||||
|
||||
INetd mMockNetd;
|
||||
PackageManager mMockPkgMgr;
|
||||
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
||||
IpSecService mIpSecService;
|
||||
Network fakeNetwork = new Network(0xAB);
|
||||
@@ -152,11 +160,16 @@ public class IpSecServiceParameterizedTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mMockNetd = mock(INetd.class);
|
||||
mMockPkgMgr = mock(PackageManager.class);
|
||||
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
||||
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
|
||||
|
||||
// Injecting mock netd
|
||||
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
|
||||
|
||||
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
|
||||
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);
|
||||
|
||||
// A package granted the AppOp for MANAGE_IPSEC_TUNNELS will be MODE_ALLOWED.
|
||||
when(mMockAppOps.noteOp(anyInt(), anyInt(), eq("blessedPackage")))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
@@ -709,4 +722,18 @@ public class IpSecServiceParameterizedTest {
|
||||
} catch (SecurityException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeatureFlagVerification() throws Exception {
|
||||
when(mMockPkgMgr.hasSystemFeature(eq(PackageManager.FEATURE_IPSEC_TUNNELS)))
|
||||
.thenReturn(false);
|
||||
|
||||
try {
|
||||
String addr = Inet4Address.getLoopbackAddress().getHostAddress();
|
||||
mIpSecService.createTunnelInterface(
|
||||
addr, addr, new Network(0), new Binder(), "blessedPackage");
|
||||
fail("Expected UnsupportedOperationException for disabled feature");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user