mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-07-30 09:06:35 -04:00
this code base uses integer values for SDK_INT checks
This commit is contained in:
@@ -544,7 +544,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
return false;
|
||||
}
|
||||
// use new isNumericAddress method if possible, otherwise attempt to use regex
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
return InetAddresses.isNumericAddress(host);
|
||||
} else {
|
||||
// regex found online, verified with unit testing
|
||||
@@ -568,7 +568,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
|
||||
private static boolean isIpv4(String host) {
|
||||
// use new parseNumericAddress method if possible, otherwise attempt to check for format
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
try {
|
||||
InetAddress i = InetAddresses.parseNumericAddress(host);
|
||||
return (i instanceof Inet4Address);
|
||||
@@ -583,7 +583,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
|
||||
private static boolean isIpv6(String host) {
|
||||
// use new parseNumericAddress method if possible, otherwise attempt to check for format
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
try {
|
||||
InetAddress i = InetAddresses.parseNumericAddress(host);
|
||||
return (i instanceof Inet6Address);
|
||||
|
||||
@@ -73,21 +73,21 @@ public class SwapWorkflowActivityTest {
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
@Config(sdk = Build.VERSION_CODES.R)
|
||||
@Config(sdk = 30)
|
||||
public void testValidSwapUrlModern() {
|
||||
assertTrue(SwapWorkflowActivity.isSwapUrl("192.168.0.50", 8888));
|
||||
assertTrue(SwapWorkflowActivity.isSwapUrl("2001:db8:abcd::1234", 8888));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(sdk = Build.VERSION_CODES.R)
|
||||
@Config(sdk = 30)
|
||||
public void testOutOfSubnetModern() {
|
||||
assertFalse(SwapWorkflowActivity.isSwapUrl("10.0.0.50", 8888));
|
||||
assertFalse(SwapWorkflowActivity.isSwapUrl("2010:db8:abcd::1234", 8888));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(sdk = Build.VERSION_CODES.R)
|
||||
@Config(sdk = 30)
|
||||
public void testHostnameIsNeverResolvedModern() {
|
||||
// a hostname must be rejected outright, never resolved via DNS
|
||||
// several of these are considered numeric due to a Robolectric issue, but fail
|
||||
|
||||
Reference in New Issue
Block a user