Refractoring Stage 5 Completed channel-specific IPC validation
This commit is contained in:
@@ -16,6 +16,8 @@ test('validates supported IPC channels and their positional argument types', ()
|
||||
assert.throws(() => validateIpcArguments('mail:list-accounts', ['unexpected']), /Invalid argument count/);
|
||||
assert.doesNotThrow(() => validateIpcArguments('dav:sync', ['carddav']));
|
||||
assert.throws(() => validateIpcArguments('dav:sync', ['contacts']), /Invalid enum/);
|
||||
assert.throws(() => validateIpcArguments('mail:open-external', [`https://example.test/${'x'.repeat(2048)}`]), /too large/);
|
||||
assert.throws(() => validateIpcArguments('pgp:export-public', ['A'.repeat(65)]), /too large/);
|
||||
assert.throws(() => validateIpcArguments('unknown:channel', []), /Unknown IPC channel/);
|
||||
});
|
||||
|
||||
@@ -42,6 +44,31 @@ test('rejects non-finite numbers, cycles, and prototype-sensitive fields', () =>
|
||||
assert.throws(() => validateIpcArguments('mail:save-draft', [unsafe]), /Unsafe field/);
|
||||
});
|
||||
|
||||
test('validates channel-specific field shapes, limits, and enums', () => {
|
||||
assert.doesNotThrow(() => validateIpcArguments('mail:connect', [{
|
||||
email: 'user@example.test', password: 'secret', displayName: 'User',
|
||||
imapHost: 'imap.example.test', smtpHost: 'smtp.example.test',
|
||||
rules: [{ senderContains: 'alerts', action: 'flag', value: '' }]
|
||||
}]));
|
||||
assert.throws(() => validateIpcArguments('mail:connect', [{ rules: Array(51).fill({ action: 'flag' }) }]), /Invalid argument 1/);
|
||||
assert.throws(() => validateIpcArguments('mail:update-message', [{ uid: '4', action: 'star' }]), /uid/);
|
||||
assert.throws(() => validateIpcArguments('mail:update-message', [{ uid: 4, action: 'delete-anything' }]), /action/);
|
||||
assert.throws(() => validateIpcArguments('pgp:add-key-server', [{ name: 'Keys', url: 'https://keys.example.test', protocol: 'ftp' }]), /protocol/);
|
||||
assert.throws(() => validateIpcArguments('dav:save-event', [{ title: 'Event', _dav: { etag: 42 } }]), /_dav.etag/);
|
||||
});
|
||||
|
||||
test('prevents renderer-supplied raw SMTP messages while accepting standard compose fields', () => {
|
||||
assert.doesNotThrow(() => validateIpcArguments('mail:send', [{
|
||||
to: 'friend@example.test', cc: '', subject: 'Hello', text: 'Body',
|
||||
attachments: [{ filename: 'note.txt', contentBase64: 'aGVsbG8=' }],
|
||||
pgp: { encrypt: true, sign: false, passphrase: null }
|
||||
}]));
|
||||
assert.doesNotThrow(() => validateIpcArguments('pgp:decrypt-message', [{ folder: 'Inbox', uid: 4, passphrase: null }]));
|
||||
assert.throws(() => validateIpcArguments('mail:send', [{ rawBase64: 'YWJj', envelope: { to: ['victim@example.test'] } }]), /Unsupported message field/);
|
||||
assert.throws(() => validateIpcArguments('mail:send', [{ pgp: { encrypt: 'true' } }]), /pgp.encrypt/);
|
||||
assert.throws(() => validateIpcArguments('mail:send', [{ attachments: [{ contentBase64: 123 }] }]), /contentBase64/);
|
||||
});
|
||||
|
||||
test('every registered main-process IPC handler has a request schema', () => {
|
||||
const mainPath = path.resolve(__dirname, '..', 'desktop', 'main.cjs');
|
||||
const source = fs.readFileSync(mainPath, 'utf8');
|
||||
|
||||
Reference in New Issue
Block a user