From 3a0a03d2264afc389367f6ea9fb2e1a216eff828 Mon Sep 17 00:00:00 2001 From: hy001 Date: Sat, 9 May 2026 13:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=B0=E6=B9=BEIP=E5=B1=8F?= =?UTF-8?q?=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/common/LoginAccessValidationService.java | 4 ++-- .../common/LoginAccessValidationServiceTest.java | 14 ++++++++++++-- .../circle/other/infra/utils/IpCountryUtils.java | 4 ++-- .../other/infra/utils/IpCountryUtilsTest.java | 12 ++++++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/rc-auth/src/main/java/com/red/circle/auth/common/LoginAccessValidationService.java b/rc-auth/src/main/java/com/red/circle/auth/common/LoginAccessValidationService.java index 5562fda6..749bb614 100644 --- a/rc-auth/src/main/java/com/red/circle/auth/common/LoginAccessValidationService.java +++ b/rc-auth/src/main/java/com/red/circle/auth/common/LoginAccessValidationService.java @@ -39,10 +39,10 @@ public class LoginAccessValidationService { "香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan" ); private static final List BLOCKED_COUNTRY_CODES = List.of( - "HK", "MO", "SG" + "HK", "MO", "SG", "TW" ); private static final List BLOCKED_COUNTRY_NAMES = List.of( - "香港", "澳门", "澳門", "Hong Kong", "Macau", "Macao", "新加坡", "Singapore" + "香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan", "新加坡", "Singapore" ); private static final List IP_GEO_PROVIDERS = List.of( new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"), diff --git a/rc-auth/src/test/java/com/red/circle/auth/common/LoginAccessValidationServiceTest.java b/rc-auth/src/test/java/com/red/circle/auth/common/LoginAccessValidationServiceTest.java index 6f5dadf0..67acab0e 100644 --- a/rc-auth/src/test/java/com/red/circle/auth/common/LoginAccessValidationServiceTest.java +++ b/rc-auth/src/test/java/com/red/circle/auth/common/LoginAccessValidationServiceTest.java @@ -98,11 +98,21 @@ public class LoginAccessValidationServiceTest { } @Test - public void allowTaiwanRegion() { + public void blockTaiwanRegion() { JSONObject data = JSON.parseObject(""" {"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)); } } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java index 7d58dea3..4ece76b9 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/utils/IpCountryUtils.java @@ -32,10 +32,10 @@ public class IpCountryUtils { "香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan" ); private static final List BLOCKED_COUNTRY_CODES = List.of( - "HK", "MO", "SG" + "HK", "MO", "SG", "TW" ); private static final List BLOCKED_COUNTRY_NAMES = List.of( - "香港", "澳门", "澳門", "Hong Kong", "Macau", "Macao", "新加坡", "Singapore" + "香港", "澳门", "澳門", "台湾", "台灣", "Hong Kong", "Macau", "Macao", "Taiwan", "新加坡", "Singapore" ); private static final List IP_GEO_PROVIDERS = List.of( new IpGeoProvider("ip.sb", "https://api.ip.sb/geoip/%s"), diff --git a/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/utils/IpCountryUtilsTest.java b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/utils/IpCountryUtilsTest.java index 2272368a..85dadffb 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/utils/IpCountryUtilsTest.java +++ b/rc-service/rc-service-other/other-infrastructure/src/test/java/com/red/circle/other/infra/utils/IpCountryUtilsTest.java @@ -91,9 +91,17 @@ public class IpCountryUtilsTest { } @Test - public void allowTaiwanRegion() { + public void blockTaiwanRegion() { 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)); } }