Files
coolify/resources/js/modal-confirmation.test.js
T
Andras Bacsai 6a59008cda fix(dns): lock DNS modal state and unquote modal confirmation args
Mark DNS proposals, conflicts and server IP properties as #[Locked] so
clients cannot tamper with them. Re-resolve the zone per hostname,
lowercase hostnames, validate record content server-side and use the
resource's team id for DNS lookups and jobs.

Move modal-confirmation submitAction parsing into a tested JS helper
that strips quotes and keeps commas, parentheses and escaped quotes
inside quoted arguments. Pass the hostname to replaceManagedDnsRecord
through it instead of Js::from.

Rework member-permission tests to open the real DNS dialog rather than
setting locked properties directly.
2026-09-30 10:23:51 +02:00

37 lines
1.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { parseSubmitAction } from './modal-confirmation.js';
test('keeps unquoted arguments as text, as the modal always passed them', () => {
assert.deepEqual(parseSubmitAction('delete(5)'), { method: 'delete', params: ['5'] });
assert.deepEqual(parseSubmitAction('changeSource(3, App\\Models\\GithubApp)'), {
method: 'changeSource',
params: ['3', 'App\\Models\\GithubApp'],
});
assert.deepEqual(parseSubmitAction('resetDefaultLabels(true)'), { method: 'resetDefaultLabels', params: ['true'] });
});
test('removes the quotes of quoted arguments', () => {
assert.deepEqual(parseSubmitAction("generateNginxConfiguration('spa')"), {
method: 'generateNginxConfiguration',
params: ['spa'],
});
assert.deepEqual(parseSubmitAction("replaceManagedDnsRecord('app.example.com', 4)"), {
method: 'replaceManagedDnsRecord',
params: ['app.example.com', '4'],
});
assert.deepEqual(parseSubmitAction('rename("staging")'), { method: 'rename', params: ['staging'] });
});
test('keeps commas, parentheses and escaped quotes inside quoted arguments', () => {
assert.deepEqual(parseSubmitAction("save('a, b', 'c)d', 'it\\'s')"), {
method: 'save',
params: ['a, b', 'c)d', "it's"],
});
});
test('passes no arguments for empty parentheses or a bare method name', () => {
assert.deepEqual(parseSubmitAction('cleanupDeleted()'), { method: 'cleanupDeleted', params: [] });
assert.deepEqual(parseSubmitAction('delete'), { method: 'delete', params: [] });
});