1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net.ip
18 
19 import android.net.ipmemorystore.NetworkAttributes
20 import android.util.ArrayMap
21 import org.mockito.Mockito.any
22 import org.mockito.ArgumentCaptor
23 import org.mockito.Mockito.eq
24 import org.mockito.Mockito.never
25 import org.mockito.Mockito.timeout
26 import org.mockito.Mockito.verify
27 
28 /**
29  * Tests for IpClient, run with signature permissions.
30  */
31 class IpClientIntegrationTest : IpClientIntegrationTestCommon() {
32     private val mEnabledFeatures = ArrayMap<String, Boolean>()
33 
34     override fun makeIIpClient(ifaceName: String, cb: IIpClientCallbacks): IIpClient {
35         return mIpc.makeConnector()
36     }
37 
38     override fun useNetworkStackSignature() = true
39 
40     override fun isFeatureEnabled(name: String, defaultEnabled: Boolean): Boolean {
41         return mEnabledFeatures.get(name) ?: defaultEnabled
42     }
43 
44     override fun setFeatureEnabled(name: String, enabled: Boolean) {
45         mEnabledFeatures.put(name, enabled)
46     }
47 
48     override fun getStoredNetworkAttributes(l2Key: String, timeout: Long): NetworkAttributes {
49         val networkAttributesCaptor = ArgumentCaptor.forClass(NetworkAttributes::class.java)
50 
51         verify(mIpMemoryStore, timeout(timeout))
52                 .storeNetworkAttributes(eq(l2Key), networkAttributesCaptor.capture(), any())
53         return networkAttributesCaptor.value
54     }
55 
56     override fun assertIpMemoryNeverStoreNetworkAttributes(l2Key: String, timeout: Long) {
57         verify(mIpMemoryStore, never()).storeNetworkAttributes(eq(l2Key), any(), any())
58     }
59 }
60