1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.net.ipsec.test.ike.message; 18 19 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_APPLICATION_VERSION; 20 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_ADDRESS; 21 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_DHCP; 22 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_DNS; 23 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_NETMASK; 24 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP4_SUBNET; 25 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP6_ADDRESS; 26 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP6_DNS; 27 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_INTERNAL_IP6_SUBNET; 28 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_IP4_PCSCF; 29 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_ATTR_IP6_PCSCF; 30 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_TYPE_REPLY; 31 import static com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.CONFIG_TYPE_REQUEST; 32 import static com.android.internal.net.ipsec.test.ike.message.IkePayload.PAYLOAD_TYPE_CP; 33 import static com.android.internal.net.ipsec.test.ike.message.IkePayload.PAYLOAD_TYPE_NOTIFY; 34 35 import static org.junit.Assert.assertArrayEquals; 36 import static org.junit.Assert.assertEquals; 37 import static org.junit.Assert.assertFalse; 38 import static org.junit.Assert.assertNull; 39 import static org.junit.Assert.assertTrue; 40 import static org.junit.Assert.fail; 41 import static org.mockito.Matchers.any; 42 import static org.mockito.Mockito.doAnswer; 43 import static org.mockito.Mockito.doReturn; 44 import static org.mockito.Mockito.mock; 45 46 import android.net.InetAddresses; 47 import android.net.LinkAddress; 48 import android.net.ipsec.test.ike.exceptions.InvalidSyntaxException; 49 import android.os.PersistableBundle; 50 51 import com.android.internal.net.TestUtils; 52 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttribute; 53 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeAppVersion; 54 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Address; 55 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Dhcp; 56 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Dns; 57 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Netmask; 58 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Pcscf; 59 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv4Subnet; 60 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv6Address; 61 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv6Dns; 62 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv6Pcscf; 63 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.ConfigAttributeIpv6Subnet; 64 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.IkeConfigAttrIpv4AddressBase; 65 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.IkeConfigAttrIpv6AddressBase; 66 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.TunnelModeChildConfigAttrIpv4AddressBase; 67 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.TunnelModeChildConfigAttrIpv6AddrRangeBase; 68 import com.android.internal.net.ipsec.test.ike.message.IkeConfigPayload.TunnelModeChildConfigAttrIpv6AddressBase; 69 70 import org.junit.Before; 71 import org.junit.Test; 72 73 import java.net.Inet4Address; 74 import java.net.Inet6Address; 75 import java.net.InetAddress; 76 import java.nio.ByteBuffer; 77 import java.util.ArrayList; 78 import java.util.List; 79 80 public final class IkeConfigPayloadTest { 81 private static final String CONFIG_REQ_PAYLOAD_HEX = 82 "2900003401000000000100000008000000030000000a0000" 83 + "00140004c0000201" // IPv4 P_CSCF 84 + "0015001020010db8000000000000000000000001"; // IPv6 P_CSCF 85 private static final String CONFIG_RESP_PAYLOAD_HEX = 86 "2100003C0200000000010004c000026400030004080808080003000408080404" 87 + "00140004c0000201" // IPv4 P_CSCF 88 + "0015001020010db8000000000000000000000001"; // IPv6 P_CSCF 89 private static final String CONFIG_RESP_PAYLOAD_INVALID_ONE_HEX = 90 "210000200200000000010004c000026400020004fffffffe00020004fffffffe"; 91 private static final String CONFIG_RESP_PAYLOAD_INVALID_TWO_HEX = 92 "210000100200000000020004fffffffe"; 93 94 private static final byte[] CONFIG_REQ_PAYLOAD = 95 TestUtils.hexStringToByteArray(CONFIG_REQ_PAYLOAD_HEX); 96 private static final byte[] CONFIG_RESP_PAYLOAD = 97 TestUtils.hexStringToByteArray(CONFIG_RESP_PAYLOAD_HEX); 98 99 private static final Inet4Address IPV4_ADDRESS = 100 (Inet4Address) InetAddresses.parseNumericAddress("192.0.2.100"); 101 private static final Inet4Address IPV4_NETMASK = 102 (Inet4Address) InetAddresses.parseNumericAddress("255.255.255.240"); 103 private static final int IP4_PREFIX_LEN = 28; 104 private static final LinkAddress IPV4_LINK_ADDRESS = 105 new LinkAddress(IPV4_ADDRESS, IP4_PREFIX_LEN); 106 107 private static final byte[] IPV4_ADDRESS_ATTRIBUTE_WITH_VALUE = 108 TestUtils.hexStringToByteArray("00010004c0000264"); 109 private static final byte[] IPV4_ADDRESS_ATTRIBUTE_WITHOUT_VALUE = 110 TestUtils.hexStringToByteArray("00010000"); 111 112 private static final byte[] IPV4_NETMASK_ATTRIBUTE_WITHOUT_VALUE = 113 TestUtils.hexStringToByteArray("00020000"); 114 115 private static final Inet4Address IPV4_DNS = 116 (Inet4Address) InetAddresses.parseNumericAddress("8.8.8.8"); 117 private static final byte[] IPV4_DNS_ATTRIBUTE_VALUE = 118 TestUtils.hexStringToByteArray("08080808"); 119 private static final byte[] IPV4_DNS_ATTRIBUTE_WITHOUT_VALUE = 120 TestUtils.hexStringToByteArray("00030000"); 121 122 private static final Inet4Address IPV4_DHCP = 123 (Inet4Address) InetAddresses.parseNumericAddress("192.0.2.200"); 124 private static final byte[] IPV4_DHCP_ATTRIBUTE_WITH_VALUE = 125 TestUtils.hexStringToByteArray("00060004c00002c8"); 126 private static final byte[] IPV4_DHCP_ATTRIBUTE_WITHOUT_VALUE = 127 TestUtils.hexStringToByteArray("00060000"); 128 129 private static final byte[] IPV4_SUBNET_ATTRIBUTE_VALUE = 130 TestUtils.hexStringToByteArray("c0000264fffffff0"); 131 private static final byte[] IPV4_SUBNET_ATTRIBUTE_WITH_VALUE = 132 TestUtils.hexStringToByteArray("000d0008c0000264fffffff0"); 133 private static final byte[] IPV4_SUBNET_ATTRIBUTE_WITHOUT_VALUE = 134 TestUtils.hexStringToByteArray("000d0000"); 135 136 private static final Inet4Address IPV4_PCSCF_ADDR = 137 (Inet4Address) InetAddresses.parseNumericAddress("192.0.2.1"); 138 private static final byte[] IPV4_PCSCF_ATTRIBUTE_WITH_VALUE = 139 TestUtils.hexStringToByteArray("00140004c0000201"); 140 private static final byte[] IPV4_PCSCF_ATTRIBUTE_WITHOUT_VALUE = 141 TestUtils.hexStringToByteArray("00140000"); 142 143 private static final Inet6Address IPV6_ADDRESS = 144 (Inet6Address) InetAddresses.parseNumericAddress("2001:db8::1"); 145 private static final int IP6_PREFIX_LEN = 64; 146 private static final LinkAddress IPV6_LINK_ADDRESS = 147 new LinkAddress(IPV6_ADDRESS, IP6_PREFIX_LEN); 148 149 private static final byte[] IPV6_ADDRESS_ATTRIBUTE_VALUE = 150 TestUtils.hexStringToByteArray("20010db800000000000000000000000140"); 151 private static final byte[] IPV6_ADDRESS_ATTRIBUTE_WITH_VALUE = 152 TestUtils.hexStringToByteArray("0008001120010db800000000000000000000000140"); 153 private static final byte[] IPV6_ADDRESS_ATTRIBUTE_WITHOUT_VALUE = 154 TestUtils.hexStringToByteArray("00080000"); 155 156 private static final byte[] IPV6_SUBNET_ATTRIBUTE_VALUE = IPV6_ADDRESS_ATTRIBUTE_VALUE; 157 private static final byte[] IPV6_SUBNET_ATTRIBUTE_WITH_VALUE = 158 TestUtils.hexStringToByteArray("000f001120010db800000000000000000000000140"); 159 private static final byte[] IPV6_SUBNET_ATTRIBUTE_WITHOUT_VALUE = 160 TestUtils.hexStringToByteArray("000f0000"); 161 162 private static final Inet6Address IPV6_DNS = 163 (Inet6Address) InetAddresses.parseNumericAddress("2001:db8:100::1"); 164 private static final byte[] IPV6_DNS_ATTRIBUTE_WITHOUT_VALUE = 165 TestUtils.hexStringToByteArray("000a0000"); 166 167 private static final Inet6Address IPV6_PCSCF_ADDR = 168 (Inet6Address) InetAddresses.parseNumericAddress("2001:db8::1"); 169 private static final byte[] IPV6_PCSCF_ATTRIBUTE_WITH_VALUE = 170 TestUtils.hexStringToByteArray("0015001020010db8000000000000000000000001"); 171 private static final byte[] IPV6_PCSCF_ATTRIBUTE_WITHOUT_VALUE = 172 TestUtils.hexStringToByteArray("00150000"); 173 174 private static final String APP_VERSION = "Test IKE Server 1.0"; 175 private static final byte[] APP_VERSION_ATTRIBUTE_WITH_VALUE = 176 TestUtils.hexStringToByteArray("000700135465737420494b452053657276657220312e30"); 177 private static final byte[] APP_VERSION_ATTRIBUTE_WITHOUT_VALUE = 178 TestUtils.hexStringToByteArray("00070000"); 179 180 private Inet4Address[] mNetMasks; 181 private int[] mIpv4PrefixLens; 182 183 @Before setUp()184 public void setUp() throws Exception { 185 mNetMasks = 186 new Inet4Address[] { 187 (Inet4Address) InetAddresses.parseNumericAddress("0.0.0.0"), 188 (Inet4Address) InetAddresses.parseNumericAddress("255.255.255.255"), 189 (Inet4Address) InetAddresses.parseNumericAddress("255.255.255.240") 190 }; 191 mIpv4PrefixLens = new int[] {0, 32, 28}; 192 } 193 verifyDecodeHeaderAndGetPayload( IkePayload payload, int expectedConfigType)194 private IkeConfigPayload verifyDecodeHeaderAndGetPayload( 195 IkePayload payload, int expectedConfigType) { 196 assertEquals(PAYLOAD_TYPE_CP, payload.payloadType); 197 assertFalse(payload.isCritical); 198 assertTrue(payload instanceof IkeConfigPayload); 199 200 IkeConfigPayload configPayload = (IkeConfigPayload) payload; 201 assertEquals(expectedConfigType, configPayload.configType); 202 203 return configPayload; 204 } 205 206 @Test testDecodeConfigRequest()207 public void testDecodeConfigRequest() throws Exception { 208 IkePayload payload = 209 IkePayloadFactory.getIkePayload( 210 PAYLOAD_TYPE_CP, 211 false /*isResp*/, 212 ByteBuffer.wrap(CONFIG_REQ_PAYLOAD)) 213 .first; 214 215 IkeConfigPayload configPayload = 216 verifyDecodeHeaderAndGetPayload(payload, CONFIG_TYPE_REQUEST); 217 218 List<ConfigAttribute> recognizedAttributeList = configPayload.recognizedAttributeList; 219 assertEquals(6, recognizedAttributeList.size()); 220 221 ConfigAttribute att = recognizedAttributeList.get(0); 222 assertEquals(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, att.attributeType); 223 assertNull(((ConfigAttributeIpv4Address) att).address); 224 225 att = recognizedAttributeList.get(1); 226 assertEquals(CONFIG_ATTR_INTERNAL_IP6_ADDRESS, att.attributeType); 227 assertNull(((ConfigAttributeIpv6Address) att).linkAddress); 228 229 att = recognizedAttributeList.get(2); 230 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DNS, att.attributeType); 231 assertNull(((ConfigAttributeIpv4Dns) att).address); 232 233 att = recognizedAttributeList.get(3); 234 assertEquals(CONFIG_ATTR_INTERNAL_IP6_DNS, att.attributeType); 235 assertNull(((ConfigAttributeIpv6Dns) att).address); 236 237 att = recognizedAttributeList.get(4); 238 assertEquals(CONFIG_ATTR_IP4_PCSCF, att.attributeType); 239 assertEquals(IPV4_PCSCF_ADDR, ((ConfigAttributeIpv4Pcscf) att).address); 240 241 att = recognizedAttributeList.get(5); 242 assertEquals(CONFIG_ATTR_IP6_PCSCF, att.attributeType); 243 assertEquals(IPV6_PCSCF_ADDR, ((ConfigAttributeIpv6Pcscf) att).address); 244 } 245 246 @Test testDecodeConfigResponse()247 public void testDecodeConfigResponse() throws Exception { 248 IkePayload payload = 249 IkePayloadFactory.getIkePayload( 250 PAYLOAD_TYPE_CP, 251 true /*isResp*/, 252 ByteBuffer.wrap(CONFIG_RESP_PAYLOAD)) 253 .first; 254 255 IkeConfigPayload configPayload = 256 verifyDecodeHeaderAndGetPayload(payload, CONFIG_TYPE_REPLY); 257 258 List<ConfigAttribute> recognizedAttributeList = configPayload.recognizedAttributeList; 259 assertEquals(5, recognizedAttributeList.size()); 260 261 ConfigAttribute att = recognizedAttributeList.get(0); 262 assertEquals(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, att.attributeType); 263 assertEquals(IPV4_ADDRESS, ((ConfigAttributeIpv4Address) att).address); 264 265 att = recognizedAttributeList.get(1); 266 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DNS, att.attributeType); 267 assertEquals(IPV4_DNS, ((ConfigAttributeIpv4Dns) att).address); 268 269 att = recognizedAttributeList.get(2); 270 InetAddress expectedDns = InetAddress.getByName("8.8.4.4"); 271 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DNS, att.attributeType); 272 assertEquals(expectedDns, ((ConfigAttributeIpv4Dns) att).address); 273 274 att = recognizedAttributeList.get(3); 275 assertEquals(CONFIG_ATTR_IP4_PCSCF, att.attributeType); 276 assertEquals(IPV4_PCSCF_ADDR, ((ConfigAttributeIpv4Pcscf) att).address); 277 278 att = recognizedAttributeList.get(4); 279 assertEquals(CONFIG_ATTR_IP6_PCSCF, att.attributeType); 280 assertEquals(IPV6_PCSCF_ADDR, ((ConfigAttributeIpv6Pcscf) att).address); 281 } 282 283 @Test testDecodeConfigRespWithTwoNetmask()284 public void testDecodeConfigRespWithTwoNetmask() throws Exception { 285 byte[] configPayloadBytes = 286 TestUtils.hexStringToByteArray(CONFIG_RESP_PAYLOAD_INVALID_ONE_HEX); 287 try { 288 IkePayloadFactory.getIkePayload( 289 PAYLOAD_TYPE_CP, true /*isResp*/, ByteBuffer.wrap(configPayloadBytes)); 290 fail("Expected to fail because more than on netmask found"); 291 } catch (InvalidSyntaxException expected) { 292 } 293 } 294 295 @Test testDecodeConfigRespNetmaskFoundWithoutIpv4Addr()296 public void testDecodeConfigRespNetmaskFoundWithoutIpv4Addr() throws Exception { 297 byte[] configPayloadBytes = 298 TestUtils.hexStringToByteArray(CONFIG_RESP_PAYLOAD_INVALID_TWO_HEX); 299 try { 300 IkePayloadFactory.getIkePayload( 301 PAYLOAD_TYPE_CP, true /*isResp*/, ByteBuffer.wrap(configPayloadBytes)); 302 fail("Expected to fail because netmask is found without a IPv4 address"); 303 } catch (InvalidSyntaxException expected) { 304 } 305 } 306 makeMockAttribute(byte[] encodedAttribute)307 private ConfigAttribute makeMockAttribute(byte[] encodedAttribute) { 308 ConfigAttribute mockAttribute = mock(ConfigAttribute.class); 309 310 doReturn(encodedAttribute.length).when(mockAttribute).getAttributeLen(); 311 312 doAnswer( 313 (invocation) -> { 314 ByteBuffer buffer = (ByteBuffer) invocation.getArguments()[0]; 315 buffer.put(encodedAttribute); 316 return null; 317 }) 318 .when(mockAttribute) 319 .encodeAttributeToByteBuffer(any(ByteBuffer.class)); 320 321 return mockAttribute; 322 } 323 324 @Test testBuildAndEncodeOutboundConfig()325 public void testBuildAndEncodeOutboundConfig() throws Exception { 326 List<ConfigAttribute> mockAttributeList = new ArrayList<>(); 327 mockAttributeList.add(makeMockAttribute(IPV4_ADDRESS_ATTRIBUTE_WITHOUT_VALUE)); 328 mockAttributeList.add(makeMockAttribute(IPV6_ADDRESS_ATTRIBUTE_WITHOUT_VALUE)); 329 mockAttributeList.add(makeMockAttribute(IPV4_DNS_ATTRIBUTE_WITHOUT_VALUE)); 330 mockAttributeList.add(makeMockAttribute(IPV6_DNS_ATTRIBUTE_WITHOUT_VALUE)); 331 mockAttributeList.add(makeMockAttribute(IPV4_PCSCF_ATTRIBUTE_WITH_VALUE)); 332 mockAttributeList.add(makeMockAttribute(IPV6_PCSCF_ATTRIBUTE_WITH_VALUE)); 333 IkeConfigPayload configPayload = new IkeConfigPayload(false /*isReply*/, mockAttributeList); 334 335 assertEquals(PAYLOAD_TYPE_CP, configPayload.payloadType); 336 assertFalse(configPayload.isCritical); 337 assertEquals(CONFIG_TYPE_REQUEST, configPayload.configType); 338 assertEquals(mockAttributeList, configPayload.recognizedAttributeList); 339 340 ByteBuffer buffer = ByteBuffer.allocate(configPayload.getPayloadLength()); 341 configPayload.encodeToByteBuffer(PAYLOAD_TYPE_NOTIFY, buffer); 342 assertArrayEquals(CONFIG_REQ_PAYLOAD, buffer.array()); 343 } 344 verifyBuildAndEncodeAttributeCommon( ConfigAttribute attribute, int expectedAttributeType, byte[] expectedEncodedAttribute)345 private void verifyBuildAndEncodeAttributeCommon( 346 ConfigAttribute attribute, int expectedAttributeType, byte[] expectedEncodedAttribute) { 347 assertEquals(expectedAttributeType, attribute.attributeType); 348 349 ByteBuffer buffer = ByteBuffer.allocate(attribute.getAttributeLen()); 350 attribute.encodeAttributeToByteBuffer(buffer); 351 assertArrayEquals(expectedEncodedAttribute, buffer.array()); 352 } 353 verifyEncodeIpv4AddressBaseAttribute( TunnelModeChildConfigAttrIpv4AddressBase attribute, int expectedAttributeType, byte[] expectedEncodedAttribute, Inet4Address expectedAddress)354 private void verifyEncodeIpv4AddressBaseAttribute( 355 TunnelModeChildConfigAttrIpv4AddressBase attribute, 356 int expectedAttributeType, 357 byte[] expectedEncodedAttribute, 358 Inet4Address expectedAddress) { 359 verifyBuildAndEncodeAttributeCommon( 360 attribute, expectedAttributeType, expectedEncodedAttribute); 361 assertEquals(expectedAddress, attribute.address); 362 } 363 verifyEncodeIpv4AddressBaseAttribute( IkeConfigAttrIpv4AddressBase attribute, int expectedAttributeType, byte[] expectedEncodedAttribute, Inet4Address expectedAddress)364 private void verifyEncodeIpv4AddressBaseAttribute( 365 IkeConfigAttrIpv4AddressBase attribute, 366 int expectedAttributeType, 367 byte[] expectedEncodedAttribute, 368 Inet4Address expectedAddress) { 369 verifyBuildAndEncodeAttributeCommon( 370 attribute, expectedAttributeType, expectedEncodedAttribute); 371 assertEquals(expectedAddress, attribute.address); 372 } 373 verifyEncodeIpv6AddressBaseAttribute( TunnelModeChildConfigAttrIpv6AddressBase attribute, int expectedAttributeType, byte[] expectedEncodedAttribute, Inet6Address expectedAddress)374 private void verifyEncodeIpv6AddressBaseAttribute( 375 TunnelModeChildConfigAttrIpv6AddressBase attribute, 376 int expectedAttributeType, 377 byte[] expectedEncodedAttribute, 378 Inet6Address expectedAddress) { 379 verifyBuildAndEncodeAttributeCommon( 380 attribute, expectedAttributeType, expectedEncodedAttribute); 381 assertEquals(expectedAddress, attribute.address); 382 } 383 verifyEncodeIpv6AddressBaseAttribute( IkeConfigAttrIpv6AddressBase attribute, int expectedAttributeType, byte[] expectedEncodedAttribute, Inet6Address expectedAddress)384 private void verifyEncodeIpv6AddressBaseAttribute( 385 IkeConfigAttrIpv6AddressBase attribute, 386 int expectedAttributeType, 387 byte[] expectedEncodedAttribute, 388 Inet6Address expectedAddress) { 389 verifyBuildAndEncodeAttributeCommon( 390 attribute, expectedAttributeType, expectedEncodedAttribute); 391 assertEquals(expectedAddress, attribute.address); 392 } 393 verifyEncodeIpv6RangeBaseAttribute( TunnelModeChildConfigAttrIpv6AddrRangeBase attribute, int expectedAttributeType, byte[] expectedEncodedAttribute, LinkAddress expectedLinkAddress)394 private void verifyEncodeIpv6RangeBaseAttribute( 395 TunnelModeChildConfigAttrIpv6AddrRangeBase attribute, 396 int expectedAttributeType, 397 byte[] expectedEncodedAttribute, 398 LinkAddress expectedLinkAddress) { 399 verifyBuildAndEncodeAttributeCommon( 400 attribute, expectedAttributeType, expectedEncodedAttribute); 401 assertEquals(expectedLinkAddress, attribute.linkAddress); 402 } 403 verifyPersistableBundleEncodeDecodeIsLossless(ConfigAttribute attribute)404 private static void verifyPersistableBundleEncodeDecodeIsLossless(ConfigAttribute attribute) { 405 PersistableBundle bundle = attribute.toPersistableBundle(); 406 ConfigAttribute resultAttribute = ConfigAttribute.fromPersistableBundle(bundle); 407 408 assertEquals(attribute, resultAttribute); 409 } 410 411 @Test testDecodeIpv4AddressWithValue()412 public void testDecodeIpv4AddressWithValue() throws Exception { 413 ConfigAttributeIpv4Address attributeIp4Address = 414 new ConfigAttributeIpv4Address(IPV4_ADDRESS.getAddress()); 415 416 assertEquals(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, attributeIp4Address.attributeType); 417 assertEquals(IPV4_ADDRESS, attributeIp4Address.address); 418 } 419 420 @Test testDecodeIpv4AddressWithoutValue()421 public void testDecodeIpv4AddressWithoutValue() throws Exception { 422 ConfigAttributeIpv4Address attributeIp4Address = 423 new ConfigAttributeIpv4Address(new byte[0]); 424 425 assertEquals(CONFIG_ATTR_INTERNAL_IP4_ADDRESS, attributeIp4Address.attributeType); 426 assertNull(attributeIp4Address.address); 427 } 428 429 @Test testDecodeIpv4AddressWithInvalidValue()430 public void testDecodeIpv4AddressWithInvalidValue() throws Exception { 431 byte[] invalidValue = new byte[] {1}; 432 433 try { 434 ConfigAttributeIpv4Address attributeIp4Address = 435 new ConfigAttributeIpv4Address(invalidValue); 436 fail("Expected to fail due to invalid attribute value"); 437 } catch (InvalidSyntaxException expected) { 438 } 439 } 440 441 @Test testEncodeIpv4AddressWithValue()442 public void testEncodeIpv4AddressWithValue() throws Exception { 443 ConfigAttributeIpv4Address attributeIp4Address = 444 new ConfigAttributeIpv4Address(IPV4_ADDRESS); 445 446 verifyEncodeIpv4AddressBaseAttribute( 447 attributeIp4Address, 448 CONFIG_ATTR_INTERNAL_IP4_ADDRESS, 449 IPV4_ADDRESS_ATTRIBUTE_WITH_VALUE, 450 IPV4_ADDRESS); 451 } 452 453 @Test testPersistableBundleEncodeDecodeIpv4AddressConfig()454 public void testPersistableBundleEncodeDecodeIpv4AddressConfig() throws Exception { 455 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Address(IPV4_ADDRESS)); 456 } 457 458 @Test testPersistableBundleEncodeDecodeIpv4AddressConfigEmpty()459 public void testPersistableBundleEncodeDecodeIpv4AddressConfigEmpty() throws Exception { 460 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Address()); 461 } 462 463 @Test testEncodeIpv4AddressWithoutValue()464 public void testEncodeIpv4AddressWithoutValue() throws Exception { 465 ConfigAttributeIpv4Address attributeIp4Address = new ConfigAttributeIpv4Address(); 466 467 verifyEncodeIpv4AddressBaseAttribute( 468 attributeIp4Address, 469 CONFIG_ATTR_INTERNAL_IP4_ADDRESS, 470 IPV4_ADDRESS_ATTRIBUTE_WITHOUT_VALUE, 471 null /*expectedAddress*/); 472 } 473 474 @Test testDecodeIpv4NetmaskWithValue()475 public void testDecodeIpv4NetmaskWithValue() throws Exception { 476 ConfigAttributeIpv4Netmask attribute = 477 new ConfigAttributeIpv4Netmask(IPV4_NETMASK.getAddress()); 478 479 assertEquals(CONFIG_ATTR_INTERNAL_IP4_NETMASK, attribute.attributeType); 480 assertEquals(IPV4_NETMASK, attribute.address); 481 } 482 483 @Test testDecodeIpv4NetmaskWithoutValue()484 public void testDecodeIpv4NetmaskWithoutValue() throws Exception { 485 ConfigAttributeIpv4Netmask attribute = new ConfigAttributeIpv4Netmask(new byte[0]); 486 487 assertEquals(CONFIG_ATTR_INTERNAL_IP4_NETMASK, attribute.attributeType); 488 assertNull(attribute.address); 489 } 490 491 @Test testEncodeIpv4Netmask()492 public void testEncodeIpv4Netmask() throws Exception { 493 ConfigAttributeIpv4Netmask attribute = new ConfigAttributeIpv4Netmask(); 494 495 verifyEncodeIpv4AddressBaseAttribute( 496 attribute, 497 CONFIG_ATTR_INTERNAL_IP4_NETMASK, 498 IPV4_NETMASK_ATTRIBUTE_WITHOUT_VALUE, 499 null /*expectedAddress*/); 500 } 501 502 @Test testPersistableBundleEncodeDecodeIpv4NetmaskConfig()503 public void testPersistableBundleEncodeDecodeIpv4NetmaskConfig() throws Exception { 504 verifyPersistableBundleEncodeDecodeIsLossless( 505 new ConfigAttributeIpv4Netmask(IPV4_NETMASK.getAddress())); 506 } 507 508 @Test testPersistableBundleEncodeDecodeIpv4NetmaskConfigEmpty()509 public void testPersistableBundleEncodeDecodeIpv4NetmaskConfigEmpty() throws Exception { 510 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Netmask()); 511 } 512 513 @Test testDecodeIpv4DnsWithValue()514 public void testDecodeIpv4DnsWithValue() throws Exception { 515 ConfigAttributeIpv4Dns attribute = new ConfigAttributeIpv4Dns(IPV4_DNS.getAddress()); 516 517 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DNS, attribute.attributeType); 518 assertEquals(IPV4_DNS, attribute.address); 519 } 520 521 @Test testDecodeIpv4DnsWithoutValue()522 public void testDecodeIpv4DnsWithoutValue() throws Exception { 523 ConfigAttributeIpv4Dns attribute = new ConfigAttributeIpv4Dns(new byte[0]); 524 525 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DNS, attribute.attributeType); 526 assertNull(attribute.address); 527 } 528 529 @Test testEncodeIpv4Dns()530 public void testEncodeIpv4Dns() throws Exception { 531 ConfigAttributeIpv4Dns attribute = new ConfigAttributeIpv4Dns(); 532 533 verifyEncodeIpv4AddressBaseAttribute( 534 attribute, 535 CONFIG_ATTR_INTERNAL_IP4_DNS, 536 IPV4_DNS_ATTRIBUTE_WITHOUT_VALUE, 537 null /*expectedAddress*/); 538 } 539 540 @Test testPersistableBundleEncodeDecodeIpv4DnsConfig()541 public void testPersistableBundleEncodeDecodeIpv4DnsConfig() throws Exception { 542 verifyPersistableBundleEncodeDecodeIsLossless( 543 new ConfigAttributeIpv4Dns(IPV4_DNS.getAddress())); 544 } 545 546 @Test testPersistableBundleEncodeDecodeIpv4DnsConfigEmpty()547 public void testPersistableBundleEncodeDecodeIpv4DnsConfigEmpty() throws Exception { 548 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Dns()); 549 } 550 551 @Test testDecodeIpv4DhcpWithValue()552 public void testDecodeIpv4DhcpWithValue() throws Exception { 553 ConfigAttributeIpv4Dhcp attribute = new ConfigAttributeIpv4Dhcp(IPV4_DHCP.getAddress()); 554 555 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DHCP, attribute.attributeType); 556 assertEquals(IPV4_DHCP, attribute.address); 557 } 558 559 @Test testDecodeIpv4DhcpWithoutValue()560 public void testDecodeIpv4DhcpWithoutValue() throws Exception { 561 ConfigAttributeIpv4Dhcp attribute = new ConfigAttributeIpv4Dhcp(new byte[0]); 562 563 assertEquals(CONFIG_ATTR_INTERNAL_IP4_DHCP, attribute.attributeType); 564 assertNull(attribute.address); 565 } 566 567 @Test testEncodeIpv4DhcpWithValue()568 public void testEncodeIpv4DhcpWithValue() throws Exception { 569 ConfigAttributeIpv4Dhcp attributeIp4Dhcp = new ConfigAttributeIpv4Dhcp(IPV4_DHCP); 570 571 verifyEncodeIpv4AddressBaseAttribute( 572 attributeIp4Dhcp, 573 CONFIG_ATTR_INTERNAL_IP4_DHCP, 574 IPV4_DHCP_ATTRIBUTE_WITH_VALUE, 575 IPV4_DHCP); 576 } 577 578 @Test testEncodeIpv4DhcpWithoutValue()579 public void testEncodeIpv4DhcpWithoutValue() throws Exception { 580 ConfigAttributeIpv4Dhcp attribute = new ConfigAttributeIpv4Dhcp(); 581 582 verifyEncodeIpv4AddressBaseAttribute( 583 attribute, 584 CONFIG_ATTR_INTERNAL_IP4_DHCP, 585 IPV4_DHCP_ATTRIBUTE_WITHOUT_VALUE, 586 null /*expectedAddress*/); 587 } 588 589 @Test testPersistableBundleEncodeDecodeIpv4DhcpConfig()590 public void testPersistableBundleEncodeDecodeIpv4DhcpConfig() throws Exception { 591 verifyPersistableBundleEncodeDecodeIsLossless( 592 new ConfigAttributeIpv4Dhcp(IPV4_DHCP.getAddress())); 593 } 594 595 @Test testPersistableBundleEncodeDecodeIpv4DhcpConfigEmpty()596 public void testPersistableBundleEncodeDecodeIpv4DhcpConfigEmpty() throws Exception { 597 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Dhcp()); 598 } 599 600 @Test testDecodeIpv4SubnetWithValue()601 public void testDecodeIpv4SubnetWithValue() throws Exception { 602 ConfigAttributeIpv4Subnet attributeIp4Subnet = 603 new ConfigAttributeIpv4Subnet(IPV4_SUBNET_ATTRIBUTE_VALUE); 604 605 assertEquals(CONFIG_ATTR_INTERNAL_IP4_SUBNET, attributeIp4Subnet.attributeType); 606 assertEquals(IPV4_LINK_ADDRESS, attributeIp4Subnet.linkAddress); 607 } 608 609 @Test testDecodeIpv4SubnetWithoutValue()610 public void testDecodeIpv4SubnetWithoutValue() throws Exception { 611 ConfigAttributeIpv4Subnet attributeIp4Subnet = new ConfigAttributeIpv4Subnet(new byte[0]); 612 613 assertEquals(CONFIG_ATTR_INTERNAL_IP4_SUBNET, attributeIp4Subnet.attributeType); 614 assertNull(attributeIp4Subnet.linkAddress); 615 } 616 617 @Test testDecodeIpv4SubnetWithInvalidValue()618 public void testDecodeIpv4SubnetWithInvalidValue() throws Exception { 619 byte[] ipAddress = IPV4_ADDRESS.getAddress(); 620 ByteBuffer buffer = ByteBuffer.allocate(ipAddress.length * 2); 621 buffer.put(ipAddress).put(ipAddress); 622 623 try { 624 new ConfigAttributeIpv4Subnet(buffer.array()); 625 fail("Expected to fail due to invalid netmask."); 626 } catch (InvalidSyntaxException expected) { 627 } 628 } 629 630 @Test testEncodeIpv4SubnetWithoutValue()631 public void testEncodeIpv4SubnetWithoutValue() throws Exception { 632 ConfigAttributeIpv4Subnet attributeIp4Subnet = new ConfigAttributeIpv4Subnet(); 633 634 verifyBuildAndEncodeAttributeCommon( 635 attributeIp4Subnet, 636 CONFIG_ATTR_INTERNAL_IP4_SUBNET, 637 IPV4_SUBNET_ATTRIBUTE_WITHOUT_VALUE); 638 assertNull(attributeIp4Subnet.linkAddress); 639 } 640 641 @Test testPersistableBundleEncodeDecodeIpv4SubnetConfig()642 public void testPersistableBundleEncodeDecodeIpv4SubnetConfig() throws Exception { 643 verifyPersistableBundleEncodeDecodeIsLossless( 644 new ConfigAttributeIpv4Subnet(IPV4_SUBNET_ATTRIBUTE_VALUE)); 645 } 646 647 @Test testPersistableBundleEncodeDecodeIpv4SubnetConfigEmpty()648 public void testPersistableBundleEncodeDecodeIpv4SubnetConfigEmpty() throws Exception { 649 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Subnet()); 650 } 651 652 @Test testNetmaskToPrefixLen()653 public void testNetmaskToPrefixLen() throws Exception { 654 for (int i = 0; i < mNetMasks.length; i++) { 655 assertEquals(mIpv4PrefixLens[i], ConfigAttribute.netmaskToPrefixLen(mNetMasks[i])); 656 } 657 } 658 659 @Test testPrefixToNetmaskBytes()660 public void testPrefixToNetmaskBytes() throws Exception { 661 for (int i = 0; i < mIpv4PrefixLens.length; i++) { 662 assertArrayEquals( 663 mNetMasks[i].getAddress(), 664 ConfigAttribute.prefixToNetmaskBytes(mIpv4PrefixLens[i])); 665 } 666 } 667 668 @Test testConstructIpv4PcscfWithValue()669 public void testConstructIpv4PcscfWithValue() throws Exception { 670 ConfigAttributeIpv4Pcscf attribute = new ConfigAttributeIpv4Pcscf(IPV4_PCSCF_ADDR); 671 672 assertEquals(CONFIG_ATTR_IP4_PCSCF, attribute.attributeType); 673 assertEquals(IPV4_PCSCF_ADDR, attribute.address); 674 } 675 676 @Test testConstructIpv4PcscfWithoutValue()677 public void testConstructIpv4PcscfWithoutValue() throws Exception { 678 ConfigAttributeIpv4Pcscf attribute = new ConfigAttributeIpv4Pcscf(); 679 680 assertEquals(CONFIG_ATTR_IP4_PCSCF, attribute.attributeType); 681 assertNull(attribute.address); 682 } 683 684 @Test testDecodeIpv4PcscfWithValue()685 public void testDecodeIpv4PcscfWithValue() throws Exception { 686 ConfigAttributeIpv4Pcscf attribute = 687 new ConfigAttributeIpv4Pcscf(IPV4_PCSCF_ADDR.getAddress()); 688 689 assertEquals(CONFIG_ATTR_IP4_PCSCF, attribute.attributeType); 690 assertEquals(IPV4_PCSCF_ADDR, attribute.address); 691 } 692 693 @Test testDecodeIpv4PcscfWithoutValue()694 public void testDecodeIpv4PcscfWithoutValue() throws Exception { 695 ConfigAttributeIpv4Pcscf attribute = new ConfigAttributeIpv4Pcscf(new byte[0]); 696 697 assertEquals(CONFIG_ATTR_IP4_PCSCF, attribute.attributeType); 698 assertNull(attribute.address); 699 } 700 701 @Test testEncodeIpv4PcscfWithValue()702 public void testEncodeIpv4PcscfWithValue() throws Exception { 703 ConfigAttributeIpv4Pcscf attribute = new ConfigAttributeIpv4Pcscf(IPV4_PCSCF_ADDR); 704 705 verifyEncodeIpv4AddressBaseAttribute( 706 attribute, CONFIG_ATTR_IP4_PCSCF, IPV4_PCSCF_ATTRIBUTE_WITH_VALUE, IPV4_PCSCF_ADDR); 707 } 708 709 @Test testEncodeIpv4PcscfWithoutValue()710 public void testEncodeIpv4PcscfWithoutValue() throws Exception { 711 ConfigAttributeIpv4Pcscf attribute = new ConfigAttributeIpv4Pcscf(); 712 713 verifyEncodeIpv4AddressBaseAttribute( 714 attribute, 715 CONFIG_ATTR_IP4_PCSCF, 716 IPV4_PCSCF_ATTRIBUTE_WITHOUT_VALUE, 717 null /*expectedAddress*/); 718 } 719 720 @Test testPersistableBundleEncodeDecodeIpv4PcscfConfig()721 public void testPersistableBundleEncodeDecodeIpv4PcscfConfig() throws Exception { 722 verifyPersistableBundleEncodeDecodeIsLossless( 723 new ConfigAttributeIpv4Pcscf(IPV4_PCSCF_ADDR)); 724 } 725 726 @Test testPersistableBundleEncodeDecodeIpv4PcscfConfigEmpty()727 public void testPersistableBundleEncodeDecodeIpv4PcscfConfigEmpty() throws Exception { 728 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv4Pcscf()); 729 } 730 731 @Test testDecodeIpv6AddressWithValue()732 public void testDecodeIpv6AddressWithValue() throws Exception { 733 ConfigAttributeIpv6Address attributeIp6Address = 734 new ConfigAttributeIpv6Address(IPV6_ADDRESS_ATTRIBUTE_VALUE); 735 736 assertEquals(CONFIG_ATTR_INTERNAL_IP6_ADDRESS, attributeIp6Address.attributeType); 737 assertEquals(IPV6_LINK_ADDRESS, attributeIp6Address.linkAddress); 738 } 739 740 @Test testDecodeIpv6AddressWithoutValue()741 public void testDecodeIpv6AddressWithoutValue() throws Exception { 742 ConfigAttributeIpv6Address attributeIp6Address = 743 new ConfigAttributeIpv6Address(new byte[0]); 744 745 assertEquals(CONFIG_ATTR_INTERNAL_IP6_ADDRESS, attributeIp6Address.attributeType); 746 assertNull(attributeIp6Address.linkAddress); 747 } 748 749 @Test testDecodeIpv6AddressWithInvalidValue()750 public void testDecodeIpv6AddressWithInvalidValue() throws Exception { 751 byte[] invalidValue = new byte[] {1}; 752 753 try { 754 ConfigAttributeIpv6Address attributeIp6Address = 755 new ConfigAttributeIpv6Address(invalidValue); 756 fail("Expected to fail due to invalid attribute value"); 757 } catch (InvalidSyntaxException expected) { 758 } 759 } 760 761 @Test testEncodeIpv6AddressWithValue()762 public void testEncodeIpv6AddressWithValue() throws Exception { 763 ConfigAttributeIpv6Address attributeIp6Address = 764 new ConfigAttributeIpv6Address(IPV6_LINK_ADDRESS); 765 766 verifyEncodeIpv6RangeBaseAttribute( 767 attributeIp6Address, 768 CONFIG_ATTR_INTERNAL_IP6_ADDRESS, 769 IPV6_ADDRESS_ATTRIBUTE_WITH_VALUE, 770 IPV6_LINK_ADDRESS); 771 } 772 773 @Test testEncodeIpv6AddressWithoutValue()774 public void testEncodeIpv6AddressWithoutValue() throws Exception { 775 ConfigAttributeIpv6Address attributeIp6Address = new ConfigAttributeIpv6Address(); 776 777 verifyEncodeIpv6RangeBaseAttribute( 778 attributeIp6Address, 779 CONFIG_ATTR_INTERNAL_IP6_ADDRESS, 780 IPV6_ADDRESS_ATTRIBUTE_WITHOUT_VALUE, 781 null /*expectedLinkAddress*/); 782 } 783 784 @Test testPersistableBundleEncodeDecodeIpv6AddressConfig()785 public void testPersistableBundleEncodeDecodeIpv6AddressConfig() throws Exception { 786 verifyPersistableBundleEncodeDecodeIsLossless( 787 new ConfigAttributeIpv6Address(IPV6_LINK_ADDRESS)); 788 } 789 790 @Test testPersistableBundleEncodeDecodeIpv6AddressConfigEmpty()791 public void testPersistableBundleEncodeDecodeIpv6AddressConfigEmpty() throws Exception { 792 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv6Address()); 793 } 794 795 @Test testDecodeIpv6SubnetWithValue()796 public void testDecodeIpv6SubnetWithValue() throws Exception { 797 ConfigAttributeIpv6Subnet attributeIp6Subnet = 798 new ConfigAttributeIpv6Subnet(IPV6_SUBNET_ATTRIBUTE_VALUE); 799 800 assertEquals(CONFIG_ATTR_INTERNAL_IP6_SUBNET, attributeIp6Subnet.attributeType); 801 assertEquals(IPV6_LINK_ADDRESS, attributeIp6Subnet.linkAddress); 802 } 803 804 @Test testDecodeIpv6SubnetWithoutValue()805 public void testDecodeIpv6SubnetWithoutValue() throws Exception { 806 ConfigAttributeIpv6Subnet attributeIp6Subnet = new ConfigAttributeIpv6Subnet(new byte[0]); 807 808 assertEquals(CONFIG_ATTR_INTERNAL_IP6_SUBNET, attributeIp6Subnet.attributeType); 809 assertNull(attributeIp6Subnet.linkAddress); 810 } 811 812 @Test testEncodeIpv6SubnetWithoutValue()813 public void testEncodeIpv6SubnetWithoutValue() throws Exception { 814 ConfigAttributeIpv6Subnet attributeIp6Subnet = new ConfigAttributeIpv6Subnet(); 815 816 verifyEncodeIpv6RangeBaseAttribute( 817 attributeIp6Subnet, 818 CONFIG_ATTR_INTERNAL_IP6_SUBNET, 819 IPV6_SUBNET_ATTRIBUTE_WITHOUT_VALUE, 820 null /*expectedLinkAddress*/); 821 } 822 823 @Test testPersistableBundleEncodeDecodeIpv6SubnetConfig()824 public void testPersistableBundleEncodeDecodeIpv6SubnetConfig() throws Exception { 825 verifyPersistableBundleEncodeDecodeIsLossless( 826 new ConfigAttributeIpv6Subnet(IPV6_SUBNET_ATTRIBUTE_VALUE)); 827 } 828 829 @Test testPersistableBundleEncodeDecodeIpv6SubnetConfigEmpty()830 public void testPersistableBundleEncodeDecodeIpv6SubnetConfigEmpty() throws Exception { 831 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv6Subnet()); 832 } 833 834 @Test testDecodeIpv6DnsWithValue()835 public void testDecodeIpv6DnsWithValue() throws Exception { 836 ConfigAttributeIpv6Dns attribute = new ConfigAttributeIpv6Dns(IPV6_DNS.getAddress()); 837 838 assertEquals(CONFIG_ATTR_INTERNAL_IP6_DNS, attribute.attributeType); 839 assertEquals(IPV6_DNS, attribute.address); 840 } 841 842 @Test testDecodeIpv6DnsWithoutValue()843 public void testDecodeIpv6DnsWithoutValue() throws Exception { 844 ConfigAttributeIpv6Dns attribute = new ConfigAttributeIpv6Dns(new byte[0]); 845 846 assertEquals(CONFIG_ATTR_INTERNAL_IP6_DNS, attribute.attributeType); 847 assertNull(attribute.address); 848 } 849 850 @Test testEncodeIpv6Dns()851 public void testEncodeIpv6Dns() throws Exception { 852 ConfigAttributeIpv6Dns attribute = new ConfigAttributeIpv6Dns(); 853 854 verifyBuildAndEncodeAttributeCommon( 855 attribute, CONFIG_ATTR_INTERNAL_IP6_DNS, IPV6_DNS_ATTRIBUTE_WITHOUT_VALUE); 856 assertNull(attribute.address); 857 } 858 859 @Test testPersistableBundleEncodeDecodeIpv6DnsConfig()860 public void testPersistableBundleEncodeDecodeIpv6DnsConfig() throws Exception { 861 verifyPersistableBundleEncodeDecodeIsLossless( 862 new ConfigAttributeIpv6Dns(IPV6_DNS.getAddress())); 863 } 864 865 @Test testPersistableBundleEncodeDecodeIpv6DnsConfigEmpty()866 public void testPersistableBundleEncodeDecodeIpv6DnsConfigEmpty() throws Exception { 867 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv6Dns()); 868 } 869 870 @Test testConstructIpv6PcscfWithValue()871 public void testConstructIpv6PcscfWithValue() throws Exception { 872 ConfigAttributeIpv6Pcscf attribute = new ConfigAttributeIpv6Pcscf(IPV6_PCSCF_ADDR); 873 874 assertEquals(CONFIG_ATTR_IP6_PCSCF, attribute.attributeType); 875 assertEquals(IPV6_PCSCF_ADDR, attribute.address); 876 } 877 878 @Test testConstructIpv6PcscfWithoutValue()879 public void testConstructIpv6PcscfWithoutValue() throws Exception { 880 ConfigAttributeIpv6Pcscf attribute = new ConfigAttributeIpv6Pcscf(); 881 882 assertEquals(CONFIG_ATTR_IP6_PCSCF, attribute.attributeType); 883 assertNull(attribute.address); 884 } 885 886 @Test testDecodeIpv6PcscfWithValue()887 public void testDecodeIpv6PcscfWithValue() throws Exception { 888 ConfigAttributeIpv6Pcscf attribute = 889 new ConfigAttributeIpv6Pcscf(IPV6_PCSCF_ADDR.getAddress()); 890 891 assertEquals(CONFIG_ATTR_IP6_PCSCF, attribute.attributeType); 892 assertEquals(IPV6_PCSCF_ADDR, attribute.address); 893 } 894 895 @Test testDecodeIpv6PcscfWithoutValue()896 public void testDecodeIpv6PcscfWithoutValue() throws Exception { 897 ConfigAttributeIpv6Pcscf attribute = new ConfigAttributeIpv6Pcscf(new byte[0]); 898 899 assertEquals(CONFIG_ATTR_IP6_PCSCF, attribute.attributeType); 900 assertNull(attribute.address); 901 } 902 903 @Test testEncodeIpv6PcscfWithValue()904 public void testEncodeIpv6PcscfWithValue() throws Exception { 905 ConfigAttributeIpv6Pcscf attribute = new ConfigAttributeIpv6Pcscf(IPV6_PCSCF_ADDR); 906 907 verifyEncodeIpv6AddressBaseAttribute( 908 attribute, CONFIG_ATTR_IP6_PCSCF, IPV6_PCSCF_ATTRIBUTE_WITH_VALUE, IPV6_PCSCF_ADDR); 909 } 910 911 @Test testEncodeIpv6PcscfWithoutValue()912 public void testEncodeIpv6PcscfWithoutValue() throws Exception { 913 ConfigAttributeIpv6Pcscf attribute = new ConfigAttributeIpv6Pcscf(); 914 915 verifyEncodeIpv6AddressBaseAttribute( 916 attribute, 917 CONFIG_ATTR_IP6_PCSCF, 918 IPV6_PCSCF_ATTRIBUTE_WITHOUT_VALUE, 919 null /*expectedAddress*/); 920 } 921 922 @Test testPersistableBundleEncodeDecodeIpv6PscsfConfig()923 public void testPersistableBundleEncodeDecodeIpv6PscsfConfig() throws Exception { 924 verifyPersistableBundleEncodeDecodeIsLossless( 925 new ConfigAttributeIpv6Pcscf(IPV6_PCSCF_ADDR)); 926 } 927 928 @Test testPersistableBundleEncodeDecodeIpv6PscsfConfigEmpty()929 public void testPersistableBundleEncodeDecodeIpv6PscsfConfigEmpty() throws Exception { 930 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeIpv6Pcscf()); 931 } 932 933 @Test testDecodeAppVersionWithValue()934 public void testDecodeAppVersionWithValue() throws Exception { 935 ConfigAttributeAppVersion attribute = new ConfigAttributeAppVersion(APP_VERSION.getBytes()); 936 937 assertEquals(CONFIG_ATTR_APPLICATION_VERSION, attribute.attributeType); 938 assertEquals(APP_VERSION, attribute.applicationVersion); 939 } 940 941 @Test testDecodeAppVersionWithoutValue()942 public void testDecodeAppVersionWithoutValue() throws Exception { 943 ConfigAttributeAppVersion attribute = new ConfigAttributeAppVersion(new byte[0]); 944 945 assertEquals(CONFIG_ATTR_APPLICATION_VERSION, attribute.attributeType); 946 assertEquals("", attribute.applicationVersion); 947 } 948 949 @Test testEncodeAppVersionWithValue()950 public void testEncodeAppVersionWithValue() throws Exception { 951 ConfigAttributeAppVersion attribute = new ConfigAttributeAppVersion(APP_VERSION); 952 953 verifyBuildAndEncodeAttributeCommon( 954 attribute, CONFIG_ATTR_APPLICATION_VERSION, APP_VERSION_ATTRIBUTE_WITH_VALUE); 955 assertEquals(APP_VERSION, attribute.applicationVersion); 956 } 957 958 @Test testEncodeAppVersionWithoutValue()959 public void testEncodeAppVersionWithoutValue() throws Exception { 960 ConfigAttributeAppVersion attribute = new ConfigAttributeAppVersion(); 961 962 verifyBuildAndEncodeAttributeCommon( 963 attribute, CONFIG_ATTR_APPLICATION_VERSION, APP_VERSION_ATTRIBUTE_WITHOUT_VALUE); 964 assertEquals("", attribute.applicationVersion); 965 } 966 967 @Test testPersistableBundleEncodeDecodeAppVersionConfig()968 public void testPersistableBundleEncodeDecodeAppVersionConfig() throws Exception { 969 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeAppVersion(APP_VERSION)); 970 } 971 972 @Test testPersistableBundleEncodeDecodeAppVersionConfigEmpty()973 public void testPersistableBundleEncodeDecodeAppVersionConfigEmpty() throws Exception { 974 verifyPersistableBundleEncodeDecodeIsLossless(new ConfigAttributeAppVersion()); 975 } 976 } 977