Mail relay: development hosts are known by pattern, with no env - built in: *.dev.netscale.pl
The launch rule called a site non-public only when IAPL_NOINDEX was set (or the project named its hosts).
The owner's development sites set nothing, so production's database copied onto a development address
counted as a launch and would have mailed real people.
- iapl({ developmentHosts }): host patterns of development addresses. Default DEFAULT_DEVELOPMENT_HOSTS =
['*.dev.netscale.pl'], Intecion's own development domain; a project replaces the list or empties it.
mail.relay.developmentHosts overrides it for the mail service.
- a site whose host matches is non-public exactly as with IAPL_NOINDEX=1; either signal is enough
- siteNonPublicSignal, matchDevelopmentHost, isDevelopmentHost, pluginDevelopmentHosts exported
- panel state: nonPublicBy, nonPublicPattern; doctor: mail-non-public (info) names the signal
- every case of the launch table runs with no env on the built-in pattern
- docs, AGENT.md, skills, changelog draft
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
634908eb57
commit
14abf369da
+69
-8
@@ -18,13 +18,14 @@ import { RELAY_DEFAULTS, RELAY_SHORT_NAME } from '../src/modules/email/relay/co
|
||||
import { createFakeRelay } from '../src/modules/email/relay/fake.js'
|
||||
import { dropExpectedMail, expectMailTo, takeExpectedMail, withMailKind } from '../src/modules/email/relay/kinds.js'
|
||||
import { bareAddresses, buildRelayMessage, cleanSubject } from '../src/modules/email/relay/message.js'
|
||||
import { isPublicHost, relayHost, resolveRelayOptions } from '../src/modules/email/relay/options.js'
|
||||
import { isPublicHost, pluginDevelopmentHosts, relayHost, resolveRelayOptions } from '../src/modules/email/relay/options.js'
|
||||
import { mailPanelState } from '../src/modules/email/relay/panel.js'
|
||||
import { clearUnconfirmedRelayMessages, sendThroughRelay } from '../src/modules/email/relay/send.js'
|
||||
import { disconnectRelay, enrolRelay, forgetOtherHosts, getRelayStatus, provesToken, refreshRelayStatus, rotateRelayToken, setRelayToken, siteIsNonPublic } from '../src/modules/email/relay/session.js'
|
||||
import { disconnectRelay, enrolRelay, forgetOtherHosts, getRelayStatus, provesToken, refreshRelayStatus, rotateRelayToken, setRelayToken, siteIsNonPublic, siteNonPublicSignal } from '../src/modules/email/relay/session.js'
|
||||
import { holdNonce, otherRelayHosts, readRelayCandidate, readRelayStore, updateRelayStore } from '../src/modules/email/relay/store.js'
|
||||
import { NOTIFICATION_FALLBACK, NOTIFICATION_FALLBACK_PL } from '../src/modules/notifications/defaults.js'
|
||||
import { resolveFormMessage } from '../src/modules/notifications/resolveFormMessage.js'
|
||||
import { DEFAULT_DEVELOPMENT_HOSTS, isDevelopmentHost, matchDevelopmentHost } from '../src/modules/shared/developmentHosts.js'
|
||||
import { setRateLimitStore } from '../src/modules/shared/rateLimit.js'
|
||||
import { callConfirmRoute, relayPayload, relaySite } from './mailRelay/helpers.js'
|
||||
|
||||
@@ -711,19 +712,25 @@ describe('the token over time', () => {
|
||||
})
|
||||
|
||||
// The owner's sites: built and enrolled on a development address, then launched on the real domain. A
|
||||
// development or staging site says so itself (IAPL_NOINDEX=1, or a host in mail.relay.developmentHosts).
|
||||
const DEV = 'acme.dev.agency-example.com'
|
||||
const DEV_HOSTS = { developmentHosts: ['*.dev.agency-example.com'] }
|
||||
// development address is known by its host: the built-in pattern `*.dev.netscale.pl`, with NO environment
|
||||
// variable and no option (every test here runs with IAPL_NOINDEX empty unless it says otherwise).
|
||||
const DEV = 'acme.dev.netscale.pl'
|
||||
const DEV_HOSTS = {}
|
||||
const AGENCY = { developmentHosts: ['*.dev.agency-example.com'] }
|
||||
|
||||
test('before launch: the site on its development address, with an empty store, enrols and sends by itself', async () => {
|
||||
const dev = shared({ options: DEV_HOSTS, serverURL: `https://${DEV}` })
|
||||
expect(process.env.IAPL_NOINDEX).toBe('')
|
||||
expect(siteIsNonPublic(dev.payload, dev.options)).toBe(true)
|
||||
expect(siteNonPublicSignal(dev.payload, dev.options)).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
|
||||
expect(await mailPanelState({ payload: dev.payload }, dev.options)).toMatchObject({ nonPublic: true, nonPublicBy: 'development-host', nonPublicPattern: '*.dev.netscale.pl' })
|
||||
expect((await sendThroughRelay(dev.payload, dev.options, MESSAGE)).sent).toBe(true)
|
||||
expect(dev.fake.outbox[0].host).toBe(DEV)
|
||||
// the same with the switch such a site already has, and no option at all
|
||||
vi.stubEnv('IAPL_NOINDEX', '1')
|
||||
const noindex = relaySite({ fake: { allow: [HOST] } })
|
||||
expect(siteIsNonPublic(noindex.payload, noindex.options)).toBe(true)
|
||||
expect(siteNonPublicSignal(noindex.payload, noindex.options)).toEqual({ by: 'noindex' })
|
||||
expect(await mailPanelState({ payload: noindex.payload }, noindex.options)).toMatchObject({ nonPublic: true, nonPublicBy: 'noindex' })
|
||||
expect((await sendThroughRelay(noindex.payload, noindex.options, MESSAGE)).sent).toBe(true)
|
||||
})
|
||||
|
||||
@@ -849,6 +856,60 @@ describe('the token over time', () => {
|
||||
expect((await readRelayStore(production.payload)).token).toBe(token)
|
||||
})
|
||||
|
||||
test('the development pattern is a default a project can replace or empty — the plugin option, the mail option, the matcher', async () => {
|
||||
const at = (serverURL: string, custom?: object, own: Parameters<typeof resolveRelayOptions>[1] = {}) => {
|
||||
const site = relayPayload({ custom, serverURL })
|
||||
return siteNonPublicSignal(site.payload, resolveRelayOptions(site.payload, own)!)
|
||||
}
|
||||
// built in: Intecion's development domain, any depth, any case, with a port; nothing that merely looks like it
|
||||
expect(DEFAULT_DEVELOPMENT_HOSTS).toEqual(['*.dev.netscale.pl'])
|
||||
expect(at('https://acme.dev.netscale.pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
|
||||
expect(at('https://WWW.Acme.dev.netscale.pl:8443/pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
|
||||
for (const url of ['https://client.pl', 'https://dev.netscale.pl', 'https://acme.dev.netscale.pl.evil.example', 'https://acme-dev.netscale.pl', 'https://netscale.pl', 'http://localhost:3000']) {expect(at(url)).toBeNull()}
|
||||
// iapl({ developmentHosts }) replaces the list…
|
||||
const own = { iapl: { developmentHosts: ['*.preview.agency-example.com', 'staging.client.pl'] } }
|
||||
expect(at('https://x.preview.agency-example.com', own)).toEqual({ by: 'development-host', pattern: '*.preview.agency-example.com' })
|
||||
expect(at('https://staging.client.pl', own)).toEqual({ by: 'development-host', pattern: 'staging.client.pl' })
|
||||
expect(at('https://acme.dev.netscale.pl', own)).toBeNull()
|
||||
expect(pluginDevelopmentHosts(relayPayload({ custom: own }).payload)).toEqual(own.iapl.developmentHosts)
|
||||
// …`[]` empties it (the project's choice: then only IAPL_NOINDEX marks a copy)…
|
||||
expect(at('https://acme.dev.netscale.pl', { iapl: { developmentHosts: [] } })).toBeNull()
|
||||
// …and mail.relay.developmentHosts wins for the mail service
|
||||
expect(at('https://acme.dev.netscale.pl', own, { developmentHosts: ['acme.*'] })).toEqual({ by: 'development-host', pattern: 'acme.*' })
|
||||
expect(at('https://acme.dev.netscale.pl', undefined, { developmentHosts: [] })).toBeNull()
|
||||
// either signal is enough; the host is named first
|
||||
vi.stubEnv('IAPL_NOINDEX', '1')
|
||||
expect(at('https://client.pl')).toEqual({ by: 'noindex' })
|
||||
expect(at('https://acme.dev.netscale.pl')).toEqual({ by: 'development-host', pattern: '*.dev.netscale.pl' })
|
||||
vi.stubEnv('IAPL_NOINDEX', '')
|
||||
// the matcher alone
|
||||
expect(matchDevelopmentHost('https://a.dev.netscale.pl/x')).toBe('*.dev.netscale.pl')
|
||||
expect(isDevelopmentHost('a.b.dev.netscale.pl')).toBe(true)
|
||||
expect(isDevelopmentHost('a.dev.netscale.pl', [])).toBe(false)
|
||||
expect(isDevelopmentHost('', ['*'])).toBe(false)
|
||||
expect(matchDevelopmentHost('x.example.com', [' ', '*.Example.com '])).toBe('*.Example.com ')
|
||||
|
||||
// what emptying the list means: production's data on the development address is then a "launch", and sends
|
||||
const live = shared({ serverURL: 'https://client.pl' })
|
||||
await sendThroughRelay(live.payload, live.options, MESSAGE)
|
||||
const copy = live.another(`https://${DEV}`)
|
||||
expect(await sendThroughRelay(copy.payload, copy.options, MESSAGE)).toMatchObject({ cause: 'client-other-host', sent: false })
|
||||
expect((await sendThroughRelay(copy.payload, { ...copy.options, developmentHosts: [] }, MESSAGE)).sent).toBe(true)
|
||||
})
|
||||
|
||||
test('a developer\'s `localhost` on the production database, no env: refused before any call, nothing written', async () => {
|
||||
const production = shared({ serverURL: 'https://client.pl' })
|
||||
await sendThroughRelay(production.payload, production.options, MESSAGE)
|
||||
const before = everything(production.store)
|
||||
const requests = production.fake.requests.length
|
||||
const local = production.another('http://localhost:3000')
|
||||
const real = { ...local.options, ownUrl: false }
|
||||
expect(siteNonPublicSignal(local.payload, real)).toBeNull()
|
||||
expect(await sendThroughRelay(local.payload, real, { ...MESSAGE, to: '[email protected]' })).toMatchObject({ cause: 'host-not-allowed', code: 'relay-refused', sent: false })
|
||||
expect(production.fake.requests).toHaveLength(requests)
|
||||
expect(everything(production.store)).toBe(before)
|
||||
})
|
||||
|
||||
test('`www` and the bare domain are one site, also for a non-public one: neither holds the other', async () => {
|
||||
const apex = shared({ options: DEV_HOSTS, serverURL: `https://${DEV}` })
|
||||
const www = apex.another(`https://www.${DEV}`, DEV_HOSTS)
|
||||
@@ -893,10 +954,10 @@ describe('the token over time', () => {
|
||||
expect((await sendThroughRelay(waiting.payload, named, MESSAGE)).sent).toBe(true)
|
||||
expect((await readRelayStore(waiting.payload, 'example.net')).refusal).toBeFalsy()
|
||||
// a non-public copy with 'enrol': the project took the rule away
|
||||
const any = old.another('https://copy.dev.agency-example.com', { ...DEV_HOSTS, otherHosts: 'enrol' })
|
||||
const any = old.another('https://copy.dev.agency-example.com', { ...AGENCY, otherHosts: 'enrol' })
|
||||
expect((await sendThroughRelay(any.payload, any.options, MESSAGE)).sent).toBe(true)
|
||||
// a non-public copy that names SOME hosts as its own still stops for the others
|
||||
const partly = old.another('https://two.dev.agency-example.com', { ...DEV_HOSTS, otherHosts: ['example.com'] })
|
||||
const partly = old.another('https://two.dev.agency-example.com', { ...AGENCY, otherHosts: ['example.com'] })
|
||||
expect(await sendThroughRelay(partly.payload, partly.options, MESSAGE)).toMatchObject({ cause: 'client-other-host', sent: false })
|
||||
// …the panel shows that refusal from the store, and drops it the moment its reason is gone (no send needed)
|
||||
expect((await mailPanelState({ payload: partly.payload }, partly.options)).relay?.refusal).toMatchObject({ code: 'client-other-host' })
|
||||
|
||||
Reference in New Issue
Block a user