@onekeyfe/react-native-network-throttle 3.0.84-alpha.0 → 3.0.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -140,7 +140,7 @@ internal object NetworkThrottle {
|
|
|
140
140
|
* patterns the desktop app installs, so both platforms throttle the same
|
|
141
141
|
* traffic.
|
|
142
142
|
*/
|
|
143
|
-
|
|
143
|
+
internal fun matchesHost(host: String, pattern: String): Boolean =
|
|
144
144
|
if (pattern.startsWith("*.")) {
|
|
145
145
|
host.endsWith(pattern.substring(1))
|
|
146
146
|
} else {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package com.onekeyfe.reactnativenetworkthrottle
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertFalse
|
|
4
|
+
import org.junit.Assert.assertTrue
|
|
5
|
+
import org.junit.Test
|
|
6
|
+
|
|
7
|
+
class NetworkThrottleHostMatchingTest {
|
|
8
|
+
|
|
9
|
+
@Test
|
|
10
|
+
fun matchesSubDomainsAtAnyDepth() {
|
|
11
|
+
assertTrue(NetworkThrottle.matchesHost("wallet.onekeycn.com", "*.onekeycn.com"))
|
|
12
|
+
assertTrue(NetworkThrottle.matchesHost("swap.onekeycn.com", "*.onekeycn.com"))
|
|
13
|
+
assertTrue(NetworkThrottle.matchesHost("a.b.onekeycn.com", "*.onekeycn.com"))
|
|
14
|
+
assertTrue(NetworkThrottle.matchesHost("uni.onekey-asset.com", "*.onekey-asset.com"))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Test
|
|
18
|
+
fun matchesExactHosts() {
|
|
19
|
+
assertTrue(NetworkThrottle.matchesHost("app-assets.onekey.so", "app-assets.onekey.so"))
|
|
20
|
+
assertFalse(NetworkThrottle.matchesHost("other.onekey.so", "app-assets.onekey.so"))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun doesNotMatchTheBareApex() {
|
|
25
|
+
// The desktop URLPattern wildcard behaves the same way, so a bare apex must
|
|
26
|
+
// stay untouched on both platforms.
|
|
27
|
+
assertFalse(NetworkThrottle.matchesHost("onekeycn.com", "*.onekeycn.com"))
|
|
28
|
+
assertFalse(NetworkThrottle.matchesHost("onekey-asset.com", "*.onekey-asset.com"))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Test
|
|
32
|
+
fun doesNotMatchLookAlikeHosts() {
|
|
33
|
+
// A suffix check without the leading dot would wrongly match these, which
|
|
34
|
+
// would throttle traffic that is not OneKey's.
|
|
35
|
+
assertFalse(NetworkThrottle.matchesHost("evil-onekeycn.com", "*.onekeycn.com"))
|
|
36
|
+
assertFalse(NetworkThrottle.matchesHost("notonekeycn.com", "*.onekeycn.com"))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Test
|
|
40
|
+
fun doesNotMatchUnrelatedHosts() {
|
|
41
|
+
for (host in listOf("mainnet.infura.io", "api.hyperliquid.xyz", "localhost", "127.0.0.1")) {
|
|
42
|
+
assertFalse(NetworkThrottle.matchesHost(host, "*.onekeycn.com"))
|
|
43
|
+
assertFalse(NetworkThrottle.matchesHost(host, "app-assets.onekey.so"))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED