Block HK MO TW SG login regions

This commit is contained in:
hy001 2026-06-22 13:36:29 +08:00
parent de95193bda
commit 720c7cec50
4 changed files with 26 additions and 24 deletions

View File

@ -39,10 +39,11 @@ 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(
"MO" "HK", "MO", "TW", "SG"
); );
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of( private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
"澳门", "澳門", "Macau", "Macao" "香港", "澳门", "澳門", "台湾", "台灣", "新加坡",
"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"),

View File

@ -70,22 +70,22 @@ public class LoginAccessValidationServiceTest {
} }
@Test @Test
public void allowHongKongRegion() { public void blockHongKongRegion() {
JSONObject data = JSON.parseObject(""" JSONObject data = JSON.parseObject("""
{"country_id":"CN","country":"中国","region":"香港"} {"country_id":"CN","country":"中国","region":"香港"}
"""); """);
assertFalse(LoginAccessValidationService.isMainlandChina(data)); assertFalse(LoginAccessValidationService.isMainlandChina(data));
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data)); assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
} }
@Test @Test
public void allowHongKongCountryCode() { public void blockHongKongCountryCode() {
JSONObject data = JSON.parseObject(""" JSONObject data = JSON.parseObject("""
{"country_id":"HK","country":"Hong Kong","region":"Kwai Tsing District"} {"country_id":"HK","country":"Hong Kong","region":"Kwai Tsing District"}
"""); """);
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data)); assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
} }
@Test @Test
@ -98,30 +98,30 @@ public class LoginAccessValidationServiceTest {
} }
@Test @Test
public void allowSingaporeCountryCode() { public void blockSingaporeCountryCode() {
JSONObject data = JSON.parseObject(""" JSONObject data = JSON.parseObject("""
{"country_id":"SG","country":"Singapore","region":""} {"country_id":"SG","country":"Singapore","region":""}
"""); """);
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data)); assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
} }
@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.isMainlandChina(data)); assertFalse(LoginAccessValidationService.isMainlandChina(data));
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data)); assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
} }
@Test @Test
public void allowTaiwanCountryCode() { public void blockTaiwanCountryCode() {
JSONObject data = JSON.parseObject(""" JSONObject data = JSON.parseObject("""
{"country_id":"TW","country":"Taiwan","region":""} {"country_id":"TW","country":"Taiwan","region":""}
"""); """);
assertFalse(LoginAccessValidationService.isBlockedIpRegion(data)); assertTrue(LoginAccessValidationService.isBlockedIpRegion(data));
} }
} }

View File

@ -32,10 +32,11 @@ 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(
"MO" "HK", "MO", "TW", "SG"
); );
private static final List<String> BLOCKED_COUNTRY_NAMES = List.of( private static final List<String> BLOCKED_COUNTRY_NAMES = List.of(
"澳门", "澳門", "Macau", "Macao" "香港", "澳门", "澳門", "台湾", "台灣", "新加坡",
"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"),

View File

@ -69,19 +69,19 @@ public class IpCountryUtilsTest {
} }
@Test @Test
public void allowHongKongRegion() { public void blockHongKongRegion() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "香港", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "香港", "test");
assertFalse(IpCountryUtils.isMainlandChina(data)); assertFalse(IpCountryUtils.isMainlandChina(data));
assertFalse(IpCountryUtils.isBlockedIpRegion(data)); assertTrue(IpCountryUtils.isBlockedIpRegion(data));
} }
@Test @Test
public void allowHongKongCountryCode() { public void blockHongKongCountryCode() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("HK", "Hong Kong", "", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("HK", "Hong Kong", "", "test");
assertFalse(IpCountryUtils.isMainlandChina(data)); assertFalse(IpCountryUtils.isMainlandChina(data));
assertFalse(IpCountryUtils.isBlockedIpRegion(data)); assertTrue(IpCountryUtils.isBlockedIpRegion(data));
} }
@Test @Test
@ -92,24 +92,24 @@ public class IpCountryUtilsTest {
} }
@Test @Test
public void allowSingaporeCountryCode() { public void blockSingaporeCountryCode() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("SG", "Singapore", "", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("SG", "Singapore", "", "test");
assertFalse(IpCountryUtils.isBlockedIpRegion(data)); assertTrue(IpCountryUtils.isBlockedIpRegion(data));
} }
@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.isMainlandChina(data)); assertFalse(IpCountryUtils.isMainlandChina(data));
assertFalse(IpCountryUtils.isBlockedIpRegion(data)); assertTrue(IpCountryUtils.isBlockedIpRegion(data));
} }
@Test @Test
public void allowTaiwanCountryCode() { public void blockTaiwanCountryCode() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("TW", "Taiwan", "", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("TW", "Taiwan", "", "test");
assertFalse(IpCountryUtils.isBlockedIpRegion(data)); assertTrue(IpCountryUtils.isBlockedIpRegion(data));
} }
} }