summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorEcco Park <eccopark@google.com>2018-08-14 14:23:02 -0700
committerEcco Park <eccopark@google.com>2018-08-18 19:13:11 -0700
commitda0f648ec6f7f97e7da9fb31f318eed3c7bcf233 (patch)
tree427d30ccc67f4c63fa84c518c2395eb662d4eb99 /service
parent7628196f455d9f550af603879692a7aea34d9555 (diff)
passpoint-r2: re-enable unit test for OsuServerConnection class
The unit test for OsuServerConnetion was disabled from pi-dev because old mockito(mockito-target) doesn't support mocking the final class. 1) re-enable unit-test for OsuServerConnection as new mockito version(mockito-target-extended) has been enabled on master. 2) mock static methods and final class 3) add test cases for exchangeSoapMessage function Bug: 112206665 Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: Ibce348ea597d695b86612c6418d9fe48941050eb Signed-off-by: Ecco Park <eccopark@google.com>
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/hotspot2/OsuServerConnection.java25
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java2
-rw-r--r--service/java/com/android/server/wifi/hotspot2/soap/HttpsTransport.java13
3 files changed, 22 insertions, 18 deletions
diff --git a/service/java/com/android/server/wifi/hotspot2/OsuServerConnection.java b/service/java/com/android/server/wifi/hotspot2/OsuServerConnection.java
index f0a114186..ca05cd017 100644
--- a/service/java/com/android/server/wifi/hotspot2/OsuServerConnection.java
+++ b/service/java/com/android/server/wifi/hotspot2/OsuServerConnection.java
@@ -137,6 +137,7 @@ public class OsuServerConnection {
return false;
}
mUrlConnection = urlConnection;
+ mHttpsTransport = HttpsTransport.createInstance(network, url);
return true;
}
@@ -161,6 +162,7 @@ public class OsuServerConnection {
for (Pair<Locale, String> identity : ASN1SubjectAltNamesParser.getProviderNames(
mTrustManager.getProviderCert())) {
if (identity.first == null) continue;
+
// Compare the language code for ISO-639.
if (identity.first.getISO3Language().equals(locale.getISO3Language()) &&
TextUtils.equals(identity.second, friendlyName)) {
@@ -177,20 +179,20 @@ public class OsuServerConnection {
/**
* The helper method to exchange a SOAP message.
*
- * @param url server's URL
* @param soapEnvelope the soap message to be sent.
* @return {@link SppResponseMessage} parsed, {@code null} in any failure
*/
- public SppResponseMessage exchangeSoapMessage(@NonNull URL url,
- @NonNull SoapSerializationEnvelope soapEnvelope) {
+ public SppResponseMessage exchangeSoapMessage(@NonNull SoapSerializationEnvelope soapEnvelope) {
if (mNetwork == null) {
Log.e(TAG, "Network is not established");
return null;
}
+
if (soapEnvelope == null) {
Log.e(TAG, "soapEnvelope is null");
return null;
}
+
if (mUrlConnection == null) {
Log.e(TAG, "Server certificate is not validated");
return null;
@@ -200,15 +202,13 @@ public class OsuServerConnection {
mServiceConnection.disconnect();
}
- mServiceConnection = getServiceConnection(url, mNetwork);
+ mServiceConnection = getServiceConnection();
if (mServiceConnection == null) {
Log.e(TAG, "ServiceConnection for https is null");
return null;
}
- mUrl = url;
- SppResponseMessage sppResponse = null;
-
+ SppResponseMessage sppResponse;
try {
// Sending the SOAP message
mHttpsTransport.call("", soapEnvelope);
@@ -221,7 +221,6 @@ public class OsuServerConnection {
Log.e(TAG, "Not a SoapObject instance");
return null;
}
-
SoapObject soapResponse = (SoapObject) response;
if (mVerboseLoggingEnabled) {
for (int i = 0; i < soapResponse.getAttributeCount(); i++) {
@@ -231,9 +230,9 @@ public class OsuServerConnection {
}
Log.v(TAG, "response : " + soapResponse.toString());
}
+
// Get the parsed SOAP SPP Response message
sppResponse = SoapParser.getResponse(soapResponse);
-
} catch (Exception e) {
if (e instanceof SSLHandshakeException) {
Log.e(TAG, "Failed to make TLS connection");
@@ -245,23 +244,17 @@ public class OsuServerConnection {
mServiceConnection.disconnect();
mServiceConnection = null;
}
-
return sppResponse;
}
/**
* Get the HTTPS service connection used for SOAP message exchange.
*
- * @param url target address that the device connect to
- * @param network {@link Network} for current wifi connection
* @return {@link HttpsServiceConnection}
*/
- private HttpsServiceConnection getServiceConnection(@NonNull URL url,
- @NonNull Network network) {
+ private HttpsServiceConnection getServiceConnection() {
HttpsServiceConnection serviceConnection;
-
try {
- mHttpsTransport = new HttpsTransport(network, url);
serviceConnection = (HttpsServiceConnection) mHttpsTransport.getServiceConnection();
if (serviceConnection != null) {
serviceConnection.setSSLSocketFactory(mSocketFactory);
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java
index d4ea894be..0c8a6a72e 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvisioner.java
@@ -316,7 +316,7 @@ public class PasspointProvisioner {
}
// Sending the first sppPostDevDataRequest message.
- SppResponseMessage sppResponse = mOsuServerConnection.exchangeSoapMessage(mServerUrl,
+ SppResponseMessage sppResponse = mOsuServerConnection.exchangeSoapMessage(
PostDevDataMessage.serializeToSoapEnvelope(mContext, mSystemInfo,
redirectUri.toString(),
SppConstants.SppReason.SUBSCRIPTION_REGISTRATION,
diff --git a/service/java/com/android/server/wifi/hotspot2/soap/HttpsTransport.java b/service/java/com/android/server/wifi/hotspot2/soap/HttpsTransport.java
index e04af2182..e299ee443 100644
--- a/service/java/com/android/server/wifi/hotspot2/soap/HttpsTransport.java
+++ b/service/java/com/android/server/wifi/hotspot2/soap/HttpsTransport.java
@@ -33,12 +33,23 @@ public class HttpsTransport extends HttpTransportSE {
private URL mUrl;
private ServiceConnection mServiceConnection;
- public HttpsTransport(@NonNull Network network, @NonNull URL url) {
+ private HttpsTransport(@NonNull Network network, @NonNull URL url) {
super(url.toString());
mNetwork = network;
mUrl = url;
}
+ /**
+ * Create an instance of {@link HttpsTransport}.
+ *
+ * @param network instance of {@link Network} that indicates current connection.
+ * @param url server url used for HTTPS connection.
+ * @return instance of {@link HttpsTransport}
+ */
+ public static HttpsTransport createInstance(@NonNull Network network, @NonNull URL url) {
+ return new HttpsTransport(network, url);
+ }
+
@Override
public ServiceConnection getServiceConnection() throws IOException {
if (mServiceConnection == null) {