diff options
Diffstat (limited to 'tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes')
21 files changed, 0 insertions, 1967 deletions
diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutnTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutnTest.java deleted file mode 100644 index ebf22e4f..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutnTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_AUTN; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_AUTN; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_AUTN_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AUTN_BYTES; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtAutn; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtAutnTest { - private EapAkaAttributeFactory mEapAkaAttributeFactory; - - @Before - public void setUp() { - mEapAkaAttributeFactory = EapAkaAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_AUTN); - EapSimAkaAttribute result = mEapAkaAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtAutn atAutn = (AtAutn) result; - assertEquals(EAP_AT_AUTN, atAutn.attributeType); - assertEquals(AT_AUTN.length, atAutn.lengthInBytes); - assertArrayEquals(AUTN_BYTES, atAutn.autn); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_AUTN_INVALID_LENGTH); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtAutn atAutn = new AtAutn(AUTN_BYTES); - - ByteBuffer result = ByteBuffer.allocate(AT_AUTN.length); - atAutn.encode(result); - assertArrayEquals(AT_AUTN, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutsTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutsTest.java deleted file mode 100644 index d65a735f..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtAutsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_AUTS; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_AUTS; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_AUTS_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AUTS_BYTES; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtAuts; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtAutsTest { - private EapAkaAttributeFactory mEapAkaAttributeFactory; - - @Before - public void setUp() { - mEapAkaAttributeFactory = EapAkaAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_AUTS); - EapSimAkaAttribute result = mEapAkaAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtAuts atAuts = (AtAuts) result; - assertEquals(EAP_AT_AUTS, atAuts.attributeType); - assertEquals(AT_AUTS.length, atAuts.lengthInBytes); - assertArrayEquals(AUTS_BYTES, atAuts.auts); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_AUTS_INVALID_LENGTH); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtAuts atAuts = new AtAuts(AUTS_BYTES); - - ByteBuffer result = ByteBuffer.allocate(AT_AUTS.length); - atAuts.encode(result); - assertArrayEquals(AT_AUTS, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtBiddingTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtBiddingTest.java deleted file mode 100644 index efdfcc2e..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtBiddingTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_BIDDING; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_BIDDING_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_BIDDING_SUPPORTS_AKA_PRIME; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtBidding; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtBiddingTest { - private EapAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = EapAkaAttributeFactory.getInstance(); - } - - @Test - public void testDecodeServerSupportsAkaPrime() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_BIDDING_SUPPORTS_AKA_PRIME); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtBidding atBidding = (AtBidding) result; - assertEquals(EAP_AT_BIDDING, atBidding.attributeType); - assertEquals(AT_BIDDING_SUPPORTS_AKA_PRIME.length, atBidding.lengthInBytes); - assertTrue(atBidding.doesServerSupportEapAkaPrime); - } - - @Test - public void testDecodeDoesNotSupportAkaPrime() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtBidding atBidding = (AtBidding) result; - assertEquals(EAP_AT_BIDDING, atBidding.attributeType); - assertEquals(AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME.length, atBidding.lengthInBytes); - assertFalse(atBidding.doesServerSupportEapAkaPrime); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_BIDDING_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeServerSupportsAkaPrime() throws Exception { - AtBidding atBidding = new AtBidding(true); - - ByteBuffer result = ByteBuffer.allocate(AT_BIDDING_SUPPORTS_AKA_PRIME.length); - atBidding.encode(result); - assertArrayEquals(AT_BIDDING_SUPPORTS_AKA_PRIME, result.array()); - } - - @Test - public void testEncodeDoesNotSupportAkaPrime() throws Exception { - AtBidding atBidding = new AtBidding(false); - - ByteBuffer result = ByteBuffer.allocate(AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME.length); - atBidding.encode(result); - assertArrayEquals(AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtClientErrorCodeTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtClientErrorCodeTest.java deleted file mode 100644 index 2051414c..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtClientErrorCodeTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToInt; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_CLIENT_ERROR_CODE; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_CLIENT_ERROR_CODE; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_CLIENT_ERROR_CODE_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.ERROR_CODE; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtClientErrorCode; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.BufferUnderflowException; -import java.nio.ByteBuffer; - -public class AtClientErrorCodeTest { - private static final int EXPECTED_LENGTH = 4; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_CLIENT_ERROR_CODE); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtClientErrorCode); - AtClientErrorCode atClientErrorCode = (AtClientErrorCode) result; - assertEquals(EAP_AT_CLIENT_ERROR_CODE, atClientErrorCode.attributeType); - assertEquals(EXPECTED_LENGTH, atClientErrorCode.lengthInBytes); - assertEquals(hexStringToInt(ERROR_CODE), atClientErrorCode.errorCode); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_CLIENT_ERROR_CODE_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected BufferUnderflowException for invalid attribute length"); - } catch (BufferUnderflowException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtClientErrorCode atNotification = new AtClientErrorCode( - EXPECTED_LENGTH, hexStringToInt(ERROR_CODE)); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atNotification.encode(result); - assertArrayEquals(AT_CLIENT_ERROR_CODE, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtCounterTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtCounterTest.java deleted file mode 100644 index eb1086d5..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtCounterTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_COUNTER; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_COUNTER_TOO_SMALL; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_COUNTER; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_COUNTER_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_COUNTER_TOO_SMALL; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_COUNTER_TOO_SMALL_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.COUNTER_INT; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtCounter; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtCounterTooSmall; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtCounterTest { - private static final int EXPECTED_LENGTH = 4; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecodeAtCounter() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_COUNTER); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtCounter); - AtCounter atCounter = (AtCounter) result; - assertEquals(EAP_AT_COUNTER, atCounter.attributeType); - assertEquals(EXPECTED_LENGTH, atCounter.lengthInBytes); - assertEquals(COUNTER_INT, atCounter.counter); - } - - @Test - public void testDecodeAtCounterInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_COUNTER_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeAtCounter() throws Exception { - AtCounter atCounter = new AtCounter(COUNTER_INT); - - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - atCounter.encode(result); - assertArrayEquals(AT_COUNTER, result.array()); - } - - @Test - public void testAtCounterTooSmallConstructor() throws Exception { - AtCounterTooSmall atCounterTooSmall = new AtCounterTooSmall(); - assertEquals(EAP_AT_COUNTER_TOO_SMALL, atCounterTooSmall.attributeType); - assertEquals(EXPECTED_LENGTH, atCounterTooSmall.lengthInBytes); - } - - @Test - public void testDecodeAtCounterTooSmall() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_COUNTER_TOO_SMALL); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtCounterTooSmall); - AtCounterTooSmall atCounterTooSmall = (AtCounterTooSmall) result; - assertEquals(EAP_AT_COUNTER_TOO_SMALL, atCounterTooSmall.attributeType); - assertEquals(EXPECTED_LENGTH, atCounterTooSmall.lengthInBytes); - } - - @Test - public void testDecodeAtCounterTooSmallInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_COUNTER_TOO_SMALL_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeAtCounterTooSmall() throws Exception { - AtCounterTooSmall atCounterTooSmall = new AtCounterTooSmall(); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - atCounterTooSmall.encode(result); - assertArrayEquals(AT_COUNTER_TOO_SMALL, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdReqTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdReqTest.java deleted file mode 100644 index d006053e..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdReqTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_ANY_ID_REQ; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_FULLAUTH_ID_REQ; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_PERMANENT_ID_REQ; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.ANY_ID_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_ANY_ID_REQ; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_FULL_AUTH_ID_REQ; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_PERMANENT_ID_REQ; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.FULL_AUTH_ID_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.PERMANENT_ID_INVALID_LENGTH; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtAnyIdReq; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtFullauthIdReq; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtPermanentIdReq; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtIdReqTest { - private static final int EXPECTED_LENGTH = 4; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecodeAtPermanentIdReq() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_PERMANENT_ID_REQ); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtPermanentIdReq); - AtPermanentIdReq atPermanentIdReq = (AtPermanentIdReq) result; - assertEquals(EAP_AT_PERMANENT_ID_REQ, atPermanentIdReq.attributeType); - assertEquals(EXPECTED_LENGTH, atPermanentIdReq.lengthInBytes); - } - - @Test - public void testDecodeAtPermanentIdReqInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(PERMANENT_ID_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid attribute length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeAtPermanentIdReq() throws Exception { - AtPermanentIdReq atPermanentIdReq = new AtPermanentIdReq(); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atPermanentIdReq.encode(result); - assertArrayEquals(AT_PERMANENT_ID_REQ, result.array()); - } - - @Test - public void testDecodeAtAnyIdReq() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_ANY_ID_REQ); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtAnyIdReq); - AtAnyIdReq atAnyIdReq = (AtAnyIdReq) result; - assertEquals(EAP_AT_ANY_ID_REQ, atAnyIdReq.attributeType); - assertEquals(EXPECTED_LENGTH, atAnyIdReq.lengthInBytes); - } - - @Test - public void testDecodeAtAnyIdReqInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(ANY_ID_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid attribute length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeAtAnyIdReq() throws Exception { - AtAnyIdReq atPermanentIdReq = new AtAnyIdReq(); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atPermanentIdReq.encode(result); - assertArrayEquals(AT_ANY_ID_REQ, result.array()); - } - - @Test - public void testDecodeAtFullauthIdReq() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_FULL_AUTH_ID_REQ); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtFullauthIdReq); - AtFullauthIdReq atFullauthIdReq = (AtFullauthIdReq) result; - assertEquals(EAP_AT_FULLAUTH_ID_REQ, atFullauthIdReq.attributeType); - assertEquals(EXPECTED_LENGTH, atFullauthIdReq.lengthInBytes); - } - - @Test - public void testDecodeAtFullauthIdReqInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(FULL_AUTH_ID_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid attribute length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncodeAtFullauthIdReq() throws Exception { - AtFullauthIdReq atPermanentIdReq = new AtFullauthIdReq(); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atPermanentIdReq.encode(result); - assertArrayEquals(AT_FULL_AUTH_ID_REQ, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdentityTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdentityTest.java deleted file mode 100644 index cf8e8803..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtIdentityTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_IDENTITY; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_IDENTITY; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.IDENTITY; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtIdentity; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtIdentityTest { - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_IDENTITY); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtIdentity); - AtIdentity atIdentity = (AtIdentity) result; - assertEquals(EAP_AT_IDENTITY, atIdentity.attributeType); - assertEquals(AT_IDENTITY.length, atIdentity.lengthInBytes); - assertArrayEquals(IDENTITY, atIdentity.identity); - } - - @Test - public void testEncode() throws Exception { - AtIdentity atIdentity = new AtIdentity(AT_IDENTITY.length, IDENTITY); - ByteBuffer result = ByteBuffer.allocate(AT_IDENTITY.length); - atIdentity.encode(result); - - assertArrayEquals(AT_IDENTITY, result.array()); - } - - @Test - public void testGetAtIdentity() throws Exception { - AtIdentity atIdentity = AtIdentity.getAtIdentity(IDENTITY); - - assertArrayEquals(IDENTITY, atIdentity.identity); - - ByteBuffer buffer = ByteBuffer.allocate(atIdentity.lengthInBytes); - atIdentity.encode(buffer); - buffer.rewind(); - - EapSimAkaAttribute eapSimAkaAttribute = - EapSimAttributeFactory.getInstance().getAttribute(buffer); - assertTrue(eapSimAkaAttribute instanceof AtIdentity); - AtIdentity newAtIdentity = (AtIdentity) eapSimAkaAttribute; - assertEquals(atIdentity.lengthInBytes, newAtIdentity.lengthInBytes); - assertArrayEquals(atIdentity.identity, newAtIdentity.identity); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfInputTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfInputTest.java deleted file mode 100644 index 51ea3f14..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfInputTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_KDF_INPUT; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_KDF_INPUT; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_KDF_INPUT_EMPTY_NETWORK_NAME; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.NETWORK_NAME_BYTES; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import com.android.internal.net.eap.message.simaka.EapAkaPrimeAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtKdfInput; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtKdfInputTest { - private EapAkaPrimeAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = EapAkaPrimeAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_KDF_INPUT); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtKdfInput atKdfInput = (AtKdfInput) result; - assertEquals(EAP_AT_KDF_INPUT, atKdfInput.attributeType); - assertEquals(AT_KDF_INPUT.length, atKdfInput.lengthInBytes); - assertArrayEquals(NETWORK_NAME_BYTES, atKdfInput.networkName); - } - - @Test - public void testDecodeEmptyNetworkName() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_KDF_INPUT_EMPTY_NETWORK_NAME); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtKdfInput atKdfInput = (AtKdfInput) result; - assertEquals(EAP_AT_KDF_INPUT, atKdfInput.attributeType); - assertEquals(AT_KDF_INPUT_EMPTY_NETWORK_NAME.length, atKdfInput.lengthInBytes); - assertArrayEquals(new byte[0], atKdfInput.networkName); - } - - @Test - public void testEncode() throws Exception { - AtKdfInput atKdfInput = new AtKdfInput(AT_KDF_INPUT.length, NETWORK_NAME_BYTES); - ByteBuffer result = ByteBuffer.allocate(AT_KDF_INPUT.length); - - atKdfInput.encode(result); - assertArrayEquals(AT_KDF_INPUT, result.array()); - assertFalse(result.hasRemaining()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfTest.java deleted file mode 100644 index 0bb07326..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtKdfTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_KDF; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_KDF; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_KDF_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.KDF_VERSION; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaPrimeAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtKdf; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtKdfTest { - private EapAkaPrimeAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = EapAkaPrimeAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_KDF); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtKdf atKdf = (AtKdf) result; - assertEquals(EAP_AT_KDF, atKdf.attributeType); - assertEquals(AT_KDF.length, atKdf.lengthInBytes); - assertEquals(KDF_VERSION, atKdf.kdf); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_KDF_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtKdf atKdf = new AtKdf(KDF_VERSION); - ByteBuffer result = ByteBuffer.allocate(AT_KDF.length); - - atKdf.encode(result); - assertArrayEquals(AT_KDF, result.array()); - assertFalse(result.hasRemaining()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtMacTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtMacTest.java deleted file mode 100644 index 82b066d5..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtMacTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToByteArray; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_MAC; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_MAC; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_MAC_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.MAC; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtMac; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtMacTest { - private static final int EXPECTED_LENGTH = 20; - private static final int MAC_LENGTH = 16; - private static final byte[] MAC_BYTES = hexStringToByteArray(MAC); - private static final byte[] INVALID_MAC = {(byte) 1, (byte) 2, (byte) 3}; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testConstructor() throws Exception { - AtMac atMac = new AtMac(); - assertEquals(EAP_AT_MAC, atMac.attributeType); - assertEquals(EXPECTED_LENGTH, atMac.lengthInBytes); - assertArrayEquals(new byte[MAC_LENGTH], atMac.mac); - } - - @Test - public void testParameterizedConstructor() throws Exception { - AtMac atMac = new AtMac(MAC_BYTES); - assertEquals(EAP_AT_MAC, atMac.attributeType); - assertEquals(EXPECTED_LENGTH, atMac.lengthInBytes); - assertArrayEquals(MAC_BYTES, atMac.mac); - } - - @Test - public void testParameterizedConstructorInvalidMac() { - try { - AtMac atMac = new AtMac(INVALID_MAC); - fail("Expected EapSimAkaInvalidAttributeException for invalid MAC length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_MAC); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtMac); - AtMac atMac = (AtMac) result; - assertEquals(EAP_AT_MAC, atMac.attributeType); - assertEquals(EXPECTED_LENGTH, atMac.lengthInBytes); - assertArrayEquals(MAC_BYTES, atMac.mac); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_MAC_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtMac atMac = new AtMac(MAC_BYTES); - - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - atMac.encode(result); - assertArrayEquals(AT_MAC, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceMtTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceMtTest.java deleted file mode 100644 index 751908a2..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceMtTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_NONCE_MT; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NONCE_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NONCE_MT; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.NONCE_MT; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtNonceMt; -import com.android.internal.net.eap.message.simaka.EapSimAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtNonceMtTest { - private static final byte[] INVALID_NONCE = new byte[10]; - private static final int EXPECTED_LENGTH = 20; - - private EapSimAttributeFactory mEapSimAttributeFactory; - - @Before - public void setUp() { - mEapSimAttributeFactory = EapSimAttributeFactory.getInstance(); - } - - @Test - public void testConstructorInvalidNonceLength() { - try { - new AtNonceMt(INVALID_NONCE); - fail("Expected EapSimAkaInvalidAttributeException for invalid NonceMt length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NONCE_MT); - EapSimAkaAttribute result = mEapSimAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtNonceMt); - AtNonceMt atNonceMt = (AtNonceMt) result; - assertEquals(EAP_AT_NONCE_MT, atNonceMt.attributeType); - assertEquals(EXPECTED_LENGTH, atNonceMt.lengthInBytes); - assertArrayEquals(NONCE_MT, atNonceMt.nonceMt); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NONCE_INVALID_LENGTH); - try { - mEapSimAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid attribute length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws EapSimAkaInvalidAttributeException { - AtNonceMt atNonceMt = new AtNonceMt(NONCE_MT); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atNonceMt.encode(result); - assertArrayEquals(AT_NONCE_MT, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceSTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceSTest.java deleted file mode 100644 index 1ad64669..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNonceSTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToByteArray; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_NONCE_S; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NONCE_S; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NONCE_S_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.NONCE_S; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtNonceS; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtNonceSTest { - private static final byte[] INVALID_NONCE = new byte[10]; - private static final int EXPECTED_LENGTH = 20; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testConstructorInvalidNonceLength() { - try { - new AtNonceS(INVALID_NONCE); - fail("Expected EapSimAkaInvalidAttributeException for invalid NonceMt length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NONCE_S); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtNonceS); - AtNonceS atNonceS = (AtNonceS) result; - assertEquals(EAP_AT_NONCE_S, atNonceS.attributeType); - assertEquals(EXPECTED_LENGTH, atNonceS.lengthInBytes); - assertArrayEquals(hexStringToByteArray(NONCE_S), atNonceS.nonceS); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NONCE_S_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtNonceS atNonceS = new AtNonceS(hexStringToByteArray(NONCE_S)); - - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - atNonceS.encode(result); - assertArrayEquals(AT_NONCE_S, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNotificationTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNotificationTest.java deleted file mode 100644 index 2db3cbb2..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtNotificationTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToInt; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtNotification.GENERAL_FAILURE_POST_CHALLENGE; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_NOTIFICATION; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NOTIFICATION; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NOTIFICATION_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_NOTIFICATION_INVALID_STATE; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.NOTIFICATION_CODE; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtNotification; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtNotificationTest { - private static final int EXPECTED_LENGTH = 4; - private static final int UNKNOWN_CODE = 0xA0FF; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NOTIFICATION); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtNotification); - AtNotification atNotification = (AtNotification) result; - assertEquals(EAP_AT_NOTIFICATION, atNotification.attributeType); - assertEquals(EXPECTED_LENGTH, atNotification.lengthInBytes); - assertTrue(atNotification.isSuccessCode); - assertFalse(atNotification.isPreSuccessfulChallenge); - assertEquals(hexStringToInt(NOTIFICATION_CODE), atNotification.notificationCode); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NOTIFICATION_INVALID_LENGTH); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid attribute length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecodeInvalidState() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_NOTIFICATION_INVALID_STATE); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid state"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtNotification atNotification = new AtNotification(hexStringToInt(NOTIFICATION_CODE)); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atNotification.encode(result); - assertArrayEquals(AT_NOTIFICATION, result.array()); - } - - @Test - public void testToString() throws Exception { - AtNotification knownCode = new AtNotification(GENERAL_FAILURE_POST_CHALLENGE); - AtNotification unknownCode = new AtNotification(UNKNOWN_CODE); - - assertNotNull(knownCode.toString()); - assertNotNull(unknownCode.toString()); - assertNotEquals(knownCode.toString(), unknownCode.toString()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtPaddingTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtPaddingTest.java deleted file mode 100644 index d310d504..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtPaddingTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_PADDING; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_PADDING; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_PADDING_INVALID_PADDING; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAtPaddingException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtPadding; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtPaddingTest { - private static final int EXPECTED_LENGTH = 8; - - private EapSimAkaAttributeFactory mAttributeFactory; - - @Before - public void setUp() { - mAttributeFactory = new EapSimAkaAttributeFactory() {}; - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_PADDING); - EapSimAkaAttribute result = mAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtPadding); - AtPadding atPadding = (AtPadding) result; - assertEquals(EAP_AT_PADDING, atPadding.attributeType); - assertEquals(EXPECTED_LENGTH, atPadding.lengthInBytes); - } - - @Test - public void testDecodeInvalidPadding() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_PADDING_INVALID_PADDING); - try { - mAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAtPaddingException for nonzero padding bytes"); - } catch (EapSimAkaInvalidAtPaddingException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtPadding atPadding = new AtPadding(EXPECTED_LENGTH); - - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - atPadding.encode(result); - - assertFalse(result.hasRemaining()); - assertArrayEquals(AT_PADDING, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandAkaTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandAkaTest.java deleted file mode 100644 index bdffdda9..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandAkaTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_RAND; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RAND_AKA; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RAND_AKA_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.RAND_1_BYTES; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtRandAka; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtRandAkaTest { - private EapAkaAttributeFactory mEapAkaAttributeFactory; - - @Before - public void setUp() { - mEapAkaAttributeFactory = EapAkaAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RAND_AKA); - EapSimAkaAttribute result = mEapAkaAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtRandAka atRandAka = (AtRandAka) result; - assertEquals(EAP_AT_RAND, atRandAka.attributeType); - assertEquals(AT_RAND_AKA.length, atRandAka.lengthInBytes); - assertArrayEquals(RAND_1_BYTES, atRandAka.rand); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RAND_AKA_INVALID_LENGTH); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtRandAka atRandAka = new AtRandAka(RAND_1_BYTES); - - ByteBuffer result = ByteBuffer.allocate(AT_RAND_AKA.length); - atRandAka.encode(result); - assertArrayEquals(AT_RAND_AKA, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandSimTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandSimTest.java deleted file mode 100644 index 7456be6c..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtRandSimTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToByteArray; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_RAND; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RAND_SIM; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RAND_SIM_DUPLICATE_RANDS; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RAND_SIM_INVALID_NUM_RANDS; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.RAND_1; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.RAND_2; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.exceptions.simaka.EapSimInvalidAtRandException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtRandSim; -import com.android.internal.net.eap.message.simaka.EapSimAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtRandSimTest { - private static final int EXPECTED_NUM_RANDS = 2; - - private EapSimAttributeFactory mEapSimAttributeFactory; - - @Before - public void setUp() { - mEapSimAttributeFactory = EapSimAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RAND_SIM); - EapSimAkaAttribute result = mEapSimAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtRandSim); - AtRandSim atRandSim = (AtRandSim) result; - assertEquals(EAP_AT_RAND, atRandSim.attributeType); - assertEquals(AT_RAND_SIM.length, atRandSim.lengthInBytes); - assertEquals(EXPECTED_NUM_RANDS, atRandSim.rands.size()); - assertArrayEquals(hexStringToByteArray(RAND_1), atRandSim.rands.get(0)); - assertArrayEquals(hexStringToByteArray(RAND_2), atRandSim.rands.get(1)); - } - - @Test - public void testDecodeInvalidNumRands() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RAND_SIM_INVALID_NUM_RANDS); - try { - mEapSimAttributeFactory.getAttribute(input); - fail("Expected EapSimInvalidAtRandException for invalid number of RANDs"); - } catch (EapSimInvalidAtRandException expected) { - } - } - - @Test - public void testDecodeDuplicateRands() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RAND_SIM_DUPLICATE_RANDS); - try { - mEapSimAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for duplicate RANDs"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - byte[][] expectedRands = new byte[][] { - hexStringToByteArray(RAND_1), - hexStringToByteArray(RAND_2) - }; - AtRandSim atRandSim = new AtRandSim(AT_RAND_SIM.length, expectedRands); - - ByteBuffer result = ByteBuffer.allocate(AT_RAND_SIM.length); - atRandSim.encode(result); - assertArrayEquals(AT_RAND_SIM, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtResTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtResTest.java deleted file mode 100644 index 34c2ff39..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtResTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_RES; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RES; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RES_INVALID_RES_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RES_LONG_RES; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_RES_SHORT_RES; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.RES_BYTES; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapAkaAttributeFactory; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtRes; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtResTest { - private EapAkaAttributeFactory mEapAkaAttributeFactory; - - @Before - public void setUp() { - mEapAkaAttributeFactory = EapAkaAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RES); - EapSimAkaAttribute result = mEapAkaAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - AtRes atRes = (AtRes) result; - assertEquals(EAP_AT_RES, atRes.attributeType); - assertEquals(AT_RES.length, atRes.lengthInBytes); - assertArrayEquals(RES_BYTES, atRes.res); - } - - @Test - public void testDecodeInvalidResLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RES_INVALID_RES_LENGTH); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid RES length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecodeShortResLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RES_SHORT_RES); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for too short RES"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testDecodeLongResLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_RES_LONG_RES); - try { - mEapAkaAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for too long RES"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtRes atRes = new AtRes(AT_RES.length, RES_BYTES); - - ByteBuffer result = ByteBuffer.allocate(AT_RES.length); - atRes.encode(result); - assertArrayEquals(AT_RES, result.array()); - } - - @Test - public void testGetAtRes() throws Exception { - AtRes atRes = AtRes.getAtRes(RES_BYTES); - - ByteBuffer result = ByteBuffer.allocate(AT_RES.length); - atRes.encode(result); - assertArrayEquals(AT_RES, result.array()); - } - - @Test - public void testIsValidResLen() { - // valid RES length: 4 <= RES length <= 16 - assertTrue(AtRes.isValidResLen(5)); - assertFalse(AtRes.isValidResLen(0)); - assertFalse(AtRes.isValidResLen(20)); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtSelectedVersionTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtSelectedVersionTest.java deleted file mode 100644 index 659fe9a8..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtSelectedVersionTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_SELECTED_VERSION; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_SELECTED_VERSION; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_SELECTED_VERSION_INVALID_LENGTH; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtSelectedVersion; -import com.android.internal.net.eap.message.simaka.EapSimAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class AtSelectedVersionTest { - private static final int EXPECTED_LENGTH = 4; - private static final int EXPECTED_VERSION = 1; - - private EapSimAttributeFactory mEapSimAttributeFactory; - - @Before - public void setUp() { - mEapSimAttributeFactory = EapSimAttributeFactory.getInstance(); - } - - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_SELECTED_VERSION); - EapSimAkaAttribute result = mEapSimAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtSelectedVersion); - AtSelectedVersion atSelectedVersion = (AtSelectedVersion) result; - assertEquals(EAP_AT_SELECTED_VERSION, atSelectedVersion.attributeType); - assertEquals(EXPECTED_LENGTH, atSelectedVersion.lengthInBytes); - assertEquals(EXPECTED_VERSION, atSelectedVersion.selectedVersion); - } - - @Test - public void testDecodeInvalidLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_SELECTED_VERSION_INVALID_LENGTH); - try { - mEapSimAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid actual list length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtSelectedVersion atSelectedVersion = new AtSelectedVersion( - EXPECTED_LENGTH, EXPECTED_VERSION); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atSelectedVersion.encode(result); - assertArrayEquals(AT_SELECTED_VERSION, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtVersionListTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtVersionListTest.java deleted file mode 100644 index 96bb7ca3..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/AtVersionListTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToInt; -import static com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.EAP_AT_VERSION_LIST; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_VERSION_LIST; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.AT_VERSION_LIST_INVALID_LENGTH; -import static com.android.internal.net.eap.message.simaka.attributes.EapTestAttributeDefinitions.VERSION; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.android.internal.net.eap.exceptions.simaka.EapSimAkaInvalidAttributeException; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtVersionList; -import com.android.internal.net.eap.message.simaka.EapSimAttributeFactory; - -import org.junit.Before; -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.List; - -public class AtVersionListTest { - private static final int EXPECTED_LENGTH = 8; - private static final List<Integer> EXPECTED_VERSIONS = Arrays.asList(1); - - private EapSimAttributeFactory mEapSimAttributeFactory; - - @Before - public void setUp() { - mEapSimAttributeFactory = EapSimAttributeFactory.getInstance(); - } - - @Test - public void testDecode() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_VERSION_LIST); - EapSimAkaAttribute result = mEapSimAttributeFactory.getAttribute(input); - - assertFalse(input.hasRemaining()); - assertTrue(result instanceof AtVersionList); - AtVersionList atVersionList = (AtVersionList) result; - assertEquals(EAP_AT_VERSION_LIST, atVersionList.attributeType); - assertEquals(EXPECTED_LENGTH, atVersionList.lengthInBytes); - assertEquals(EXPECTED_VERSIONS, atVersionList.versions); - } - - @Test - public void testDecodeInvalidActualLength() throws Exception { - ByteBuffer input = ByteBuffer.wrap(AT_VERSION_LIST_INVALID_LENGTH); - try { - mEapSimAttributeFactory.getAttribute(input); - fail("Expected EapSimAkaInvalidAttributeException for invalid actual list length"); - } catch (EapSimAkaInvalidAttributeException expected) { - } - } - - @Test - public void testEncode() throws Exception { - AtVersionList atVersionList = new AtVersionList(EXPECTED_LENGTH, hexStringToInt(VERSION)); - ByteBuffer result = ByteBuffer.allocate(EXPECTED_LENGTH); - - atVersionList.encode(result); - assertArrayEquals(AT_VERSION_LIST, result.array()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapSimAkaAttributeTest.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapSimAkaAttributeTest.java deleted file mode 100644 index 98ea222c..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapSimAkaAttributeTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertFalse; - -import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute; - -import org.junit.Test; - -import java.nio.ByteBuffer; - -public class EapSimAkaAttributeTest { - private static final int EXPECTED_ATTRIBUTE_TYPE = 1; - private static final int EXPECTED_LENGTH_IN_BYTES = 4; - private static final int BUFFER_LENGTH = 2; - private static final int EXPECTED_LENGTH_ENCODED = 1; - private static final byte[] EXPECTED_ENCODING = { - (byte) EXPECTED_ATTRIBUTE_TYPE, - (byte) EXPECTED_LENGTH_ENCODED - }; - - @Test - public void testEncode() throws Exception { - EapSimAkaAttribute eapSimAkaAttribute = new EapSimAkaAttribute( - EXPECTED_ATTRIBUTE_TYPE, - EXPECTED_LENGTH_IN_BYTES) { - public void encode(ByteBuffer byteBuffer) { - encodeAttributeHeader(byteBuffer); - } - }; - - ByteBuffer result = ByteBuffer.allocate(BUFFER_LENGTH); - eapSimAkaAttribute.encode(result); - assertArrayEquals(EXPECTED_ENCODING, result.array()); - assertFalse(result.hasRemaining()); - } -} diff --git a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapTestAttributeDefinitions.java b/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapTestAttributeDefinitions.java deleted file mode 100644 index 60397e1f..00000000 --- a/tests/iketests/src/java/com/android/internal/net/eap/message/simaka/attributes/EapTestAttributeDefinitions.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.internal.net.eap.message.simaka.attributes; - -import static com.android.internal.net.TestUtils.hexStringToByteArray; - -/** - * EapTestAttributeDefinitions provides byte[] encodings of commonly used EAP Messages. - * - * @ee <a href="https://tools.ietf.org/html/rfc4186#section-10">RFC 4186, EAP-SIM Authentication, - * Section 10</a> - * @see <a href="https://tools.ietf.org/html/rfc4187#section-10">RFC 4187, EAP-AKA Authentication, - * Section 10</a> - */ -public class EapTestAttributeDefinitions { - public static final String VERSION = "0001"; - public static final String AT_VERSION_LIST_DATA = "0002" + VERSION + "0000"; - public static final byte[] AT_VERSION_LIST = - hexStringToByteArray("0F02" + AT_VERSION_LIST_DATA); - public static final byte[] AT_SELECTED_VERSION = hexStringToByteArray("10010001"); - public static final String NONCE_MT_STRING = "0123456789ABCDEFFEDCBA9876543210"; - public static final byte[] NONCE_MT = hexStringToByteArray(NONCE_MT_STRING); - public static final byte[] AT_NONCE_MT = hexStringToByteArray("07050000" + NONCE_MT_STRING); - public static final byte[] AT_PERMANENT_ID_REQ = hexStringToByteArray("0A010000"); - public static final byte[] AT_ANY_ID_REQ = hexStringToByteArray("0D010000"); - public static final byte[] AT_FULL_AUTH_ID_REQ = hexStringToByteArray("11010000"); - - // Identity = "test1@android.net" - public static final String IDENTITY_STRING = "746573743140616E64726F69642E6E6574"; - public static final byte[] IDENTITY = hexStringToByteArray(IDENTITY_STRING); - public static final byte[] AT_IDENTITY = - hexStringToByteArray("0E060011" + IDENTITY_STRING + "000000"); - public static final String RAND_1 = "00112233445566778899AABBCCDDEEFF"; - public static final byte[] RAND_1_BYTES = hexStringToByteArray(RAND_1); - public static final String RAND_2 = "FFEEDDCCBBAA99887766554433221100"; - public static final byte[] RAND_2_BYTES = hexStringToByteArray(RAND_2); - public static final byte[] AT_RAND_SIM = hexStringToByteArray("01090000" + RAND_1 + RAND_2); - public static final byte[] AT_RAND_AKA = hexStringToByteArray("01050000" + RAND_1); - public static final byte[] AT_PADDING = hexStringToByteArray("0602000000000000"); - public static final String MAC = "112233445566778899AABBCCDDEEFF11"; - public static final byte[] MAC_BYTES = hexStringToByteArray(MAC); - public static final byte[] AT_MAC = hexStringToByteArray("0B050000" + MAC); - public static final String COUNTER = "000A"; - public static final int COUNTER_INT = Integer.parseInt(COUNTER, 16 /* radix */); - public static final byte[] AT_COUNTER = hexStringToByteArray("1301" + COUNTER); - public static final byte[] AT_COUNTER_TOO_SMALL = hexStringToByteArray("14010000"); - public static final String NONCE_S = "0123456789ABCDEFFEDCBA9876543210"; - public static final byte[] AT_NONCE_S = hexStringToByteArray("15050000" + NONCE_S); - public static final String NOTIFICATION_CODE = "8000"; - public static final byte[] AT_NOTIFICATION = hexStringToByteArray("0C01" + NOTIFICATION_CODE); - public static final String ERROR_CODE = "0001"; - public static final byte[] AT_CLIENT_ERROR_CODE = hexStringToByteArray("1601" + ERROR_CODE); - public static final String AUTN = "0123456789ABCDEFFEDCBA9876543210"; - public static final byte[] AUTN_BYTES = hexStringToByteArray(AUTN); - public static final byte[] AT_AUTN = hexStringToByteArray("02050000" + AUTN); - public static final String RES = "1122334455"; - public static final byte[] RES_BYTES = hexStringToByteArray(RES); - public static final byte[] AT_RES = hexStringToByteArray("03030028" + RES + "000000"); - public static final String AUTS = "112233445566778899AABBCCDDEE"; - public static final byte[] AUTS_BYTES = hexStringToByteArray(AUTS); - public static final byte[] AT_AUTS = hexStringToByteArray("0404" + AUTS); - public static final byte[] AT_BIDDING_SUPPORTS_AKA_PRIME = hexStringToByteArray("88018000"); - public static final byte[] AT_BIDDING_DOES_NOT_SUPPORT_AKA_PRIME = - hexStringToByteArray("88010000"); - - // Network Name = "android.net" - public static final String NETWORK_NAME_HEX = "616E64726F69642E6E6574"; - public static final byte[] NETWORK_NAME_BYTES = hexStringToByteArray(NETWORK_NAME_HEX); - public static final byte[] AT_KDF_INPUT = - hexStringToByteArray("1704000B" + NETWORK_NAME_HEX + "00"); - public static final byte[] AT_KDF_INPUT_EMPTY_NETWORK_NAME = hexStringToByteArray("17010000"); - public static final int KDF_VERSION = 1; - public static final byte[] AT_KDF = hexStringToByteArray("18010001"); - - public static final byte[] AT_VERSION_LIST_INVALID_LENGTH = hexStringToByteArray("0F020003"); - public static final byte[] AT_SELECTED_VERSION_INVALID_LENGTH = - hexStringToByteArray("10020001"); - public static final byte[] AT_NONCE_INVALID_LENGTH = - hexStringToByteArray("07060000" + NONCE_MT_STRING); - public static final byte[] PERMANENT_ID_INVALID_LENGTH = hexStringToByteArray("0A020000"); - public static final byte[] ANY_ID_INVALID_LENGTH = hexStringToByteArray("0D020000"); - public static final byte[] FULL_AUTH_ID_INVALID_LENGTH = hexStringToByteArray("11020000"); - public static final byte[] AT_RAND_SIM_INVALID_NUM_RANDS = - hexStringToByteArray("01050000" + RAND_1); - public static final byte[] AT_RAND_SIM_DUPLICATE_RANDS = - hexStringToByteArray("01090000" + RAND_1 + RAND_1); - public static final byte[] AT_RAND_AKA_INVALID_LENGTH = hexStringToByteArray("01010000"); - public static final byte[] AT_PADDING_INVALID_PADDING = hexStringToByteArray("0601FFFF"); - public static final byte[] AT_MAC_INVALID_LENGTH = hexStringToByteArray("0B06"); - public static final byte[] AT_COUNTER_INVALID_LENGTH = hexStringToByteArray("1302"); - public static final byte[] AT_COUNTER_TOO_SMALL_INVALID_LENGTH = hexStringToByteArray("1402"); - public static final byte[] AT_NONCE_S_INVALID_LENGTH = hexStringToByteArray("1506"); - public static final byte[] AT_NOTIFICATION_INVALID_LENGTH = hexStringToByteArray("0C02"); - public static final byte[] AT_NOTIFICATION_INVALID_STATE = hexStringToByteArray("0C01C000"); - public static final byte[] AT_CLIENT_ERROR_CODE_INVALID_LENGTH = hexStringToByteArray("1602"); - public static final byte[] AT_AUTN_INVALID_LENGTH = hexStringToByteArray("02010000"); - public static final byte[] AT_RES_INVALID_RES_LENGTH = - hexStringToByteArray("030300241122334450000000"); - public static final byte[] AT_RES_SHORT_RES = - hexStringToByteArray("0302000811000000"); - public static final byte[] AT_RES_LONG_RES = - hexStringToByteArray("0306008800112233445566778899AABBCCDDEEFF11000000"); - public static final byte[] AT_AUTS_INVALID_LENGTH = hexStringToByteArray("03010000"); - public static final byte[] AT_KDF_INVALID_LENGTH = hexStringToByteArray("18020001"); - public static final byte[] AT_BIDDING_INVALID_LENGTH = hexStringToByteArray("88020000"); -} |