Documentation
¶
Overview ¶
Package mailbox receives the confirmation mail a project sends when signup alone does not issue a session.
A project with email confirmation enabled is NOT a closed one. It admits anybody willing to receive a message, which on the open internet is anybody at all -- and every relation whose policy reads `TO authenticated` is reachable by that person. Without a mailbox the scan stops at "signup succeeded but no session was issued", which is honest but leaves the whole authenticated tier unmeasured on a large share of real projects.
Three properties this package must have, and each is a constraint rather than a preference:
- OPT-IN. It calls a third party, and the scan path is otherwise free of them. The operator asks for it by flag, exactly like -write.
- ONE ADDRESS PER PROJECT, derived deterministically, so a second scan reuses the first scan's identity instead of registering another account in somebody's user table.
- REMOVABLE. The inbox is residue this tool created, and residue it cannot remove is residue it must report.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UserFor ¶
UserFor derives the local part of the address for a project.
Deterministic on purpose. The alternative -- a random address per scan -- registers a fresh account every time the scanner runs, which turns a measurement into a slow leak of junk users into somebody's auth table. The hash keeps the project reference itself out of the address, since that address ends up stored in a third party's inbox list.
Types ¶
type AgentMail ¶
type AgentMail struct {
Key string
Client *client.Client
// Base is the API origin. A field so tests can point it at a stub; a scan
// never sets it.
Base string
}
AgentMail is api.agentmail.to.
Chosen after exercising every step against the live API rather than reading its description: authenticate, create an inbox, receive (the probe message arrived on the FIRST poll, under two seconds), read the body, recover the link, and DELETE the inbox afterwards.
The delete is why it is here. Two of the alternatives could not remove an address once created, which would have left a permanent artefact behind every confirm-required scan -- and this tool reports its own leftovers rather than hiding them, so there would have been nowhere honest to put it.
func (*AgentMail) Open ¶
Open creates the project's inbox, or re-opens the one a previous scan made.
The create is NOT idempotent, which is worth stating because the first version of this file asserted that it was. Creating a username that already exists returns 403 `already_exists`, not 200 -- so a second scan of the same project failed outright at the step whose entire purpose is reuse. The claim had been inferred from creating a FRESH name once and never testing the repeat, and a stub built to match the inference passed happily.
So: fetch first, create only if absent, and treat a create that loses a race as a fetch. That last case is not hypothetical -- two scans of one project started together would both see "absent" and both POST.
type Mailbox ¶
type Mailbox interface {
// Address is what to register with.
Address() string
// Await blocks until a message arrives carrying a link, or the deadline
// passes. It returns the FIRST link found, which is what a confirmation
// mail leads with.
Await(ctx context.Context, within time.Duration) (string, error)
// Close removes the mailbox. A provider that cannot remove one must say so
// rather than silently leaving it.
Close(ctx context.Context) error
}
Mailbox is one address, its inbound mail, and the ability to remove it.
type Provider ¶
type Provider interface {
// Name identifies the service in findings and diagnostics.
Name() string
// Open returns the mailbox for a project, creating it if needed. Called
// twice with the same project it must return the same address, so a repeat
// scan reuses one identity.
Open(ctx context.Context, project string) (Mailbox, error)
}
Provider hands out mailboxes.