mirror of
https://github.com/warmbly/warmbly.git
synced 2026-12-04 00:06:18 +00:00
* feat: give an organization one fused abuse posture, because every existing control watches a single subject and an actor slightly wrong on several axes sits under all of them: organizations gains risk_state, risk_score, risk_reason and an append-only risk_signals evidence blob, modelled on the warmup participant health machine that already works rather than a second vocabulary for the same idea; restricted cuts per-mailbox cold volume to a quarter and forces the free warmup pool so a risky tenant cannot spend the paid pool's shared reputation, suspended stops sending at the send gate, and watch deliberately changes nothing a customer can feel so evidence accumulates before anything is taken away; an operator's suspension outranks the derived band so a detector clearing cannot release a workspace a human suspended, transitions ride the audit spine to every teammate's dashboard, a banner says which limit is active and why rather than letting volume drop silently, and the posture never travels in a workspace archive since it is one platform's verdict reached from evidence the destination never saw * feat: make the suspension actually stop sending, and emit the audit transitions the PR claimed: emailsend.SendEmail is only the manual and API path, so campaign and warmup sends went nowhere near the gate and a suspended workspace kept sending on its schedule, while the restricted multiplier floored every mailbox at one a day which quietly turned suspension into a trickle rather than a stop; the campaign scheduler now defers the whole campaign with a reason and the warmup task skips as org-suspended, since warmup is outbound mail from the same domains; separately the band change emitted no audit entry at all despite the entity type and the frontend spine entry both existing, so no banner moved for a teammate and there was no trail of who was restricted when, and only a real transition is logged so a detector re-recording the same finding cannot fill the feed; one of my own live tests also asserted how far out a slot lands, which depends on the hour the suite runs, and now asserts the property it was about * feat: capture and score a signup's origin instead of discarding it * feat: document what a signup records, and prove the origin write is on the account path with a seam test rather than only testing the scorer * chore: drop the em dashes and trim the comments the review flagged
121 lines
3.9 KiB
Go
121 lines
3.9 KiB
Go
package signuprisk
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestScoreDisposableIsTheStrongestSignal(t *testing.T) {
|
|
got := Score("someone@mailinator.com", "203.0.113.5")
|
|
if !got.Disposable {
|
|
t.Error("a known throwaway domain was not flagged")
|
|
}
|
|
if got.Score < weightDisposable {
|
|
t.Errorf("score = %d, want at least %d", got.Score, weightDisposable)
|
|
}
|
|
if len(got.Reasons) == 0 {
|
|
t.Error("a flagged signup produced no reason for review")
|
|
}
|
|
}
|
|
|
|
// The failure that matters most: flagging ordinary customers. A business on
|
|
// Gmail is completely normal and must score clean.
|
|
func TestScoreOrdinarySignupsAreClean(t *testing.T) {
|
|
for _, email := range []string{
|
|
"ada@acme.com",
|
|
"ada@gmail.com",
|
|
"ada.lovelace@outlook.com",
|
|
"sales@some-startup.io",
|
|
"ada@sub.domain.co.uk",
|
|
} {
|
|
got := Score(email, "203.0.113.5")
|
|
if got.Score != 0 {
|
|
t.Errorf("Score(%q) = %d with %v, want 0", email, got.Score, got.Reasons)
|
|
}
|
|
if got.Disposable {
|
|
t.Errorf("Score(%q) flagged a real provider as disposable", email)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestScoreWeakSignals(t *testing.T) {
|
|
// A tagged address at a free provider is weak, not damning.
|
|
tagged := Score("ada+signup7@gmail.com", "203.0.113.5")
|
|
if tagged.Score == 0 {
|
|
t.Error("a tagged free-provider address scored nothing")
|
|
}
|
|
if tagged.Score >= weightDisposable {
|
|
t.Errorf("a tagged address scored %d, which should be well below a disposable domain", tagged.Score)
|
|
}
|
|
// The same tag on a company domain is just someone's mail routing.
|
|
if own := Score("ada+signup@acme.com", "203.0.113.5"); own.Score != 0 {
|
|
t.Errorf("a tagged address on a company domain scored %d, want 0", own.Score)
|
|
}
|
|
|
|
if malformed := Score("not-an-email", "203.0.113.5"); malformed.Score == 0 {
|
|
t.Error("an address with no domain scored nothing")
|
|
}
|
|
if noIP := Score("ada@acme.com", ""); noIP.Score == 0 {
|
|
t.Error("a signup with no source address scored nothing")
|
|
}
|
|
}
|
|
|
|
func TestScoreIsCapped(t *testing.T) {
|
|
if got := Score("a+b@mailinator.com", ""); got.Score > 100 {
|
|
t.Errorf("score = %d, want it capped at 100", got.Score)
|
|
}
|
|
}
|
|
|
|
// Normalize exists so one person cannot open several accounts that look
|
|
// unrelated. It must not merge genuinely different addresses.
|
|
func TestNormalize(t *testing.T) {
|
|
tests := []struct{ in, want string }{
|
|
{"Ada.Lovelace+signup@gmail.com", "adalovelace@gmail.com"},
|
|
{"ada.lovelace@googlemail.com", "adalovelace@gmail.com"},
|
|
{"ADA@ACME.COM", "ada@acme.com"},
|
|
{"ada+tag@acme.com", "ada@acme.com"},
|
|
// Dots are only ignored by Google. Stripping them everywhere would
|
|
// merge two different people at providers that treat them as distinct.
|
|
{"ada.lovelace@acme.com", "ada.lovelace@acme.com"},
|
|
{"first.last@outlook.com", "first.last@outlook.com"},
|
|
{"garbage", "garbage"},
|
|
}
|
|
for _, tt := range tests {
|
|
if got := Normalize(tt.in); got != tt.want {
|
|
t.Errorf("Normalize(%q) = %q, want %q", tt.in, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPrivateIP(t *testing.T) {
|
|
for _, ip := range []string{"127.0.0.1", "10.1.2.3", "192.168.1.1", "172.16.0.1", "::1", "169.254.1.1"} {
|
|
if !PrivateIP(ip) {
|
|
t.Errorf("PrivateIP(%q) = false, want true", ip)
|
|
}
|
|
}
|
|
for _, ip := range []string{"203.0.113.5", "8.8.8.8", "", "nonsense"} {
|
|
if PrivateIP(ip) {
|
|
t.Errorf("PrivateIP(%q) = true, want false", ip)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A self-hosted install signing up over a LAN is the normal case, so a private
|
|
// address must not add risk.
|
|
func TestPrivateAddressesAreNotPenalised(t *testing.T) {
|
|
lan := Score("ada@acme.com", "192.168.1.50")
|
|
public := Score("ada@acme.com", "203.0.113.5")
|
|
if lan.Score != public.Score {
|
|
t.Errorf("LAN signup scored %d vs %d for a public address", lan.Score, public.Score)
|
|
}
|
|
}
|
|
|
|
func TestReasonsAreHumanReadable(t *testing.T) {
|
|
got := Score("x@mailinator.com", "")
|
|
for _, r := range got.Reasons {
|
|
if strings.TrimSpace(r) == "" || strings.ToLower(r) != r && strings.ToUpper(r) == r {
|
|
t.Errorf("reason %q is not a readable sentence", r)
|
|
}
|
|
}
|
|
}
|