优化后端鉴权与日志安全
This commit is contained in:
@@ -102,3 +102,27 @@ test('formatLogEntry prints nested detail blocks without ansi colors in file mod
|
||||
assert.match(text, /未登录或登录已失效/)
|
||||
assert.doesNotMatch(text, /\u001B\[/)
|
||||
})
|
||||
|
||||
test('formatLogEntry masks sensitive fields in inline and nested details', () => {
|
||||
const text = formatLogEntry({
|
||||
time: '2026-04-14T10:36:24.974Z',
|
||||
level: 'info',
|
||||
scope: '[security]',
|
||||
message: 'masked',
|
||||
pid: 4671,
|
||||
detail: {
|
||||
token: 'abcdef1234567890',
|
||||
authorization: 'Bearer abcdef1234567890',
|
||||
nested: {
|
||||
cookie: 'sessionid=abcdef1234567890',
|
||||
note: 'password=super-secret-value',
|
||||
},
|
||||
},
|
||||
}, { color: false })
|
||||
|
||||
assert.doesNotMatch(text, /abcdef1234567890/)
|
||||
assert.doesNotMatch(text, /super-secret-value/)
|
||||
assert.match(text, /abcdef\*\*\*\*567890/)
|
||||
assert.match(text, /Bearer\*\*\*\*567890/)
|
||||
assert.match(text, /password=super-\*\*\*\*-value/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user