98678ff5a3
Three threads of work land here together to close out Tier 2.
### Block H follow-ups — day-of check-in
- Scanner is now an "open on your phone" magic-link flow. Hosts on
desktop mint a scoped JWT via POST /events/{id}/scanner-ticket and
render its URL into a QR; phone scans it and lands on /scanner with
the ticket as bearer. The ticket carries Audience=scanner so it can
never substitute for a session token.
- Plus-one confirmation at the door: scan → POST /check-in/preview to
fetch guest + expected party size → confirm buttons ("Just them",
"Party of N", custom) → POST /check-in. No more silent arrival_count=1.
- Offline scan queue: failed POSTs go into an IndexedDB store and drain
on the 'online' event with poison-message protection.
- Day-of arrivals headline widget on the event overview, gated to the
host's local calendar date so it doesn't dominate the page weeks out.
- Tab nav restyled with inline heroicons + scrollable segmented control;
Check-in moves to the rightmost slot.
- PWA: manifest + service worker scoped to /scanner, generated 192/512
icons (Go scripted renderer in scripts/gen-scanner-icons.go).
- Confirmation email QR was rendering broken because html/template
rewrites data: URLs to #ZgotmplZ; mark the value as template.URL.
- Email "open your invitation" link 404'd because we had no token to
put after /rsvp/. Threaded AccessLink through the RSVPConfirmed NATS
event from the API at submit time.
### Block G remainder — geolocation + threshold preview
- Pluggable GeoResolver in the fraud engine (NullResolver, IPApiResolver
for the free ip-api.com fallback, MaxMindResolver behind GG_GEOIP_DB_PATH).
Wrapped in a Redis cache (30d TTL). Geo flows through both gRPC and
NATS scoring paths.
- geo_jump scoring feature: >500km in <1h flags ("accessed from Lagos
and Paris within 12 minutes"); >500km in <6h is a softer signal. The
existing single-signal cap keeps a lone geo_jump in MEDIUM.
- FraudScored event carries geo_country/city/lat/lon; ApplyScore uses
COALESCE so a later re-score without geo doesn't wipe earlier data.
- Threshold-slider live preview: GET /events/{id}/security/thresholds/preview
returns band counts the host's existing access events would have
fallen into under the proposed thresholds. Debounced (250ms) widget
under the Advanced sliders so the host gets concrete feedback instead
of guessing.
### Cross-cutting — audit, tier-gating, feature flags
- audit_log table + internal/audit.Recorder (async fire-and-forget on
detached context so an audit blip never fails the real action). Wired
into branding update, thresholds update, allowlist add/remove,
collaborator invite/role-change/remove, message create/send-now/cancel.
- Tier-gating: extended billing.Limits with MaxCollaborators,
CustomBranding, Scanner, Broadcasts. Free = none; Pro = 5 + all;
Business = unlimited. Gates the scanner-ticket, message create,
branding put, and collaborator invite endpoints with 402 +
structured upgrade payload. Auto-reminders, fraud detection, and
analytics deliberately stay on every tier — those are safety + visibility
features, not upsell levers.
- Feature flags: feature_flags table + internal/flags.Store with 30s
in-memory refresh, stable sha256(key + user_id) percent bucketing,
unknown-key-defaults-on. Six Tier 2 flags pre-seeded. Three handlers
(branding, broadcasts, scanner) check the kill switch ahead of the
tier gate so ops can pull a feature back without a redeploy.
### Verified
- go test ./... + fraud-engine pytest (12/12 incl. 3 new geo_jump tests + 5
new flags tests).
- docker compose build + up across api, fraud-engine, notifier, frontend.
- /health endpoints 200; migrations 0014 + 0015 applied; 6 flags
seeded; audit_log table + partial indexes confirmed.
- Fraud-engine logs confirm geo resolver kind=CachedGeoResolver provider=auto.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
"""Integration test for the gRPC FraudService over an in-process channel."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import uuid4
|
|
|
|
import grpc
|
|
import pytest
|
|
|
|
from app.grpc_server import FraudServicer, serve_grpc, stop_grpc
|
|
from app.scoring import HeuristicScorer
|
|
from fraud.v1 import fraud_pb2, fraud_pb2_grpc
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_score_low_risk_first_access():
|
|
scorer = HeuristicScorer()
|
|
server = await serve_grpc(scorer, "127.0.0.1:0")
|
|
# add_insecure_port returns 0 so we need to fish out the actual bound port via _server's state.
|
|
# Easier: rebind on a known free port for the test.
|
|
await stop_grpc(server)
|
|
|
|
addr = "127.0.0.1:50951"
|
|
server = await serve_grpc(scorer, addr)
|
|
try:
|
|
async with grpc.aio.insecure_channel(addr) as channel:
|
|
stub = fraud_pb2_grpc.FraudServiceStub(channel)
|
|
resp = await stub.Score(
|
|
fraud_pb2.ScoreRequest(
|
|
event_id=str(uuid4()),
|
|
guest_id=str(uuid4()),
|
|
token_id=str(uuid4()),
|
|
access_log_id=str(uuid4()),
|
|
fingerprint={"ua": "Chrome", "platform": "macOS"},
|
|
ip_address="203.0.113.7",
|
|
user_agent="Mozilla/5.0",
|
|
),
|
|
timeout=2.0,
|
|
)
|
|
assert resp.score <= 30
|
|
assert resp.risk == fraud_pb2.RISK_LOW
|
|
finally:
|
|
await stop_grpc(server)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_score_high_risk_after_baseline_change():
|
|
scorer = HeuristicScorer()
|
|
addr = "127.0.0.1:50952"
|
|
server = await serve_grpc(scorer, addr)
|
|
try:
|
|
guest_id = str(uuid4())
|
|
async with grpc.aio.insecure_channel(addr) as channel:
|
|
stub = fraud_pb2_grpc.FraudServiceStub(channel)
|
|
|
|
await stub.Score(
|
|
fraud_pb2.ScoreRequest(
|
|
event_id=str(uuid4()),
|
|
guest_id=guest_id,
|
|
token_id=str(uuid4()),
|
|
access_log_id=str(uuid4()),
|
|
fingerprint={"ua": "Chrome"},
|
|
ip_address="203.0.113.7",
|
|
user_agent="Mozilla/5.0",
|
|
),
|
|
timeout=2.0,
|
|
)
|
|
|
|
resp = await stub.Score(
|
|
fraud_pb2.ScoreRequest(
|
|
event_id=str(uuid4()),
|
|
guest_id=guest_id,
|
|
token_id=str(uuid4()),
|
|
access_log_id=str(uuid4()),
|
|
fingerprint={"ua": "curl/8"},
|
|
ip_address="198.51.100.42",
|
|
user_agent="",
|
|
),
|
|
timeout=2.0,
|
|
)
|
|
assert resp.score >= 60
|
|
assert resp.risk in {fraud_pb2.RISK_HIGH, fraud_pb2.RISK_BLOCK}
|
|
finally:
|
|
await stop_grpc(server)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_invalid_uuid_returns_invalid_argument():
|
|
scorer = HeuristicScorer()
|
|
addr = "127.0.0.1:50953"
|
|
server = await serve_grpc(scorer, addr)
|
|
try:
|
|
async with grpc.aio.insecure_channel(addr) as channel:
|
|
stub = fraud_pb2_grpc.FraudServiceStub(channel)
|
|
with pytest.raises(grpc.RpcError) as excinfo:
|
|
await stub.Score(
|
|
fraud_pb2.ScoreRequest(
|
|
event_id="not-a-uuid",
|
|
guest_id=str(uuid4()),
|
|
token_id=str(uuid4()),
|
|
),
|
|
timeout=2.0,
|
|
)
|
|
assert excinfo.value.code() == grpc.StatusCode.INVALID_ARGUMENT
|
|
finally:
|
|
await stop_grpc(server)
|
|
|
|
|
|
def test_servicer_constructs():
|
|
# Ensures the servicer wires up against the generated stub.
|
|
FraudServicer(HeuristicScorer(), None)
|