aboutsummaryrefslogtreecommitdiff
path: root/tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java')
-rw-r--r--tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java438
1 files changed, 326 insertions, 112 deletions
diff --git a/tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java b/tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java
index 6dafef3..8a4a185 100644
--- a/tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java
+++ b/tests/src/com/android/libraries/entitlement/eapaka/EapAkaApiTest.java
@@ -48,6 +48,7 @@ import com.android.libraries.entitlement.ServiceEntitlementException;
import com.android.libraries.entitlement.ServiceEntitlementRequest;
import com.android.libraries.entitlement.http.HttpClient;
import com.android.libraries.entitlement.http.HttpConstants.ContentType;
+import com.android.libraries.entitlement.http.HttpConstants.RequestMethod;
import com.android.libraries.entitlement.http.HttpRequest;
import com.android.libraries.entitlement.http.HttpResponse;
@@ -134,21 +135,22 @@ public class EapAkaApiTest {
mMockPackageInfo.versionName = APP_VERSION;
when(mMockPackageManager.getPackageInfo(anyString(), anyInt()))
.thenReturn(mMockPackageInfo);
- mEapAkaApi = new EapAkaApi(mContext, SUB_ID, mMockHttpClient, "");
- mEapAkaApiBypassAuthentication =
- new EapAkaApi(mContext, SUB_ID, mMockHttpClient, BYPASS_EAP_AKA_RESPONSE);
- when(mContext.getSystemService(TelephonyManager.class))
- .thenReturn(mMockTelephonyManager);
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mMockTelephonyManager);
when(mMockTelephonyManager.createForSubscriptionId(SUB_ID))
.thenReturn(mMockTelephonyManagerForSubId);
when(mMockTelephonyManagerForSubId.getSubscriberId()).thenReturn(IMSI);
when(mMockTelephonyManagerForSubId.getSimOperator()).thenReturn(MCCMNC);
+ mEapAkaApi = new EapAkaApi(mContext, SUB_ID, mMockHttpClient, "");
+ mEapAkaApiBypassAuthentication =
+ new EapAkaApi(mContext, SUB_ID, mMockHttpClient, BYPASS_EAP_AKA_RESPONSE);
}
@Test
public void queryEntitlementStatus_hasAuthenticationToken() throws Exception {
HttpResponse httpResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any())).thenReturn(httpResponse);
CarrierConfig carrierConfig =
@@ -165,24 +167,59 @@ public class EapAkaApiTest {
assertThat(mHttpRequestCaptor.getValue().timeoutInSec())
.isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
assertThat(mHttpRequestCaptor.getValue().network()).isEqualTo(mMockNetwork);
+ assertThat(mHttpRequestCaptor.getValue().requestMethod()).isEqualTo(RequestMethod.GET);
+ }
+
+ @Test
+ public void queryEntitlementStatus_hasAuthenticationToken_useHttpPost() throws Exception {
+ HttpResponse httpResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
+ .build();
+ when(mMockHttpClient.request(any())).thenReturn(httpResponse);
+ CarrierConfig carrierConfig =
+ CarrierConfig.builder()
+ .setServerUrl(TEST_URL)
+ .setNetwork(mMockNetwork)
+ .setUseHttpPost(true)
+ .build();
+ ServiceEntitlementRequest request =
+ ServiceEntitlementRequest.builder().setAuthenticationToken(TOKEN).build();
+
+ HttpResponse response =
+ mEapAkaApi.queryEntitlementStatus(
+ ImmutableList.of(ServiceEntitlement.APP_VOWIFI), carrierConfig, request);
+
+ assertThat(response).isEqualTo(httpResponse);
+ verify(mMockHttpClient).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getValue().timeoutInSec())
+ .isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
+ assertThat(mHttpRequestCaptor.getValue().network()).isEqualTo(mMockNetwork);
+ assertThat(mHttpRequestCaptor.getValue().requestMethod()).isEqualTo(RequestMethod.POST);
}
@Test
public void queryEntitlementStatus_noAuthenticationToken() throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1))
+ .build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
- .thenReturn(eapChallengeResponse).thenReturn(xmlResponse);
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
@@ -192,10 +229,63 @@ public class EapAkaApiTest {
assertThat(response).isEqualTo(xmlResponse);
verify(mMockHttpClient, times(2)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.GET);
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).requestMethod())
+ .isEqualTo(RequestMethod.POST);
+ // Verify that the 2nd request has cookies set by the 1st response
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).requestProperties())
+ .containsAtLeast(
+ HTTP_HEADER_COOKIE, COOKIE_VALUE,
+ HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).timeoutInSec())
+ .isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).network()).isNull();
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).timeoutInSec())
+ .isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).network()).isNull();
+ }
+
+ @Test
+ public void queryEntitlementStatus_noAuthenticationToken_useHttpPost() throws Exception {
+ when(mMockTelephonyManagerForSubId.getIccAuthentication(
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ .thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
+ HttpResponse eapChallengeResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1))
+ .build();
+ HttpResponse xmlResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
+ .build();
+ when(mMockHttpClient.request(any()))
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
+ CarrierConfig carrierConfig =
+ CarrierConfig.builder().setServerUrl(TEST_URL).setUseHttpPost(true).build();
+ ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
+
+ HttpResponse response =
+ mEapAkaApi.queryEntitlementStatus(
+ ImmutableList.of(ServiceEntitlement.APP_VOWIFI), carrierConfig, request);
+
+ assertThat(response).isEqualTo(xmlResponse);
+ verify(mMockHttpClient, times(2)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.POST);
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).requestMethod())
+ .isEqualTo(RequestMethod.POST);
// Verify that the 2nd request has cookies set by the 1st response
assertThat(mHttpRequestCaptor.getAllValues().get(1).requestProperties())
- .containsAtLeast(HTTP_HEADER_COOKIE, COOKIE_VALUE,
- HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
+ .containsAtLeast(
+ HTTP_HEADER_COOKIE, COOKIE_VALUE,
+ HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
assertThat(mHttpRequestCaptor.getAllValues().get(0).timeoutInSec())
.isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
assertThat(mHttpRequestCaptor.getAllValues().get(0).network()).isNull();
@@ -207,9 +297,9 @@ public class EapAkaApiTest {
@Test
public void queryEntitlementStatus_noAuthenticationToken_invalidChallenge() throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
HttpResponse eapChallengeResponse =
HttpResponse.builder()
@@ -218,10 +308,13 @@ public class EapAkaApiTest {
.setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1))
.build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
- .thenReturn(eapChallengeResponse).thenReturn(xmlResponse);
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
@@ -276,8 +369,9 @@ public class EapAkaApiTest {
// Verify that the subsequent requests have cookies set by the 1st response
verify(mMockHttpClient, times(3)).request(mHttpRequestCaptor.capture());
assertThat(mHttpRequestCaptor.getAllValues().get(1).requestProperties())
- .containsAtLeast(HTTP_HEADER_COOKIE, COOKIE_VALUE,
- HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
+ .containsAtLeast(
+ HTTP_HEADER_COOKIE, COOKIE_VALUE,
+ HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
assertThat(mHttpRequestCaptor.getAllValues().get(0).timeoutInSec())
.isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
assertThat(mHttpRequestCaptor.getAllValues().get(0).network()).isNull();
@@ -323,8 +417,9 @@ public class EapAkaApiTest {
// Verify that the subsequent requests have cookies set by the 1st response
verify(mMockHttpClient, times(4)).request(mHttpRequestCaptor.capture());
assertThat(mHttpRequestCaptor.getAllValues().get(1).requestProperties())
- .containsAtLeast(HTTP_HEADER_COOKIE, COOKIE_VALUE,
- HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
+ .containsAtLeast(
+ HTTP_HEADER_COOKIE, COOKIE_VALUE,
+ HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
assertThat(mHttpRequestCaptor.getAllValues().get(0).timeoutInSec())
.isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
assertThat(mHttpRequestCaptor.getAllValues().get(0).network()).isNull();
@@ -381,11 +476,13 @@ public class EapAkaApiTest {
@Test
public void queryEntitlementStatus_hasAuthenticationToken_multipleAppIds() throws Exception {
HttpResponse response =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any())).thenReturn(response);
- ImmutableList<String> appIds = ImmutableList.of(ServiceEntitlement.APP_VOWIFI,
- ServiceEntitlement.APP_VOLTE);
+ ImmutableList<String> appIds =
+ ImmutableList.of(ServiceEntitlement.APP_VOWIFI, ServiceEntitlement.APP_VOLTE);
CarrierConfig carrierConfig =
CarrierConfig.builder().setServerUrl(TEST_URL).setTimeoutInSec(70).build();
ServiceEntitlementRequest request =
@@ -406,19 +503,20 @@ public class EapAkaApiTest {
HttpResponse eapChallengeResponse =
HttpResponse.builder().setContentType(ContentType.JSON).build();
when(mMockHttpClient.request(any())).thenReturn(eapChallengeResponse);
- CarrierConfig carrierConfig =
- CarrierConfig.builder().setServerUrl(TEST_URL).build();
+ CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
- ServiceEntitlementException exception = expectThrows(
- ServiceEntitlementException.class,
- () -> mEapAkaApi.queryEntitlementStatus(
- ImmutableList.of(ServiceEntitlement.APP_VOWIFI),
- carrierConfig,
- request));
+ ServiceEntitlementException exception =
+ expectThrows(
+ ServiceEntitlementException.class,
+ () ->
+ mEapAkaApi.queryEntitlementStatus(
+ ImmutableList.of(ServiceEntitlement.APP_VOWIFI),
+ carrierConfig,
+ request));
- assertThat(exception.getErrorCode()).isEqualTo(
- ServiceEntitlementException.ERROR_MALFORMED_HTTP_RESPONSE);
+ assertThat(exception.getErrorCode())
+ .isEqualTo(ServiceEntitlementException.ERROR_MALFORMED_HTTP_RESPONSE);
assertThat(exception.getMessage()).isEqualTo("Failed to parse json object");
assertThat(exception.getCause()).isInstanceOf(JSONException.class);
assertThat(exception.getHttpStatus()).isEqualTo(0);
@@ -429,17 +527,21 @@ public class EapAkaApiTest {
public void queryEntitlementStatus_noAuthenticationToken_handleEapAkaSyncFailure()
throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE)
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
.thenReturn(eapChallengeResponse)
@@ -465,14 +567,16 @@ public class EapAkaApiTest {
public void queryEntitlementStatus_noAuthenticationToken_eapAkaSyncFailure_invalidChallenge()
throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
HttpResponse invalidEapChallengeResponse =
HttpResponse.builder()
.setContentType(ContentType.JSON)
@@ -507,17 +611,19 @@ public class EapAkaApiTest {
public void queryEntitlementStatus_noAuthenticationToken_fourthEapAkaSyncFailure()
throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE)
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE)
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE)
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SYNC_FAILURE);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
when(mMockHttpClient.request(any()))
.thenReturn(eapChallengeResponse)
.thenReturn(eapChallengeResponse)
@@ -548,14 +654,19 @@ public class EapAkaApiTest {
public void queryEntitlementStatus_hasNoAuthenticationToken_bypassAuthentication()
throws Exception {
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE, COOKIE_VALUE_1))
+ .build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
- .thenReturn(eapChallengeResponse).thenReturn(xmlResponse);
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
@@ -567,8 +678,9 @@ public class EapAkaApiTest {
// Verify that the 2nd request has cookies set by the 1st response
verify(mMockHttpClient, times(2)).request(mHttpRequestCaptor.capture());
assertThat(mHttpRequestCaptor.getAllValues().get(1).requestProperties())
- .containsAtLeast(HTTP_HEADER_COOKIE, COOKIE_VALUE,
- HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
+ .containsAtLeast(
+ HTTP_HEADER_COOKIE, COOKIE_VALUE,
+ HTTP_HEADER_COOKIE, COOKIE_VALUE_1);
assertThat(mHttpRequestCaptor.getAllValues().get(0).timeoutInSec())
.isEqualTo(CarrierConfig.DEFAULT_TIMEOUT_IN_SEC);
assertThat(mHttpRequestCaptor.getAllValues().get(0).network()).isNull();
@@ -593,8 +705,7 @@ public class EapAkaApiTest {
when(mMockHttpClient.request(any())).thenReturn(response);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request =
- ServiceEntitlementRequest
- .builder()
+ ServiceEntitlementRequest.builder()
.setAuthenticationToken(TOKEN)
.setAcceptContentType(ServiceEntitlementRequest.ACCEPT_CONTENT_TYPE_XML)
.build();
@@ -614,10 +725,7 @@ public class EapAkaApiTest {
when(mMockHttpClient.request(any())).thenReturn(response);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request =
- ServiceEntitlementRequest
- .builder()
- .setAuthenticationToken(TOKEN)
- .build();
+ ServiceEntitlementRequest.builder().setAuthenticationToken(TOKEN).build();
mEapAkaApi.queryEntitlementStatus(
ImmutableList.of(ServiceEntitlement.APP_VOWIFI), carrierConfig, request);
@@ -650,11 +758,7 @@ public class EapAkaApiTest {
String.format(
"terminal_vendor=%s&terminal_model=%s&terminal_sw_version=%s",
LONG_VENDOR_TRIMMED, LONG_MODEL_TRIMMED, LONG_SW_VERSION_TRIMMED);
- assertThat(
- mHttpRequestCaptor
- .getValue()
- .url())
- .contains(urlParams);
+ assertThat(mHttpRequestCaptor.getValue().url()).contains(urlParams);
}
@Test
@@ -692,19 +796,24 @@ public class EapAkaApiTest {
@Test
public void queryEntitlementStatus_userAgentSet_duringEapAka() throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
- .thenReturn(eapChallengeResponse).thenReturn(xmlResponse);
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
CarrierConfig carrierConfig =
CarrierConfig.builder()
.setServerUrl(TEST_URL)
@@ -727,14 +836,16 @@ public class EapAkaApiTest {
VENDOR, MODEL, carrierConfig.clientTs43(), APP_VERSION, SW_VERSION);
assertThat(
mHttpRequestCaptor
- .getAllValues().get(0)
+ .getAllValues()
+ .get(0)
.requestProperties()
.get(HttpHeaders.USER_AGENT)
.get(0))
.isEqualTo(userAgent);
assertThat(
mHttpRequestCaptor
- .getAllValues().get(1)
+ .getAllValues()
+ .get(1)
.requestProperties()
.get(HttpHeaders.USER_AGENT)
.get(0))
@@ -780,52 +891,133 @@ public class EapAkaApiTest {
@Test
public void performEsimOdsaOperation_noAuthenticationToken_returnsResult() throws Exception {
when(mMockTelephonyManagerForSubId.getIccAuthentication(
- TelephonyManager.APPTYPE_USIM,
- TelephonyManager.AUTHTYPE_EAP_AKA,
- EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
.thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
HttpResponse eapChallengeResponse =
- HttpResponse
- .builder().setContentType(ContentType.JSON).setBody(EAP_AKA_CHALLENGE)
- .setCookies(ImmutableList.of(COOKIE_VALUE)).build();
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any()))
- .thenReturn(eapChallengeResponse).thenReturn(xmlResponse);
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
EsimOdsaOperation operation = EsimOdsaOperation.builder().build();
HttpResponse response =
- mEapAkaApi.performEsimOdsaOperation(ServiceEntitlement.APP_ODSA_COMPANION,
- carrierConfig, request, operation);
+ mEapAkaApi.performEsimOdsaOperation(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request, operation);
assertThat(response).isEqualTo(xmlResponse);
- verify(mMockHttpClient, times(2)).request(any());
+ verify(mMockHttpClient, times(2)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.GET);
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).requestMethod())
+ .isEqualTo(RequestMethod.POST);
+ }
+
+ @Test
+ public void performEsimOdsaOperation_noAuthenticationToken_useHttpPost_returnsResult()
+ throws Exception {
+ when(mMockTelephonyManagerForSubId.getIccAuthentication(
+ TelephonyManager.APPTYPE_USIM,
+ TelephonyManager.AUTHTYPE_EAP_AKA,
+ EAP_AKA_SECURITY_CONTEXT_REQUEST_EXPECTED))
+ .thenReturn(EAP_AKA_SECURITY_CONTEXT_RESPONSE_SUCCESS);
+ HttpResponse eapChallengeResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.JSON)
+ .setBody(EAP_AKA_CHALLENGE)
+ .setCookies(ImmutableList.of(COOKIE_VALUE))
+ .build();
+ HttpResponse xmlResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
+ .build();
+ when(mMockHttpClient.request(any()))
+ .thenReturn(eapChallengeResponse)
+ .thenReturn(xmlResponse);
+ CarrierConfig carrierConfig =
+ CarrierConfig.builder().setServerUrl(TEST_URL).setUseHttpPost(true).build();
+ ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
+ EsimOdsaOperation operation = EsimOdsaOperation.builder().build();
+
+ HttpResponse response =
+ mEapAkaApi.performEsimOdsaOperation(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request, operation);
+
+ assertThat(response).isEqualTo(xmlResponse);
+ verify(mMockHttpClient, times(2)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.POST);
+ assertThat(mHttpRequestCaptor.getAllValues().get(1).requestMethod())
+ .isEqualTo(RequestMethod.POST);
}
@Test
public void performEsimOdsaOperation_manageSubscription_returnsResult() throws Exception {
HttpResponse xmlResponse =
- HttpResponse.builder().setContentType(ContentType.XML).setBody(RESPONSE_XML)
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
+ .build();
+ when(mMockHttpClient.request(any())).thenReturn(xmlResponse);
+ CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
+ ServiceEntitlementRequest request =
+ ServiceEntitlementRequest.builder().setAuthenticationToken(TOKEN).build();
+ EsimOdsaOperation operation =
+ EsimOdsaOperation.builder()
+ .setOperation(EsimOdsaOperation.OPERATION_MANAGE_SUBSCRIPTION)
+ .setOperationType(EsimOdsaOperation.OPERATION_TYPE_SUBSCRIBE)
+ .build();
+
+ HttpResponse response =
+ mEapAkaApi.performEsimOdsaOperation(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request, operation);
+
+ assertThat(response).isEqualTo(xmlResponse);
+ verify(mMockHttpClient, times(1)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.GET);
+ }
+
+ @Test
+ public void performEsimOdsaOperation_manageSubscription_useHttpPost_returnsResult()
+ throws Exception {
+ HttpResponse xmlResponse =
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setBody(RESPONSE_XML)
.build();
when(mMockHttpClient.request(any())).thenReturn(xmlResponse);
CarrierConfig carrierConfig =
- CarrierConfig.builder().setServerUrl(TEST_URL).build();
+ CarrierConfig.builder().setServerUrl(TEST_URL).setUseHttpPost(true).build();
ServiceEntitlementRequest request =
ServiceEntitlementRequest.builder().setAuthenticationToken(TOKEN).build();
- EsimOdsaOperation operation = EsimOdsaOperation.builder()
- .setOperation(EsimOdsaOperation.OPERATION_MANAGE_SUBSCRIPTION)
- .setOperationType(EsimOdsaOperation.OPERATION_TYPE_SUBSCRIBE)
- .build();
+ EsimOdsaOperation operation =
+ EsimOdsaOperation.builder()
+ .setOperation(EsimOdsaOperation.OPERATION_MANAGE_SUBSCRIPTION)
+ .setOperationType(EsimOdsaOperation.OPERATION_TYPE_SUBSCRIBE)
+ .build();
HttpResponse response =
- mEapAkaApi.performEsimOdsaOperation(ServiceEntitlement.APP_ODSA_COMPANION,
- carrierConfig, request, operation);
+ mEapAkaApi.performEsimOdsaOperation(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request, operation);
assertThat(response).isEqualTo(xmlResponse);
- verify(mMockHttpClient, times(1)).request(any());
+ verify(mMockHttpClient, times(1)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.POST);
}
@Test
@@ -879,17 +1071,40 @@ public class EapAkaApiTest {
.setContentType(ContentType.XML)
.setLocation(HTTP_HEADER_LOCATION)
.build();
- when(mMockHttpClient.request(any()))
- .thenReturn(response);
+ when(mMockHttpClient.request(any())).thenReturn(response);
CarrierConfig carrierConfig = CarrierConfig.builder().setServerUrl(TEST_URL).build();
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
String endpoint =
- mEapAkaApi.acquireOidcAuthenticationEndpoint(ServiceEntitlement.APP_ODSA_COMPANION,
- carrierConfig, request);
+ mEapAkaApi.acquireOidcAuthenticationEndpoint(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request);
assertThat(endpoint).isEqualTo(HTTP_HEADER_LOCATION);
- verify(mMockHttpClient, times(1)).request(any());
+ verify(mMockHttpClient, times(1)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.GET);
+ }
+
+ @Test
+ public void acquireOidcAuthenticationEndpoint_useHttpPost() throws Exception {
+ HttpResponse response =
+ HttpResponse.builder()
+ .setContentType(ContentType.XML)
+ .setLocation(HTTP_HEADER_LOCATION)
+ .build();
+ when(mMockHttpClient.request(any())).thenReturn(response);
+ CarrierConfig carrierConfig =
+ CarrierConfig.builder().setServerUrl(TEST_URL).setUseHttpPost(true).build();
+ ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
+
+ String endpoint =
+ mEapAkaApi.acquireOidcAuthenticationEndpoint(
+ ServiceEntitlement.APP_ODSA_COMPANION, carrierConfig, request);
+
+ assertThat(endpoint).isEqualTo(HTTP_HEADER_LOCATION);
+ verify(mMockHttpClient, times(1)).request(mHttpRequestCaptor.capture());
+ assertThat(mHttpRequestCaptor.getAllValues().get(0).requestMethod())
+ .isEqualTo(RequestMethod.POST);
}
@Test
@@ -904,8 +1119,7 @@ public class EapAkaApiTest {
ServiceEntitlementRequest request = ServiceEntitlementRequest.builder().build();
HttpResponse response =
- mEapAkaApi.queryEntitlementStatusFromOidc(
- TEST_URL, carrierConfig, request);
+ mEapAkaApi.queryEntitlementStatusFromOidc(TEST_URL, carrierConfig, request);
assertThat(response).isEqualTo(xmlResponse);
verify(mMockHttpClient, times(1)).request(any());