58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const root = path.join(__dirname, '..')
|
|
const { isE2eeEnvelope, opaquePreview } = require('../utils/e2ee')
|
|
|
|
const checks = []
|
|
const env = JSON.stringify({ v: 1, e2ee: true, iv: 'x', ciphertext: 'y' })
|
|
checks.push(['envelope detect', isE2eeEnvelope(env) === true])
|
|
checks.push(['opaque', opaquePreview(env).includes('رمزنگاری')])
|
|
checks.push(['plain', opaquePreview('سلام دنیا').includes('سلام')])
|
|
|
|
const idx = fs.readFileSync(path.join(root, 'index.js'), 'utf8')
|
|
checks.push(['socket jwt binding', idx.includes('socket.data.userId') && idx.includes('jwt.verify')])
|
|
checks.push(['sms disabled', idx.includes('status(410)')])
|
|
|
|
const routes = fs.readFileSync(path.join(root, 'routes/index.js'), 'utf8')
|
|
checks.push(['panel adminAuth', routes.includes("panel/users', [adminAuth]")])
|
|
|
|
const profile = fs.readFileSync(
|
|
path.join(root, 'controllers/application/profile/profileController.js'),
|
|
'utf8'
|
|
)
|
|
checks.push([
|
|
'profile strips secrets',
|
|
!profile.includes('password: user.password') && profile.includes('e2ee_public_key')
|
|
])
|
|
|
|
const userModel = fs.readFileSync(path.join(root, 'models/UserModel.js'), 'utf8')
|
|
checks.push(['user e2ee field', userModel.includes('e2ee_public_key')])
|
|
|
|
const roomModel = fs.readFileSync(path.join(root, 'models/ChatRoomModel.js'), 'utf8')
|
|
checks.push([
|
|
'room e2ee fields',
|
|
roomModel.includes('e2ee_wrapped_keys') && roomModel.includes('e2ee_enabled')
|
|
])
|
|
|
|
const frontRoot = path.join(root, '../modstagram-next/src/lib/e2ee')
|
|
const frontOk = ['dm.ts', 'room.ts', 'keys.ts', 'crypto.ts', 'envelope.ts'].every((f) =>
|
|
fs.existsSync(path.join(frontRoot, f))
|
|
)
|
|
checks.push(['front e2ee lib', frontOk])
|
|
|
|
const roomCtrl = fs.readFileSync(
|
|
path.join(root, 'controllers/application/chatRooms/chatRoomController.js'),
|
|
'utf8'
|
|
)
|
|
checks.push(['room membership gate', roomCtrl.includes('NOT_A_MEMBER')])
|
|
checks.push([
|
|
'room e2ee APIs',
|
|
roomCtrl.includes('getRoomE2eeKeys') && roomCtrl.includes('putRoomE2eeKeys')
|
|
])
|
|
|
|
for (const [name, ok] of checks) {
|
|
console.log(`${ok ? 'OK' : 'FAIL'} ${name}`)
|
|
}
|
|
if (checks.some(([, ok]) => !ok)) process.exit(1)
|
|
console.log('ALL CHECKS PASSED')
|