fix: allow Taiwan login access

This commit is contained in:
hy001 2026-05-15 19:00:13 +08:00
parent 3ec362be15
commit 1d2961c09a
4 changed files with 12 additions and 12 deletions

View File

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

@ -107,21 +107,21 @@ public class LoginAccessValidationServiceTest {
} }
@Test @Test
public void blockTaiwanRegion() { public void allowTaiwanRegion() {
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));
assertTrue(LoginAccessValidationService.isBlockedIpRegion(data)); assertFalse(LoginAccessValidationService.isBlockedIpRegion(data));
} }
@Test @Test
public void blockTaiwanCountryCode() { public void allowTaiwanCountryCode() {
JSONObject data = JSON.parseObject(""" JSONObject data = JSON.parseObject("""
{"country_id":"TW","country":"Taiwan","region":""} {"country_id":"TW","country":"Taiwan","region":""}
"""); """);
assertTrue(LoginAccessValidationService.isBlockedIpRegion(data)); assertFalse(LoginAccessValidationService.isBlockedIpRegion(data));
} }
} }

View File

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

@ -99,17 +99,17 @@ public class IpCountryUtilsTest {
} }
@Test @Test
public void blockTaiwanRegion() { public void allowTaiwanRegion() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "台湾", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("CN", "中国", "台湾", "test");
assertFalse(IpCountryUtils.isMainlandChina(data)); assertFalse(IpCountryUtils.isMainlandChina(data));
assertTrue(IpCountryUtils.isBlockedIpRegion(data)); assertFalse(IpCountryUtils.isBlockedIpRegion(data));
} }
@Test @Test
public void blockTaiwanCountryCode() { public void allowTaiwanCountryCode() {
IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("TW", "Taiwan", "", "test"); IpCountryUtils.IpGeoData data = new IpCountryUtils.IpGeoData("TW", "Taiwan", "", "test");
assertTrue(IpCountryUtils.isBlockedIpRegion(data)); assertFalse(IpCountryUtils.isBlockedIpRegion(data));
} }
} }