diff options
author | Etan Cohen <etancohen@google.com> | 2016-10-05 05:23:53 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-10-05 05:23:53 +0000 |
commit | ed67732404cca8272a09d78f046871176483fbed (patch) | |
tree | a6742eceaacdfa101423f1b9f3f76fdfcbc50d35 /tests | |
parent | d386b877185c2a6cc8211c4b4abb509971f3f4e9 (diff) | |
parent | 8acd9c88b0e2e408e685eac3964135f40a783756 (diff) |
Merge "[NAN] Use NAN capability information to validate configurations"
am: 8acd9c88b0
Change-Id: Ife22029d1c035efa7da95c9b79111ee9bba82e66
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/nan/WifiNanServiceImplTest.java | 174 |
2 files changed, 159 insertions, 19 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java index 13e3dd41c..50f7a11c7 100644 --- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java @@ -168,7 +168,7 @@ public class WifiNanDataPathStateManagerTest { InOrder inOrder = inOrder(mMockNative); // (1) get capabilities - mDut.getCapabilities(); + mDut.queryCapabilities(); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).getCapabilities(transactionId.capture()); mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), capabilities); @@ -701,7 +701,7 @@ public class WifiNanDataPathStateManagerTest { collector.checkThat("factory name", "WIFI_NAN_FACTORY", equalTo(strCaptor.getValue())); // (1) get capabilities - mDut.getCapabilities(); + mDut.queryCapabilities(); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).getCapabilities(transactionId.capture()); mDut.onCapabilitiesUpdateResponse(transactionId.getValue(), capabilities); diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanServiceImplTest.java index 13912e9b6..86d388b25 100644 --- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanServiceImplTest.java @@ -36,6 +36,7 @@ import android.net.wifi.nan.IWifiNanDiscoverySessionCallback; import android.net.wifi.nan.IWifiNanEventCallback; import android.net.wifi.nan.PublishConfig; import android.net.wifi.nan.SubscribeConfig; +import android.net.wifi.nan.WifiNanCharacteristics; import android.os.IBinder; import android.os.Looper; import android.test.suitebuilder.annotation.SmallTest; @@ -56,6 +57,8 @@ import java.lang.reflect.Field; */ @SmallTest public class WifiNanServiceImplTest { + private static final int MAX_LENGTH = 255; + private WifiNanServiceImplSpy mDut; private int mDefaultUid = 1500; @@ -104,6 +107,7 @@ public class WifiNanServiceImplTest { when(mContextMock.getPackageManager()).thenReturn(mPackageManagerMock); when(mPackageManagerMock.hasSystemFeature(PackageManager.FEATURE_WIFI_NAN)) .thenReturn(true); + when(mNanStateManagerMock.getCharacteristics()).thenReturn(getCharacteristics()); installMockNanStateManager(); @@ -323,16 +327,38 @@ public class WifiNanServiceImplTest { * name. */ @Test(expected = IllegalArgumentException.class) - public void testPublishBadServiceName() { - PublishConfig publishConfig = new PublishConfig.Builder().setServiceName( - "Including invalid characters - spaces").build(); - int clientId = doConnect(); - IWifiNanDiscoverySessionCallback mockCallback = mock( - IWifiNanDiscoverySessionCallback.class); + public void testPublishInvalidServiceName() { + doBadPublishConfiguration("Including invalid characters - spaces", null, null); + } - mDut.publish(clientId, publishConfig, mockCallback); + /** + * Validate that publish() verifies the input PublishConfig and fails on a "very long" + * service name. + */ + @Test(expected = IllegalArgumentException.class) + public void testPublishServiceNameTooLong() { + byte[] byteArray = new byte[MAX_LENGTH + 1]; + for (int i = 0; i < MAX_LENGTH + 1; ++i) { + byteArray[i] = 'a'; + } + doBadPublishConfiguration(new String(byteArray), null, null); + } - verify(mNanStateManagerMock).publish(clientId, publishConfig, mockCallback); + /** + * Validate that publish() verifies the input PublishConfig and fails on a "very long" ssi. + */ + @Test(expected = IllegalArgumentException.class) + public void testPublishSsiTooLong() { + doBadPublishConfiguration("correctservicename", new byte[MAX_LENGTH + 1], null); + } + + /** + * Validate that publish() verifies the input PublishConfig and fails on a "very long" match + * filter. + */ + @Test(expected = IllegalArgumentException.class) + public void testPublishMatchFilterTooLong() { + doBadPublishConfiguration("correctservicename", null, new byte[MAX_LENGTH + 1]); } /** @@ -351,6 +377,21 @@ public class WifiNanServiceImplTest { } /** + * Validate updatePublish() error checking. + */ + @Test(expected = IllegalArgumentException.class) + public void testUpdatePublishInvalid() { + int sessionId = 1232; + PublishConfig publishConfig = new PublishConfig.Builder() + .setServiceName("something with spaces").build(); + int clientId = doConnect(); + + mDut.updatePublish(clientId, sessionId, publishConfig); + + verify(mNanStateManagerMock).updatePublish(clientId, sessionId, publishConfig); + } + + /** * Validate subscribe() - correct pass-through args. */ @Test @@ -371,20 +412,58 @@ public class WifiNanServiceImplTest { * name. */ @Test(expected = IllegalArgumentException.class) - public void testSubscribeBadServiceName() { - SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName( - "InvalidServiceCharacters__").build(); + public void testSubscribeInvalidServiceName() { + doBadSubscribeConfiguration("Including invalid characters - spaces", null, null); + } + + /** + * Validate that subscribe() verifies the input SubscribeConfig and fails on a "very long" + * service name. + */ + @Test(expected = IllegalArgumentException.class) + public void testSubscribeServiceNameTooLong() { + byte[] byteArray = new byte[MAX_LENGTH + 1]; + for (int i = 0; i < MAX_LENGTH + 1; ++i) { + byteArray[i] = 'a'; + } + doBadSubscribeConfiguration(new String(byteArray), null, null); + } + + /** + * Validate that subscribe() verifies the input SubscribeConfig and fails on a "very long" ssi. + */ + @Test(expected = IllegalArgumentException.class) + public void testSubscribeSsiTooLong() { + doBadSubscribeConfiguration("correctservicename", new byte[MAX_LENGTH + 1], null); + } + + /** + * Validate that subscribe() verifies the input SubscribeConfig and fails on a "very long" match + * filter. + */ + @Test(expected = IllegalArgumentException.class) + public void testSubscribeMatchFilterTooLong() { + doBadSubscribeConfiguration("correctservicename", null, new byte[MAX_LENGTH + 1]); + } + + /** + * Validate updateSubscribe() error checking. + */ + @Test(expected = IllegalArgumentException.class) + public void testUpdateSubscribeInvalid() { + int sessionId = 1232; + SubscribeConfig subscribeConfig = new SubscribeConfig.Builder() + .setServiceName("something.valid") + .setServiceSpecificInfo(new byte[MAX_LENGTH + 1]).build(); int clientId = doConnect(); - IWifiNanDiscoverySessionCallback mockCallback = mock( - IWifiNanDiscoverySessionCallback.class); - mDut.subscribe(clientId, subscribeConfig, mockCallback); + mDut.updateSubscribe(clientId, sessionId, subscribeConfig); - verify(mNanStateManagerMock).subscribe(clientId, subscribeConfig, mockCallback); + verify(mNanStateManagerMock).updateSubscribe(clientId, sessionId, subscribeConfig); } /** - * Validate updateSubscribe() - correct pass-through args. + * Validate updateSubscribe() validates configuration. */ @Test public void testUpdateSubscribe() { @@ -405,7 +484,24 @@ public class WifiNanServiceImplTest { public void testSendMessage() { int sessionId = 2394; int peerId = 2032; - byte[] message = new byte[23]; + byte[] message = new byte[MAX_LENGTH]; + int messageId = 2043; + int clientId = doConnect(); + + mDut.sendMessage(clientId, sessionId, peerId, message, messageId, 0); + + verify(mNanStateManagerMock).sendMessage(clientId, sessionId, peerId, message, messageId, + 0); + } + + /** + * Validate sendMessage() validates that message length is correct. + */ + @Test(expected = IllegalArgumentException.class) + public void testSendMessageTooLong() { + int sessionId = 2394; + int peerId = 2032; + byte[] message = new byte[MAX_LENGTH + 1]; int messageId = 2043; int clientId = doConnect(); @@ -492,6 +588,32 @@ public class WifiNanServiceImplTest { * Utilities */ + private void doBadPublishConfiguration(String serviceName, byte[] ssi, byte[] matchFilter) + throws IllegalArgumentException { + PublishConfig publishConfig = new PublishConfig.Builder().setServiceName(serviceName) + .setServiceSpecificInfo(ssi).setMatchFilter(matchFilter).build(); + int clientId = doConnect(); + IWifiNanDiscoverySessionCallback mockCallback = mock( + IWifiNanDiscoverySessionCallback.class); + + mDut.publish(clientId, publishConfig, mockCallback); + + verify(mNanStateManagerMock).publish(clientId, publishConfig, mockCallback); + } + + private void doBadSubscribeConfiguration(String serviceName, byte[] ssi, byte[] matchFilter) + throws IllegalArgumentException { + SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName(serviceName) + .setServiceSpecificInfo(ssi).setMatchFilter(matchFilter).build(); + int clientId = doConnect(); + IWifiNanDiscoverySessionCallback mockCallback = mock( + IWifiNanDiscoverySessionCallback.class); + + mDut.subscribe(clientId, subscribeConfig, mockCallback); + + verify(mNanStateManagerMock).subscribe(clientId, subscribeConfig, mockCallback); + } + private int doConnect() { String callingPackage = "com.google.somePackage"; @@ -512,6 +634,24 @@ public class WifiNanServiceImplTest { field.set(null, mNanStateManagerMock); } + private static WifiNanCharacteristics getCharacteristics() { + WifiNanNative.Capabilities cap = new WifiNanNative.Capabilities(); + cap.maxConcurrentNanClusters = 1; + cap.maxPublishes = 2; + cap.maxSubscribes = 2; + cap.maxServiceNameLen = MAX_LENGTH; + cap.maxMatchFilterLen = MAX_LENGTH; + cap.maxTotalMatchFilterLen = 255; + cap.maxServiceSpecificInfoLen = MAX_LENGTH; + cap.maxVsaDataLen = 255; + cap.maxMeshDataLen = 255; + cap.maxNdiInterfaces = 1; + cap.maxNdpSessions = 1; + cap.maxAppInfoLen = 255; + cap.maxQueuedTransmitMessages = 6; + return cap.toPublicCharacteristics(); + } + private int getInternalStateUid(int clientId) throws Exception { Field field = WifiNanServiceImpl.class.getDeclaredField("mUidByClientId"); field.setAccessible(true); |