Hub 2.10.0: emails laid out as Events' and Accounts'; FastPanel ^~ /api/
- src/utils/emailLayout.js: one layout for every Hub email (Cross Code header with the logo, heading, button with the link under it, notes, tables, job steps, code blocks, footer), HTML and plain text from the same blocks, everything escaped. mail.sendMail attaches the logo. - Every email moved onto it: job reports, alerts, update requests, the SMTP test, notices, and all emails to site admins. Billing keeps its own. - The FastPanel email and the install page give the backend as nginx config with location ^~ /api/ (FastPanel's static-file rule took /api/...png). - Proxy done checks /api/proxy-check.png doesn't reach the frontend. - deployment.md: ^~ for the Hub's own /api/ too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// The Hub's email layout (2.10.0): HTML and plain text from the same blocks, everything escaped.
|
||||
const { render, logoAttachment } = require('../src/utils/emailLayout');
|
||||
const { notesBlocks } = require('../src/utils/jobs');
|
||||
|
||||
describe('render', () => {
|
||||
test('makes the HTML and its plain-text twin from the same blocks', () => {
|
||||
const { html, text } = render({
|
||||
heading: 'Installed',
|
||||
sub: 'Now set it up',
|
||||
blocks: [
|
||||
{ hello: 'Jane' },
|
||||
{ p: 'See https://hub.test/jobs/1 for more.' },
|
||||
{ note: { kind: 'warning', title: 'Careful', text: 'Two lines\nhere' } },
|
||||
{ rows: [['Site', 'events.hope.co.za'], ['Empty', null]] },
|
||||
{ steps: [{ outcome: 'ok', name: 'Backup' }, { outcome: 'failed', name: 'Migrate', detail: 'P3009' }] },
|
||||
{ numbered: [{ text: 'Add the site.' }, { text: 'Add this:', code: 'location ^~ /api/ {\n}' }] },
|
||||
{ code: 'line 1\nline 2', label: 'Last log lines' },
|
||||
{ button: { label: 'Open the job', url: 'https://hub.test/jobs/1' } },
|
||||
null,
|
||||
],
|
||||
});
|
||||
expect(text).toBe([
|
||||
'Installed', 'Now set it up', 'Hi Jane,', 'See https://hub.test/jobs/1 for more.', 'Careful\nTwo lines\nhere',
|
||||
'Site: events.hope.co.za', ' ✓ Backup\n ✗ Migrate (P3009)',
|
||||
'1. Add the site.\n\n2. Add this:\n\n location ^~ /api/ {\n }',
|
||||
'Last log lines:\nline 1\nline 2', 'Open the job: https://hub.test/jobs/1',
|
||||
].join('\n\n'));
|
||||
expect(html).toContain('<a href="https://hub.test/jobs/1" style="color:#1d6a9c;word-break:break-all">https://hub.test/jobs/1</a> for more.');
|
||||
expect(html).toContain('Two lines<br>here');
|
||||
expect(html).not.toContain('Empty');
|
||||
expect(html).toContain('location ^~ /api/ {');
|
||||
expect(html).toContain('>Open the job</a>');
|
||||
});
|
||||
|
||||
test('escapes everything and only links http(s)', () => {
|
||||
const { html } = render({
|
||||
heading: '<script>alert(1)</script>',
|
||||
blocks: [{ p: 'Tom & "Jerry" <b>' }, { button: { label: 'Go', url: 'javascript:alert(1)' } }, { code: '</pre><img src=x>' }],
|
||||
});
|
||||
expect(html).not.toContain('<script>');
|
||||
expect(html).toContain('<script>alert(1)</script>');
|
||||
expect(html).toContain('Tom & "Jerry" <b>');
|
||||
expect(html).not.toContain('href="javascript:');
|
||||
expect(html).toContain('href="#"');
|
||||
expect(html).toContain('</pre><img src=x>');
|
||||
});
|
||||
|
||||
test('shows the logo when there is one, through cid:logo', () => {
|
||||
const { html } = render({ heading: 'Hi', blocks: [] });
|
||||
if (logoAttachment()) {
|
||||
expect(html).toContain('src="cid:logo"');
|
||||
expect(logoAttachment()).toMatchObject({ cid: 'logo', contentType: 'image/png' });
|
||||
} else {
|
||||
expect(html).not.toContain('cid:logo');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('notesBlocks (What\'s New in the update email)', () => {
|
||||
test('lists, paragraphs, continuation lines, and no Markdown marks', () => {
|
||||
expect(notesBlocks('Works with any Accounts.\n\n- **Fix:** logo uploads\n failed with `x`.\n- Faster.\nAfter the list.')).toEqual([
|
||||
{ p: 'Works with any Accounts.' },
|
||||
{ bullets: ['Fix: logo uploads failed with x.', 'Faster.'] },
|
||||
{ p: 'After the list.' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -145,8 +145,33 @@ describe('jobs', () => {
|
||||
expect(await db.deployment.findUnique({ where: { id: deployment.id } })).toMatchObject({ status: 'waiting_for_proxy', version: '2.4.0' });
|
||||
expect(await db.job.findFirst({ where: { serverId: central.id, type: 'check-ports' } })).toMatchObject({ args: { ports: [20000, 20001] } });
|
||||
const mail = mockMails.find(m => m.subject.includes('Installed: hope'));
|
||||
expect(mail.text).toContain('/api → http://127.0.0.1:20001');
|
||||
expect(mail.text).toContain('everything else → http://127.0.0.1:20000');
|
||||
// 2.10.0: the backend location is ^~, so FastPanel's static-file rule can't take /api/…/logo.png.
|
||||
expect(mail.text).toContain('location ^~ /api/ {');
|
||||
expect(mail.text).toContain('proxy_pass http://127.0.0.1:20001;');
|
||||
expect(mail.text).toContain('as a proxy to http://127.0.0.1:20000 (the frontend)');
|
||||
expect(mail.html).toContain('location ^~ /api/ {');
|
||||
expect(mail.html).toContain('href="https://hub.test/servers/installs/');
|
||||
expect(await jobs.fastPanelText(await db.deployment.findUnique({ where: { id: deployment.id } }))).toContain(' location ^~ /api/ {');
|
||||
});
|
||||
|
||||
test('Proxy done refuses a site whose /api paths with a file extension reach the frontend', async () => {
|
||||
const { server } = await joinServer();
|
||||
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
|
||||
const { deployment } = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za', adminName: 'Jane', adminEmail: 'jane@hope.test' }, admin, NOW);
|
||||
const answer = (status, poweredBy, json) => ({ status, headers: new Headers(poweredBy ? { 'x-powered-by': poweredBy } : {}), json: async () => json });
|
||||
const site = frontendTakesFiles => async url => {
|
||||
if (url.endsWith('/api/health')) return answer(200, 'Express', { version: null });
|
||||
if (url.includes('/api/proxy-check.png')) return answer(404, frontendTakesFiles ? 'Next.js' : 'Express');
|
||||
return answer(200, 'Next.js');
|
||||
};
|
||||
const refused = await jobs.proxyDone(deployment.id, NOW, site(true));
|
||||
expect(refused.live).toBe(false);
|
||||
expect(refused.problems.join(' ')).toContain('location ^~ /api/');
|
||||
const ok = await jobs.proxyDone(deployment.id, NOW, site(false));
|
||||
expect(ok).toEqual({ live: true, problems: [] });
|
||||
const ready = mockMails.find(m => m.subject.includes('site is ready'));
|
||||
expect(ready.html).toContain('href="https://events.hope.co.za/setup"');
|
||||
expect(ready.text).toContain('Start the setup: https://events.hope.co.za/setup');
|
||||
});
|
||||
|
||||
test('a failed install frees its ports again', async () => {
|
||||
|
||||
Reference in New Issue
Block a user