Use consistent naming for allocating SPI.
Throughout the IPsec code (API, system server, netd) we use "reserve" SPI and "allocate" SPI interchangeably. This renames to use "allocate" everywhere for self-consistency and consistency with the kernel (ALLOCSPI). In javadoc, I am leaving the word "reserve" in several places because it is still an accurate description of how the method behaves. Bug: 69128142 Test: TreeHugger should be enough Change-Id: I8ea603b4612303b0393beef04032671fa53d2106
This commit is contained in:
committed by
Nathan Harold
parent
49f174beba
commit
fbe3a82340
@@ -80,7 +80,7 @@ public class IpSecManagerTest {
|
|||||||
int resourceId = 1;
|
int resourceId = 1;
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
new IpSecSpiResponse(IpSecManager.Status.OK, resourceId, DROID_SPI);
|
new IpSecSpiResponse(IpSecManager.Status.OK, resourceId, DROID_SPI);
|
||||||
when(mMockIpSecService.reserveSecurityParameterIndex(
|
when(mMockIpSecService.allocateSecurityParameterIndex(
|
||||||
eq(IpSecTransform.DIRECTION_IN),
|
eq(IpSecTransform.DIRECTION_IN),
|
||||||
eq(GOOGLE_DNS_4.getHostAddress()),
|
eq(GOOGLE_DNS_4.getHostAddress()),
|
||||||
eq(DROID_SPI),
|
eq(DROID_SPI),
|
||||||
@@ -88,7 +88,7 @@ public class IpSecManagerTest {
|
|||||||
.thenReturn(spiResp);
|
.thenReturn(spiResp);
|
||||||
|
|
||||||
IpSecManager.SecurityParameterIndex droidSpi =
|
IpSecManager.SecurityParameterIndex droidSpi =
|
||||||
mIpSecManager.reserveSecurityParameterIndex(
|
mIpSecManager.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_IN, GOOGLE_DNS_4, DROID_SPI);
|
IpSecTransform.DIRECTION_IN, GOOGLE_DNS_4, DROID_SPI);
|
||||||
assertEquals(DROID_SPI, droidSpi.getSpi());
|
assertEquals(DROID_SPI, droidSpi.getSpi());
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class IpSecManagerTest {
|
|||||||
int resourceId = 1;
|
int resourceId = 1;
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
new IpSecSpiResponse(IpSecManager.Status.OK, resourceId, DROID_SPI);
|
new IpSecSpiResponse(IpSecManager.Status.OK, resourceId, DROID_SPI);
|
||||||
when(mMockIpSecService.reserveSecurityParameterIndex(
|
when(mMockIpSecService.allocateSecurityParameterIndex(
|
||||||
eq(IpSecTransform.DIRECTION_OUT),
|
eq(IpSecTransform.DIRECTION_OUT),
|
||||||
eq(GOOGLE_DNS_4.getHostAddress()),
|
eq(GOOGLE_DNS_4.getHostAddress()),
|
||||||
eq(IpSecManager.INVALID_SECURITY_PARAMETER_INDEX),
|
eq(IpSecManager.INVALID_SECURITY_PARAMETER_INDEX),
|
||||||
@@ -110,7 +110,7 @@ public class IpSecManagerTest {
|
|||||||
.thenReturn(spiResp);
|
.thenReturn(spiResp);
|
||||||
|
|
||||||
IpSecManager.SecurityParameterIndex randomSpi =
|
IpSecManager.SecurityParameterIndex randomSpi =
|
||||||
mIpSecManager.reserveSecurityParameterIndex(
|
mIpSecManager.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
||||||
|
|
||||||
assertEquals(DROID_SPI, randomSpi.getSpi());
|
assertEquals(DROID_SPI, randomSpi.getSpi());
|
||||||
@@ -127,12 +127,13 @@ public class IpSecManagerTest {
|
|||||||
public void testAllocSpiResUnavaiableExeption() throws Exception {
|
public void testAllocSpiResUnavaiableExeption() throws Exception {
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
new IpSecSpiResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE, 0, 0);
|
new IpSecSpiResponse(IpSecManager.Status.RESOURCE_UNAVAILABLE, 0, 0);
|
||||||
when(mMockIpSecService.reserveSecurityParameterIndex(
|
when(mMockIpSecService.allocateSecurityParameterIndex(
|
||||||
anyInt(), anyString(), anyInt(), anyObject()))
|
anyInt(), anyString(), anyInt(), anyObject()))
|
||||||
.thenReturn(spiResp);
|
.thenReturn(spiResp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mIpSecManager.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
mIpSecManager.allocateSecurityParameterIndex(
|
||||||
|
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
||||||
fail("ResourceUnavailableException was not thrown");
|
fail("ResourceUnavailableException was not thrown");
|
||||||
} catch (IpSecManager.ResourceUnavailableException e) {
|
} catch (IpSecManager.ResourceUnavailableException e) {
|
||||||
}
|
}
|
||||||
@@ -144,12 +145,13 @@ public class IpSecManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAllocSpiSpiUnavaiableExeption() throws Exception {
|
public void testAllocSpiSpiUnavaiableExeption() throws Exception {
|
||||||
IpSecSpiResponse spiResp = new IpSecSpiResponse(IpSecManager.Status.SPI_UNAVAILABLE, 0, 0);
|
IpSecSpiResponse spiResp = new IpSecSpiResponse(IpSecManager.Status.SPI_UNAVAILABLE, 0, 0);
|
||||||
when(mMockIpSecService.reserveSecurityParameterIndex(
|
when(mMockIpSecService.allocateSecurityParameterIndex(
|
||||||
anyInt(), anyString(), anyInt(), anyObject()))
|
anyInt(), anyString(), anyInt(), anyObject()))
|
||||||
.thenReturn(spiResp);
|
.thenReturn(spiResp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mIpSecManager.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
mIpSecManager.allocateSecurityParameterIndex(
|
||||||
|
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4);
|
||||||
fail("ResourceUnavailableException was not thrown");
|
fail("ResourceUnavailableException was not thrown");
|
||||||
} catch (IpSecManager.ResourceUnavailableException e) {
|
} catch (IpSecManager.ResourceUnavailableException e) {
|
||||||
}
|
}
|
||||||
@@ -161,7 +163,7 @@ public class IpSecManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRequestAllocInvalidSpi() throws Exception {
|
public void testRequestAllocInvalidSpi() throws Exception {
|
||||||
try {
|
try {
|
||||||
mIpSecManager.reserveSecurityParameterIndex(
|
mIpSecManager.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4, 0);
|
IpSecTransform.DIRECTION_OUT, GOOGLE_DNS_4, 0);
|
||||||
fail("Able to allocate invalid spi");
|
fail("Able to allocate invalid spi");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class IpSecServiceParameterizedTest {
|
|||||||
.thenReturn(TEST_SPI_OUT);
|
.thenReturn(TEST_SPI_OUT);
|
||||||
|
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_OUT, mRemoteAddr, TEST_SPI_OUT, new Binder());
|
IpSecTransform.DIRECTION_OUT, mRemoteAddr, TEST_SPI_OUT, new Binder());
|
||||||
assertEquals(IpSecManager.Status.OK, spiResp.status);
|
assertEquals(IpSecManager.Status.OK, spiResp.status);
|
||||||
assertEquals(TEST_SPI_OUT, spiResp.spi);
|
assertEquals(TEST_SPI_OUT, spiResp.spi);
|
||||||
@@ -142,7 +142,7 @@ public class IpSecServiceParameterizedTest {
|
|||||||
.thenReturn(TEST_SPI_OUT);
|
.thenReturn(TEST_SPI_OUT);
|
||||||
|
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_OUT, mRemoteAddr, TEST_SPI_OUT, new Binder());
|
IpSecTransform.DIRECTION_OUT, mRemoteAddr, TEST_SPI_OUT, new Binder());
|
||||||
|
|
||||||
mIpSecService.releaseSecurityParameterIndex(spiResp.resourceId);
|
mIpSecService.releaseSecurityParameterIndex(spiResp.resourceId);
|
||||||
@@ -162,7 +162,7 @@ public class IpSecServiceParameterizedTest {
|
|||||||
.thenReturn(returnSpi);
|
.thenReturn(returnSpi);
|
||||||
|
|
||||||
IpSecSpiResponse spi =
|
IpSecSpiResponse spi =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
direction,
|
direction,
|
||||||
NetworkUtils.numericToInetAddress(remoteAddress).getHostAddress(),
|
NetworkUtils.numericToInetAddress(remoteAddress).getHostAddress(),
|
||||||
IpSecManager.INVALID_SECURITY_PARAMETER_INDEX,
|
IpSecManager.INVALID_SECURITY_PARAMETER_INDEX,
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ public class IpSecServiceTest {
|
|||||||
for (String address : invalidAddresses) {
|
for (String address : invalidAddresses) {
|
||||||
try {
|
try {
|
||||||
IpSecSpiResponse spiResp =
|
IpSecSpiResponse spiResp =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
IpSecTransform.DIRECTION_OUT, address, DROID_SPI, new Binder());
|
IpSecTransform.DIRECTION_OUT, address, DROID_SPI, new Binder());
|
||||||
fail("Invalid address was passed through IpSecService validation: " + address);
|
fail("Invalid address was passed through IpSecService validation: " + address);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@@ -336,7 +336,7 @@ public class IpSecServiceTest {
|
|||||||
// Reserve spis until it fails.
|
// Reserve spis until it fails.
|
||||||
for (int i = 0; i < MAX_NUM_SPIS; i++) {
|
for (int i = 0; i < MAX_NUM_SPIS; i++) {
|
||||||
IpSecSpiResponse newSpi =
|
IpSecSpiResponse newSpi =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
0x1,
|
0x1,
|
||||||
InetAddress.getLoopbackAddress().getHostAddress(),
|
InetAddress.getLoopbackAddress().getHostAddress(),
|
||||||
DROID_SPI + i,
|
DROID_SPI + i,
|
||||||
@@ -352,7 +352,7 @@ public class IpSecServiceTest {
|
|||||||
|
|
||||||
// Try to reserve one more SPI, and should fail.
|
// Try to reserve one more SPI, and should fail.
|
||||||
IpSecSpiResponse extraSpi =
|
IpSecSpiResponse extraSpi =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
0x1,
|
0x1,
|
||||||
InetAddress.getLoopbackAddress().getHostAddress(),
|
InetAddress.getLoopbackAddress().getHostAddress(),
|
||||||
DROID_SPI + MAX_NUM_SPIS,
|
DROID_SPI + MAX_NUM_SPIS,
|
||||||
@@ -366,7 +366,7 @@ public class IpSecServiceTest {
|
|||||||
|
|
||||||
// Should successfully reserve one more spi.
|
// Should successfully reserve one more spi.
|
||||||
extraSpi =
|
extraSpi =
|
||||||
mIpSecService.reserveSecurityParameterIndex(
|
mIpSecService.allocateSecurityParameterIndex(
|
||||||
0x1,
|
0x1,
|
||||||
InetAddress.getLoopbackAddress().getHostAddress(),
|
InetAddress.getLoopbackAddress().getHostAddress(),
|
||||||
DROID_SPI + MAX_NUM_SPIS,
|
DROID_SPI + MAX_NUM_SPIS,
|
||||||
|
|||||||
Reference in New Issue
Block a user