diff options
author | Vikram Gaur <vikramgaur@google.com> | 2024-01-25 19:39:08 +0000 |
---|---|---|
committer | Vikram Gaur <vikramgaur@google.com> | 2024-03-06 21:51:30 +0000 |
commit | 91351e79fc53197185455439ec88f0f1bc6fb62c (patch) | |
tree | 03f62db664db1a2ec9d40109e27754894df53481 | |
parent | a50e28dbd1d558836a6d1ea9e3660c79b670ad64 (diff) | |
download | RemoteKeyProvisioning-91351e79fc53197185455439ec88f0f1bc6fb62c.tar.gz |
Check network connectivity before connecting to RKP servers.
Test: atest RkpdAppUnitTests
Change-Id: I4807424aaccf8cac853440e1827c9075208f5500
-rw-r--r-- | app/src/com/android/rkpdapp/interfaces/ServerInterface.java | 4 | ||||
-rw-r--r-- | app/tests/unit/src/com/android/rkpdapp/unittest/ServerInterfaceTest.java | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/app/src/com/android/rkpdapp/interfaces/ServerInterface.java b/app/src/com/android/rkpdapp/interfaces/ServerInterface.java index 8ce4917..0ebb947 100644 --- a/app/src/com/android/rkpdapp/interfaces/ServerInterface.java +++ b/app/src/com/android/rkpdapp/interfaces/ServerInterface.java @@ -195,6 +195,10 @@ public class ServerInterface { */ public GeekResponse fetchGeek(ProvisioningAttempt metrics) throws RkpdException, InterruptedException { + if (!isNetworkConnected(mContext)) { + throw new RkpdException(RkpdException.ErrorCode.NO_NETWORK_CONNECTIVITY, + "No network detected."); + } byte[] input = CborUtils.buildProvisioningInfo(mContext); byte[] cborBytes = connectAndGetData(metrics, generateFetchGeekUrl(), input, Operation.FETCH_GEEK); diff --git a/app/tests/unit/src/com/android/rkpdapp/unittest/ServerInterfaceTest.java b/app/tests/unit/src/com/android/rkpdapp/unittest/ServerInterfaceTest.java index 896a4b3..c0ae2eb 100644 --- a/app/tests/unit/src/com/android/rkpdapp/unittest/ServerInterfaceTest.java +++ b/app/tests/unit/src/com/android/rkpdapp/unittest/ServerInterfaceTest.java @@ -254,26 +254,23 @@ public class ServerInterfaceTest { } @Test - public void testDataBudgetEmptyFetchGeekNetworkDisconnected() throws Exception { + public void testNetworkDisconnected() throws Exception { try (FakeRkpServer server = new FakeRkpServer( FakeRkpServer.Response.FETCH_EEK_OK, FakeRkpServer.Response.SIGN_CERTS_OK_VALID_CBOR)) { Settings.setDeviceConfig(sContext, 2 /* extraKeys */, TIME_TO_REFRESH_HOURS /* expiringBy */, server.getUrl()); - // Check the data budget in order to initialize a rolling window. - assertThat(Settings.hasErrDataBudget(sContext, null /* curTime */)).isTrue(); - Settings.consumeErrDataBudget(sContext, Settings.FAILURE_DATA_USAGE_MAX); ProvisioningAttempt metrics = ProvisioningAttempt.createScheduledAttemptMetrics( sContext); - // We are okay in mocking connectivity failure since err data budget is the first thing - // to be checked. + // We are okay in mocking connectivity failure since network check is the first thing + // to happen. mockConnectivityFailure(ConnectivityState.DISCONNECTED); mServerInterface.fetchGeek(metrics); assertWithMessage("Network transaction should not have proceeded.").fail(); } catch (RkpdException e) { - assertThat(e).hasMessageThat().contains("Out of data budget due to repeated errors"); + assertThat(e).hasMessageThat().contains("No network detected"); assertThat(e.getErrorCode()).isEqualTo(RkpdException.ErrorCode.NO_NETWORK_CONNECTIVITY); } } |