Fix cron cwd for super_admin and harden IM channel job isolation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-10 10:00:59 +08:00
parent b35bfde557
commit b1bb0067a0
16 changed files with 714 additions and 49 deletions

View file

@ -11,6 +11,7 @@ import {
deliverRunToIm,
mirrorRunToSession,
jobVisibleToPeer,
assertDeliveryAllowedForIdentity,
} from '../lib/delivery.js'
test('normalizeDelivery defaults to dsh', () => {
@ -439,3 +440,17 @@ test('formatRunResultBody matches IM delivery header', () => {
const en = formatRunResultBody({ name: 'Daily' }, 'ok', 'en')
assert.match(en, /^\[Scheduled tasks · Daily\]\n/)
})
test('assertDeliveryAllowedForIdentity blocks non-admin web IM delivery', () => {
const im = { kind: 'im', botId: 'b', targetId: 't' }
assert.equal(
assertDeliveryAllowedForIdentity(im, { empNo: 'a1', permissions: { canViewAllSessions: true } }),
im,
)
assert.doesNotThrow(() => assertDeliveryAllowedForIdentity(im, { empNo: '__local__', permissions: { canViewAllSessions: true } }))
assert.throws(
() => assertDeliveryAllowedForIdentity(im, { empNo: 'u1', permissions: { canViewAllSessions: false } }),
(error) => error.code === 'IM_DELIVERY_FORBIDDEN',
)
assert.doesNotThrow(() => assertDeliveryAllowedForIdentity({ kind: 'dsh' }, { empNo: 'u1', permissions: {} }))
})