增加台湾IP屏蔽
This commit is contained in:
parent
8d9b3b05d3
commit
3a0a03d226
@ -39,10 +39,10 @@ public class LoginAccessValidationService {
|
|||||||
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan"
|
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan"
|
||||||
);
|
);
|
||||||
private static final List<String> BLOCKED_COUNTRY_CODES = List.of(
|
private static final List<String> BLOCKED_COUNTRY_CODES = List.of(
|
||||||
"HK", "MO", "SG"
|
"HK", "MO", "SG", "TW"
|
||||||
);
|
);
|
||||||
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
|
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
|
||||||
"香港", "澳门", "澳門", "Hong Kong", "Macau", "Macao", "新加坡", "Singapore"
|
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan", "新加坡", "Singapore"
|
||||||
);
|
);
|
||||||
private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of(
|
private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of(
|
||||||
new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"),
|
new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"),
|
||||||
|
|||||||
@ -98,11 +98,21 @@ public class LoginAccessValidationServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allowTaiwanRegion() {
|
public void blockTaiwanRegion() {
|
||||||
JSONObject data = JSON.parseObject("""
|
JSONObject data = JSON.parseObject("""
|
||||||
{"country_id":"CN","country":"中国","region":"台湾"}
|
{"country_id":"CN","country":"中国","region":"台湾"}
|
||||||
""");
|
""");
|
||||||
|
|
||||||
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data));
|
assertFalse(LoginAccessValidationService.isMainlandChina(data));
|
||||||
|
assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockTaiwanCountryCode() {
|
||||||
|
JSONObject data = JSON.parseObject("""
|
||||||
|
{"country_id":"TW","country":"Taiwan","region":""}
|
||||||
|
""");
|
||||||
|
|
||||||
|
assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,10 +32,10 @@ public class IpCountryUtils {
|
|||||||
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan"
|
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan"
|
||||||
);
|
);
|
||||||
private static final List<String> BLOCKED_COUNTRY_CODES = List.of(
|
private static final List<String> BLOCKED_COUNTRY_CODES = List.of(
|
||||||
"HK", "MO", "SG"
|
"HK", "MO", "SG", "TW"
|
||||||
);
|
);
|
||||||
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
|
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
|
||||||
"香港", "澳门", "澳門", "Hong Kong", "Macau", "Macao", "新加坡", "Singapore"
|
"香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan", "新加坡", "Singapore"
|
||||||
);
|
);
|
||||||
private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of(
|
private static final List<IpGeoProvider> IP_GEO_PROVIDERS = List.of(
|
||||||
new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"),
|
new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"),
|
||||||
|
|||||||
@ -91,9 +91,17 @@ public class IpCountryUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allowTaiwanRegion() {
|
public void blockTaiwanRegion() {
|
||||||
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "台湾", "test");
|
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "台湾", "test");
|
||||||
|
|
||||||
assertFalse(IpCountryUtils.isBlockedIpRegion(data));
|
assertFalse(IpCountryUtils.isMainlandChina(data));
|
||||||
|
assertTrue(IpCountryUtils.isBlockedIpRegion(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockTaiwanCountryCode() {
|
||||||
|
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("TW", "Taiwan", "", "test");
|
||||||
|
|
||||||
|
assertTrue(IpCountryUtils.isBlockedIpRegion(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user