diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-10-05 19:38:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-10-05 19:38:42 +0000 |
commit | 574dad6518cec201bab9cee3942995094e4a6b40 (patch) | |
tree | a78aae9c5f86ed8429f62e5f614b8b0ef2ca2739 /tests | |
parent | 8ef190b8523924a392fabb5d1cc5a880908a9a3a (diff) | |
parent | 63d022cb4aae028e21902cc6839875bc8c091aca (diff) |
Merge "passpoint-r2: sending a second SOAP message and receiving a response"
Diffstat (limited to 'tests')
3 files changed, 173 insertions, 12 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java index 8a123c2f2..f0a72efce 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java @@ -305,20 +305,16 @@ public class OsuServerConnectionTest { public void verifyExchangeSoapMessage() { // static mocking MockitoSession session = ExtendedMockito.mockitoSession().mockStatic( - HttpsTransport.class).startMocking(); + HttpsTransport.class).mockStatic(SoapParser.class).startMocking(); try { mOsuServerConnection.init(mTlsContext, mDelegate); mOsuServerConnection.setEventCallback(mOsuServerCallbacks); - when(HttpsTransport.createInstance(any(Network.class), any(URL.class))).thenReturn( - mHttpsTransport); assertTrue(mOsuServerConnection.connect(mValidServerUrl, mNetwork)); - session.finishMocking(); - // new static mocking - session = ExtendedMockito.mockitoSession().mockStatic( - SoapParser.class).startMocking(); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); envelope.bodyIn = new SoapObject(); + when(HttpsTransport.createInstance(any(Network.class), any(URL.class))).thenReturn( + mHttpsTransport); when(SoapParser.getResponse(any(SoapObject.class))).thenReturn(mSppResponseMessage); assertTrue(mOsuServerConnection.exchangeSoapMessage(envelope)); 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 5e73cd652..4b5a822d3 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java @@ -54,6 +54,7 @@ import com.android.server.wifi.hotspot2.soap.PostDevDataResponse; import com.android.server.wifi.hotspot2.soap.RedirectListener; 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; import com.android.server.wifi.hotspot2.soap.command.SppCommand; import org.junit.After; @@ -81,6 +82,7 @@ public class PasspointProvisionerTest { private static final int STEP_AP_CONNECT = 1; 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 String TEST_DEV_ID = "12312341"; private static final String TEST_MANUFACTURER = Build.MANUFACTURER; @@ -132,6 +134,7 @@ public class PasspointProvisionerTest { @Mock TelephonyManager mTelephonyManager; @Mock SppCommand mSppCommand; @Mock BrowserUri mBrowserUri; + @Mock PpsMoData mPpsMoData; @Mock RedirectListener mRedirectListener; @Mock PackageManager mPackageManager; @@ -185,6 +188,7 @@ public class PasspointProvisionerTest { SppResponseMessage.MessageType.POST_DEV_DATA_RESPONSE); when(mSppResponseMessage.getSppCommand()).thenReturn(mSppCommand); when(mSppResponseMessage.getSessionID()).thenReturn(TEST_SESSION_ID); + when(mSppCommand.getSppCommandId()).thenReturn(SppCommand.CommandId.EXEC); when(mSppCommand.getExecCommandId()).thenReturn(SppCommand.ExecCommandId.BROWSER); when(mSppCommand.getCommandData()).thenReturn(mBrowserUri); when(mBrowserUri.getUri()).thenReturn(TEST_URL); @@ -257,7 +261,7 @@ public class PasspointProvisionerTest { verify(mCallback).onProvisioningStatus( ProvisioningCallback.OSU_STATUS_INIT_SOAP_EXCHANGE); - // Received soapMessageResponse + // Received a first soapMessageResponse mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(), mSppResponseMessage); mLooper.dispatchAll(); @@ -268,6 +272,26 @@ public class PasspointProvisionerTest { .startServer(mOnRedirectReceivedArgumentCaptor.capture()); mRedirectReceivedListener = mOnRedirectReceivedArgumentCaptor.getValue(); verifyNoMoreInteractions(mCallback); + } else if (step == STEP_WAIT_FOR_SECOND_SOAP_RESPONSE) { + when(mSppCommand.getSppCommandId()).thenReturn(SppCommand.CommandId.ADD_MO); + when(mSppCommand.getExecCommandId()).thenReturn(-1); + when(mSppCommand.getCommandData()).thenReturn(mPpsMoData); + + // Received HTTP redirect response. + mRedirectReceivedListener.onRedirectReceived(); + mLooper.dispatchAll(); + + verify(mRedirectListener, atLeastOnce()).stopServer(); + verify(mCallback).onProvisioningStatus( + ProvisioningCallback.OSU_STATUS_REDIRECT_RESPONSE_RECEIVED); + verify(mCallback).onProvisioningStatus( + ProvisioningCallback.OSU_STATUS_SECOND_SOAP_EXCHANGE); + + // Received a second soapMessageResponse + mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(), + mSppResponseMessage); + mLooper.dispatchAll(); + } } } @@ -556,11 +580,11 @@ public class PasspointProvisionerTest { } /** - * Verifies that the right provisioning callbacks are invoked as the provisioner progresses - * to the end as successful case. + * Verifies that the right provisioning callbacks are invoked when a command of a second soap + * response is not for ADD MO command. */ @Test - public void verifyProvisioningFlowForSuccessfulCase() throws RemoteException { + public void verifyNotAddMoCommandFailureForSecondSoapResponse() throws RemoteException { stopAfterStep(STEP_WAIT_FOR_REDIRECT_RESPONSE); // Received HTTP redirect response. @@ -570,7 +594,27 @@ public class PasspointProvisionerTest { verify(mRedirectListener, atLeastOnce()).stopServer(); verify(mCallback).onProvisioningStatus( ProvisioningCallback.OSU_STATUS_REDIRECT_RESPONSE_RECEIVED); - // No further runnables posted + verify(mCallback).onProvisioningStatus( + ProvisioningCallback.OSU_STATUS_SECOND_SOAP_EXCHANGE); + + // Received a second soapMessageResponse + mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(), + mSppResponseMessage); + mLooper.dispatchAll(); + + verify(mCallback).onProvisioningFailure( + ProvisioningCallback.OSU_FAILURE_UNEXPECTED_COMMAND_TYPE); + } + + /** + * 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); + + // No further runnables posted verifyNoMoreInteractions(mCallback); } } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/command/PpsMoDataTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/command/PpsMoDataTest.java new file mode 100644 index 000000000..e4f2a1521 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/command/PpsMoDataTest.java @@ -0,0 +1,121 @@ +/* + * 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.command; + +import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ADD_MO_COMMAND; +import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ATTRIBUTE_MANAGEMENT_TREE_URI; +import static com.android.server.wifi.hotspot2.soap.command.PpsMoData.ATTRIBUTE_MO_URN; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.MockitoAnnotations.initMocks; + +import android.support.test.filters.SmallTest; + +import org.junit.Before; +import org.junit.Test; +import org.ksoap2.serialization.PropertyInfo; +import org.ksoap2.serialization.SoapPrimitive; + +/** + * Unit tests for {@link PpsMoData}. + */ +@SmallTest +public class PpsMoDataTest { + private static final String TEST_PPS_MO_XML = "<MgmtTree>test</MgmtTree>"; + private static final String TEST_TREE_URI = "testTreeURI"; + private static final String TEST_MO_URN = "testMoURN"; + + /** + * Sets up test. + */ + @Before + public void setUp() throws Exception { + initMocks(this); + } + + /** + * Verify if a message is valid format, it will return a PPS MO XML. + */ + @Test + public void verifyGetPpsMo() { + PropertyInfo propertyInfo = new PropertyInfo(); + propertyInfo.setName(ADD_MO_COMMAND); + SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML); + soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI); + soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN); + propertyInfo.setValue(soapPrimitive); + + assertEquals(TEST_PPS_MO_XML, PpsMoData.createInstance(propertyInfo).getPpsMoTree()); + } + + /** + * Verify if a message does not have PPS MO XML, it will return {@code null}. + */ + @Test + public void verifyMissingPpsMoReturnNull() { + PropertyInfo propertyInfo = new PropertyInfo(); + propertyInfo.setName(ADD_MO_COMMAND); + SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML); + soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI); + soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN); + propertyInfo.setValue(null); + + assertNull(PpsMoData.createInstance(propertyInfo)); + } + + /** + * Verify if a message is missing {@link PpsMoData#ATTRIBUTE_MANAGEMENT_TREE_URI}, it will + * return {@code null}. + */ + @Test + public void verifyMissingTreeURIAttributeReturnNull() { + PropertyInfo propertyInfo = new PropertyInfo(); + propertyInfo.setName(ADD_MO_COMMAND); + SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML); + soapPrimitive.addAttribute(ATTRIBUTE_MO_URN, TEST_MO_URN); + propertyInfo.setValue(soapPrimitive); + + assertNull(PpsMoData.createInstance(propertyInfo)); + } + + /** + * Verify if a message is missing {@link PpsMoData#ATTRIBUTE_MO_URN}, it will return + * {@code null}. + */ + @Test + public void verifyMissingMoUrnAttributeReturnNull() { + PropertyInfo propertyInfo = new PropertyInfo(); + propertyInfo.setName(ADD_MO_COMMAND); + SoapPrimitive soapPrimitive = new SoapPrimitive("namespace", "name", TEST_PPS_MO_XML); + soapPrimitive.addAttribute(ATTRIBUTE_MANAGEMENT_TREE_URI, TEST_TREE_URI); + propertyInfo.setValue(soapPrimitive); + + assertNull(PpsMoData.createInstance(propertyInfo)); + } + + /** + * Verify if a message that is not for addMO command, it will return {@code null}. + */ + @Test + public void verifyNonAddMoCommandMessageReturnNull() { + PropertyInfo propertyInfo = new PropertyInfo(); + propertyInfo.setName("InvalidCommand"); + + assertNull(PpsMoData.createInstance(propertyInfo)); + } +} |