\Tests\FeatureLogDeniedTest

拒绝访问日志

被测对象:LogDeniedMiddleware::handle(统一捕获)+ UserConfigService 越权拦截(事件派发)+ LogDeniedController(管理端查询) 守护约定:401→未认证、403→权限不足(带目标权限码)、429→限流、越权拦截→类型 2; 登录失败/422/200 不记录;业务拦截已发事件不重复;非超管仅见本人行。

Summary

Methods
Properties
Constants
test_unauthorized_response_is_recorded()
test_forbidden_response_is_recorded_with_permission_code()
test_throttle_exception_is_recorded_and_rethrown()
test_non_denied_responses_are_skipped()
test_marked_request_is_not_double_recorded()
test_escalation_intercept_records_type_two()
test_denied_index_filters_search_and_scope()
No public properties found
No constants found
requireRedis()
buildCacheRegistry()
setUp()
No protected properties found
N/A
middleware()
user()
No private properties found
N/A

Methods

test_unauthorized_response_is_recorded()

test_unauthorized_response_is_recorded() : void

401 响应 → 未认证行(无用户,reason 取响应体 message)

test_forbidden_response_is_recorded_with_permission_code()

test_forbidden_response_is_recorded_with_permission_code() : void

403 响应 → 权限不足行(带路由推断的目标权限码与脱敏参数)

test_throttle_exception_is_recorded_and_rethrown()

test_throttle_exception_is_recorded_and_rethrown() : void

429 限流异常 → 限流行并原样重抛

test_non_denied_responses_are_skipped()

test_non_denied_responses_are_skipped() : void

非拒绝响应不记录:200 / 422 / 登录失败(api/login 401 由登录表专记)

test_marked_request_is_not_double_recorded()

test_marked_request_is_not_double_recorded() : void

业务拦截点已发事件(denied_logged 标记)→ 响应再经中间件不重复落库

test_escalation_intercept_records_type_two()

test_escalation_intercept_records_type_two() : void

UserConfigService 提权拦截 → 越权行(类型 2,操作者留痕),且不重复

test_denied_index_filters_search_and_scope()

test_denied_index_filters_search_and_scope() : void

拒绝日志分页:类型筛选 + 搜索命中;详情含脱敏参数;非超管仅见本人行

requireRedis()

requireRedis() : void

Redis 依赖探针:直连 Redis 的测试(限流/会话/验证码)在无 Redis 环境(如 CI) 跳过而非失败——其余用例不受影响。CI 可设 TEST_REQUIRE_REDIS=1 强制模式: Redis 不可达即失败而非跳过,安全回归套件不允许静默消失。

buildCacheRegistry()

buildCacheRegistry(array  $items) : void

建缓存注册表最小 schema(td_sys_cache)并灌入注册项。

测试跑 sqlite :memory:,生产迁移含 PostgreSQL 专属 DDL 跑不通(DataScopeServiceTest 同因自建 schema); 而 CacheManager::registry() 现已从数据库表读取——凡走注册表的测试(remember/get/key/失效推导) 必须在 setUp 先调用本方法,否则注册表为空、remember 未登记名会走「自动登记」路径。

Parameters

array $items

setUp()

setUp() : void

建拒绝表 + 最小 td_sys_user schema 并注册被测路由

middleware()

middleware() : \App\Http\Middleware\LogDeniedMiddleware

Returns

\App\Http\Middleware\LogDeniedMiddleware —

user()

user(string  $username, string  $realName, bool  $super) : \App\Models\SysUser

构造登录测试用户(库内行)

Parameters

string $username
string $realName
bool $super

Returns

\App\Models\SysUser —