Events 3.1.0, Accounts 1.2.0, contracts 1.9.0: the move needs Accounts' email
A church moved sign-in to Accounts without email set up there: codes and password links couldn't be sent, sign-in failed with a 500, nobody could get in. - contracts 1.9.0: messaging.status/test/set (SMTP, WAWP; secrets sealed); people.ensure answers emailSent. - Accounts 1.2.0: SendError instead of a 500; WhatsApp codes fall back to email; forgot password says email isn't set up; setup only offers methods that work; messaging.* (test, save only what worked); test WhatsApp in admin; WAWP from .env. - Events 3.1.0: Settings -> Sign-in shows what Accounts can send and copies this site's SMTP/WAWP into it (secrets stay on the server), test then save; Move disabled and refused (EMAIL_NOT_READY) without email. Tests: Accounts 54, contracts 218, Events 774, test:accounts 16 (also on Postgres). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,7 @@ const { signInGuard } = require('../../src/accounts/guard.ts');
|
||||
const { protect } = require('../../src/middleware/authMiddleware.js');
|
||||
const move = require('../../src/accounts/move.ts');
|
||||
const mode = require('../../src/accounts/mode.ts');
|
||||
const messaging = require('../../src/accounts/messaging.ts');
|
||||
const { setAuthClientLoader } = require('../../src/accounts/client.ts');
|
||||
|
||||
const EVENTS_ID = '6d1f0b2c-8a3e-4c5d-9e7f-1a2b3c4d5e6f';
|
||||
@@ -104,6 +105,10 @@ before(async () => {
|
||||
await h.db.productLink.create({ data: { installId: EVENTS_ID, product: 'events', url: eventsUrl, publicKey: ed25519PublicToPem(generateEd25519().publicKey), secret: h.ctx.secrets.encrypt(secret), connectedAt: new Date() } });
|
||||
await edb.productLink.create({ data: { installId: ACCOUNTS_ID, product: 'accounts', url: h.publicUrl, publicKey: 'x', secret: encrypt(secret), connectedAt: new Date(), updatedAt: new Date() } });
|
||||
await edb.appSetting.create({ data: { key: 'hub_install_id', value: EVENTS_ID } });
|
||||
// This site's own email settings (3.1.0: copied to Accounts before the move).
|
||||
for (const [key, value] of Object.entries({ smtp_host: 'smtp.hope.test', smtp_port: '587', smtp_secure: 'false', smtp_user: 'events@hope.test', smtp_pass: 'events-mail-pass', smtp_from: 'events@hope.test' })) {
|
||||
await edb.appSetting.create({ data: { key, value } });
|
||||
}
|
||||
|
||||
// Events' people before the move.
|
||||
await eventsUser({ id: ids.thandi, name: 'Thandi Mokoena', email: 'thandi@hope.test', password: await bcrypt.hash('Old-events-pass1', 4), newsEmail: true });
|
||||
@@ -143,6 +148,34 @@ async function signInThroughEvents(browser: Browser, email: string, password: st
|
||||
|
||||
const me = (token: string) => fetch(`${eventsUrl}/api/v2/me`, { headers: { authorization: `Bearer ${token}` } });
|
||||
|
||||
describe('Accounts\' email before the move (3.1.0)', () => {
|
||||
test('without email in Accounts, the check says so and the move is refused', async () => {
|
||||
(h.messenger as unknown as { emailOn: boolean }).emailOn = false;
|
||||
const r = await move.check();
|
||||
assert.equal(r.messaging.email, false);
|
||||
await assert.rejects(move.move({ actor: { id: ids.sam, role: 'admin' }, adminIds: [] }), (e: { code?: string }) => e.code === 'EMAIL_NOT_READY');
|
||||
mode.forgetMode();
|
||||
assert.equal(await mode.authMode(), 'local');
|
||||
});
|
||||
|
||||
test('this site\'s SMTP is copied (its own password, never sent to the page), tested, then saved in Accounts', async () => {
|
||||
const own = await messaging.eventsMessaging();
|
||||
assert.deepEqual(own.email, { host: 'smtp.hope.test', port: 587, secure: false, user: 'events@hope.test', from: 'events@hope.test', hasPass: true });
|
||||
const email = { host: own.email.host, port: own.email.port, secure: own.email.secure, user: own.email.user, from: own.email.from, pass: null, to: 'sam@hope.test' };
|
||||
const tested = await messaging.sendToAccounts({ email }, { save: false, actor: null });
|
||||
assert.deepEqual(tested.email, { ok: true, error: null, saved: false });
|
||||
const tried = (h.messenger as unknown as { tried: { settings: { pass: string } }[] }).tried.at(-1)!;
|
||||
assert.equal(tried.settings.pass, 'events-mail-pass', 'this site\'s own password, sealed on the way');
|
||||
assert.equal(await h.ctx.settings.get('smtp_host'), null, 'a test saves nothing');
|
||||
const saved = await messaging.sendToAccounts({ email }, { save: true, actor: null });
|
||||
assert.equal(saved.email.saved, true);
|
||||
assert.equal(await h.ctx.settings.get('smtp_pass'), 'events-mail-pass');
|
||||
// (The in-memory messenger stands for a working SMTP from here.)
|
||||
(h.messenger as unknown as { emailOn: boolean }).emailOn = true;
|
||||
assert.equal((await messaging.accountsMessaging()).email.ready, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('moving Events\' sign-in to Accounts', () => {
|
||||
test('the check counts people and writes nothing', async () => {
|
||||
const r = await move.check();
|
||||
|
||||
Reference in New Issue
Block a user