How would you test WebSocket authentication, Origin validation, authorization and scalability?
Answer
Treat the opening connection and each application action as separate trust boundaries. Test missing, expired and revoked credentials; token or session changes while the socket is already open; unauthorized room, object and tenant subscriptions; and server-side revocation. Browser WebSocket handshakes carry Origin, so validate the intended origin policy, especially when cookies authenticate the socket, but do not confuse Origin validation with real authorization or CORS. For scale, model concurrent open connections, connection churn, messages per second, message sizes, fan-out, reconnect storms, slow consumers/backpressure, memory per socket, CPU, file descriptors, network throughput and proxy/load-balancer limits.
Strong answer includes
- connection and message-level authorization boundaries
- Origin validation is not a replacement for auth
- models both connection count and message/fan-out load
Practical example
A service handles 20,000 idle sockets successfully but crashes when one event is broadcast to all clients several times per second. A useful load test therefore varies fan-out and slow-consumer behavior instead of claiming capacity from idle connection count alone.