|
|
@@ -64,6 +64,15 @@ class AuthGuardAnonymousContractTest {
|
|
|
"com.etotem.cfc.filter.JwtInterceptor"
|
|
|
};
|
|
|
|
|
|
+ /** 5 个缺陷守卫端点(B-227-1 ×3 + B-315-1 ×2):契约要求匿名一律 401/403。 */
|
|
|
+ private static final String[] GUARDED_ENDPOINTS = {
|
|
|
+ "/api/notification/list",
|
|
|
+ "/api/notification/read",
|
|
|
+ "/api/search/global",
|
|
|
+ "/api/coupon/list",
|
|
|
+ "/api/coupon/claim"
|
|
|
+ };
|
|
|
+
|
|
|
// ==================================================================
|
|
|
// 正常流 · 对照基线(当前已实现 · GREEN,证明测试装置有效)
|
|
|
// ==================================================================
|
|
|
@@ -75,6 +84,22 @@ class AuthGuardAnonymousContractTest {
|
|
|
assertAnonymousRejected(clazz, "/api/user/info", "CONTROL");
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ @DisplayName("基线:对照端点(U05~U09)匿名 POST 必须被拒绝 → 401(证明拦截器整体在工作,非全站失守)")
|
|
|
+ void controlPrivateEndpoints_匿名应被拒绝() throws Exception {
|
|
|
+ Class<?> clazz = requireInterceptorClass();
|
|
|
+ String[] controls = {
|
|
|
+ "/api/family/member/list", // TC-AU-U05
|
|
|
+ "/api/growth/record/list", // TC-AU-U06
|
|
|
+ "/api/mind/fortune", // TC-AU-U07
|
|
|
+ "/api/reward/estimate", // TC-AU-U08
|
|
|
+ "/api/admin/parse-monitor/overview" // TC-AU-U09
|
|
|
+ };
|
|
|
+ for (String path : controls) {
|
|
|
+ assertAnonymousRejected(clazz, path, "CONTROL(" + path + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
@DisplayName("基线:JwtInterceptor 类可定位(候选 FQCN / 简单名扫描)")
|
|
|
void jwtInterceptor_classLocatable() {
|
|
|
@@ -159,6 +184,31 @@ class AuthGuardAnonymousContractTest {
|
|
|
"设计 §3.2:券领取为用户私有写,必须收录(或 /api/coupon/ 前缀)");
|
|
|
}
|
|
|
|
|
|
+ // ==================================================================
|
|
|
+ // 结构流:5 个守卫端点不得被「改成公开」假修复(当前 GREEN,防绕过)
|
|
|
+ // ==================================================================
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("结构:5 个缺陷守卫端点不得出现在 PUBLIC_PATHS(防『改白名单』假修复)")
|
|
|
+ void publicPaths_不得收录五个守卫端点() throws Exception {
|
|
|
+ Class<?> clazz = requireInterceptorClass();
|
|
|
+ Field field = clazz.getDeclaredField("PUBLIC_PATHS");
|
|
|
+ field.setAccessible(true);
|
|
|
+ Object value = field.get(null);
|
|
|
+ assertNotNull(value, "[auth.guard.anonymous] JwtInterceptor.PUBLIC_PATHS 字段为 null。");
|
|
|
+
|
|
|
+ String[] paths = (String[]) value;
|
|
|
+ for (String endpoint : GUARDED_ENDPOINTS) {
|
|
|
+ for (String p : paths) {
|
|
|
+ String boundary = p.endsWith("/**") ? p.substring(0, p.length() - 3) : p;
|
|
|
+ boolean publicMatch = endpoint.equals(p) || endpoint.startsWith(boundary + "/");
|
|
|
+ assertFalse(publicMatch,
|
|
|
+ "[auth.guard.anonymous] " + endpoint + " 不得出现在 PUBLIC_PATHS(命中 " + p
|
|
|
+ + "):契约要求匿名 401,公开放行会绕过登录门禁。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// ==================================================================
|
|
|
// helpers
|
|
|
// ==================================================================
|