summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java43
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/ExchangeCompleteMessageTest.java65
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/UpdateResponseMessageTest.java91
3 files changed, 197 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
index 4b5a822d3..2214d53d3 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
@@ -50,8 +50,10 @@ import android.telephony.TelephonyManager;
import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.org.conscrypt.TrustManagerImpl;
import com.android.server.wifi.WifiNative;
+import com.android.server.wifi.hotspot2.soap.ExchangeCompleteMessage;
import com.android.server.wifi.hotspot2.soap.PostDevDataResponse;
import com.android.server.wifi.hotspot2.soap.RedirectListener;
+import com.android.server.wifi.hotspot2.soap.SppConstants;
import com.android.server.wifi.hotspot2.soap.SppResponseMessage;
import com.android.server.wifi.hotspot2.soap.command.BrowserUri;
import com.android.server.wifi.hotspot2.soap.command.PpsMoData;
@@ -83,6 +85,7 @@ public class PasspointProvisionerTest {
private static final int STEP_SERVER_CONNECT = 2;
private static final int STEP_WAIT_FOR_REDIRECT_RESPONSE = 3;
private static final int STEP_WAIT_FOR_SECOND_SOAP_RESPONSE = 4;
+ private static final int STEP_WAIT_FOR_THIRD_SOAP_RESPONSE = 5;
private static final String TEST_DEV_ID = "12312341";
private static final String TEST_MANUFACTURER = Build.MANUFACTURER;
@@ -130,6 +133,7 @@ public class PasspointProvisionerTest {
@Mock SSLContext mTlsContext;
@Mock WifiNative mWifiNative;
@Mock PostDevDataResponse mSppResponseMessage;
+ @Mock ExchangeCompleteMessage mExchangeCompleteMessage;
@Mock SystemInfo mSystemInfo;
@Mock TelephonyManager mTelephonyManager;
@Mock SppCommand mSppCommand;
@@ -184,6 +188,12 @@ public class PasspointProvisionerTest {
when(mSystemInfo.getFirmwareVersion()).thenReturn(TEST_FW_VERSION);
when(mTelephonyManager.getSubscriberId()).thenReturn(TEST_IMSI);
+ when(mExchangeCompleteMessage.getMessageType()).thenReturn(
+ SppResponseMessage.MessageType.EXCHANGE_COMPLETE);
+ when(mExchangeCompleteMessage.getStatus()).thenReturn(
+ SppConstants.SppStatus.EXCHANGE_COMPLETE);
+ when(mExchangeCompleteMessage.getSessionID()).thenReturn(TEST_SESSION_ID);
+ when(mExchangeCompleteMessage.getError()).thenReturn(SppConstants.INVALID_SPP_CONSTANT);
when(mSppResponseMessage.getMessageType()).thenReturn(
SppResponseMessage.MessageType.POST_DEV_DATA_RESPONSE);
when(mSppResponseMessage.getSppCommand()).thenReturn(mSppCommand);
@@ -291,7 +301,14 @@ public class PasspointProvisionerTest {
mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(),
mSppResponseMessage);
mLooper.dispatchAll();
+ } else if (step == STEP_WAIT_FOR_THIRD_SOAP_RESPONSE) {
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_THIRD_SOAP_EXCHANGE);
+ // Received a third soapMessageResponse
+ mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(),
+ mExchangeCompleteMessage);
+ mLooper.dispatchAll();
}
}
}
@@ -581,7 +598,7 @@ public class PasspointProvisionerTest {
/**
* Verifies that the right provisioning callbacks are invoked when a command of a second soap
- * response is not for ADD MO command.
+ * response {@link PostDevDataResponse} is not for ADD MO command.
*/
@Test
public void verifyNotAddMoCommandFailureForSecondSoapResponse() throws RemoteException {
@@ -607,12 +624,34 @@ public class PasspointProvisionerTest {
}
/**
+ * Verifies that the right provisioning callbacks are invoked when a message of a third soap
+ * response {@link ExchangeCompleteMessage} has an error property.
+ */
+ @Test
+ public void verifyHandlingErrorPropertyInThirdSoapResponse() throws RemoteException {
+ when(mExchangeCompleteMessage.getError()).thenReturn(
+ SppConstants.SppError.PROVISIONING_FAILED);
+ stopAfterStep(STEP_WAIT_FOR_SECOND_SOAP_RESPONSE);
+
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_THIRD_SOAP_EXCHANGE);
+
+ // Received a third soapMessageResponse
+ mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(),
+ mExchangeCompleteMessage);
+ mLooper.dispatchAll();
+
+ verify(mCallback).onProvisioningFailure(
+ ProvisioningCallback.OSU_FAILURE_PROVISIONING_ABORTED);
+ }
+
+ /**
* Verifies that the right provisioning callbacks are invoked as the provisioner progresses
* to the end as successful case.
*/
@Test
public void verifyProvisioningFlowForSuccessfulCase() throws RemoteException {
- stopAfterStep(STEP_WAIT_FOR_SECOND_SOAP_RESPONSE);
+ stopAfterStep(STEP_WAIT_FOR_THIRD_SOAP_RESPONSE);
// No further runnables posted
verifyNoMoreInteractions(mCallback);
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/ExchangeCompleteMessageTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/ExchangeCompleteMessageTest.java
new file mode 100644
index 000000000..dcddb5380
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/ExchangeCompleteMessageTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2018 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.server.wifi.hotspot2.soap;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import android.support.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.ksoap2.serialization.SoapObject;
+
+/**
+ * Unit tests for {@link ExchangeCompleteMessage}.
+ */
+@SmallTest
+public class ExchangeCompleteMessageTest {
+ private static final String TEST_STATUS = "OK";
+ private static final String TEST_SESSION_ID = "D215D696517BA138F1D28442DF0F4E07";
+ private static final String TEST_VERSION = "1.0";
+
+ private ExchangeCompleteMessage mExchangeCompleteMessage;
+
+ /**
+ * Verify if the ExchangeCompleteMessage message is properly parsed.
+ */
+ @Test
+ public void verifyValidExchangeComplete() {
+ SoapObject response = new SoapObject();
+ response.addAttribute(SppResponseMessage.SPPStatusAttribute, TEST_STATUS);
+ response.addAttribute(SppResponseMessage.SPPSessionIDAttribute, TEST_SESSION_ID);
+ response.addAttribute(SppResponseMessage.SPPVersionAttribute, TEST_VERSION);
+
+ mExchangeCompleteMessage = ExchangeCompleteMessage.createInstance(response);
+
+ assertNotNull(mExchangeCompleteMessage);
+ }
+
+ /**
+ * Verify if the exchangeComplete message missing session id will return {@code null}
+ */
+ @Test
+ public void verifyInvalidExchangeCompleteReturnNull() {
+ SoapObject response = new SoapObject();
+ response.addAttribute(SppResponseMessage.SPPStatusAttribute, TEST_STATUS);
+ response.addAttribute(SppResponseMessage.SPPVersionAttribute, TEST_VERSION);
+ mExchangeCompleteMessage = ExchangeCompleteMessage.createInstance(response);
+
+ assertNull(mExchangeCompleteMessage);
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/UpdateResponseMessageTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/UpdateResponseMessageTest.java
new file mode 100644
index 000000000..edda5273e
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/UpdateResponseMessageTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 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.server.wifi.hotspot2.soap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.support.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.ksoap2.SoapEnvelope;
+import org.ksoap2.serialization.SoapObject;
+import org.ksoap2.serialization.SoapSerializationEnvelope;
+
+/**
+ * Unit tests for {@link UpdateResponseMessage}.
+ */
+@SmallTest
+public class UpdateResponseMessageTest {
+ private static final String TEST_SESSION_ID = "123456";
+
+ /**
+ * Verify the request is organized correctly with a session id.
+ */
+ @Test
+ public void serializeUpdateResponseMessageWithSessionIdWithoutError() {
+ SoapSerializationEnvelope request = UpdateResponseMessage.serializeToSoapEnvelope(
+ TEST_SESSION_ID, false);
+ assertNotNull(request);
+ assertEquals(SoapEnvelope.VER12, request.version);
+ SoapObject soapRequest = (SoapObject) request.bodyOut;
+ verifyCommonFields(soapRequest);
+
+ // Should have an OK status attribute
+ assertEquals(SppConstants.mapStatusIntToString(SppConstants.SppStatus.OK),
+ soapRequest.getAttributeAsString(SoapEnvelope.NS20,
+ SppConstants.ATTRIBUTE_SPP_STATUS));
+ }
+
+ /**
+ * Verify the request is organized correctly with a session id and an error.
+ */
+ @Test
+ public void serializeUpdateResponseMessageWithError() {
+ SoapSerializationEnvelope request = UpdateResponseMessage.serializeToSoapEnvelope(
+ TEST_SESSION_ID, true);
+ assertNotNull(request);
+ assertEquals(SoapEnvelope.VER12, request.version);
+ SoapObject soapRequest = (SoapObject) request.bodyOut;
+ verifyCommonFields(soapRequest);
+
+ // Should have an error status attribute
+ assertEquals(SppConstants.mapStatusIntToString(SppConstants.SppStatus.ERROR),
+ soapRequest.getAttributeAsString(SoapEnvelope.NS20,
+ SppConstants.ATTRIBUTE_SPP_STATUS));
+ assertEquals(1, soapRequest.getPropertyCount());
+
+ SoapObject sppError = (SoapObject) soapRequest.getProperty(0);
+ assertNotNull(sppError);
+ assertEquals(sppError.getNamespace(), SoapEnvelope.NS20);
+ assertEquals(
+ SppConstants.mapErrorIntToString(SppConstants.SppError.MO_ADD_OR_UPDATE_FAILED),
+ sppError.getAttributeAsString(SppConstants.ATTRIBUTE_ERROR_CODE));
+ }
+
+ private void verifyCommonFields(SoapObject request) {
+ assertEquals(request.getNamespace(), SoapEnvelope.NS20);
+ assertEquals(request.getName(), SppConstants.METHOD_UPDATE_RESPONSE);
+ assertEquals(SppConstants.SUPPORTED_SPP_VERSION,
+ request.getAttributeAsString(SoapEnvelope.NS20,
+ SppConstants.ATTRIBUTE_SPP_VERSION));
+
+ // Should have a session id attribute
+ assertEquals(TEST_SESSION_ID, request.getAttributeAsString(SoapEnvelope.NS20,
+ SppConstants.ATTRIBUTE_SESSION_ID));
+ }
+}