1
0

revocation_snapshot_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package tuic
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestAudit3ActualSessionRevokedAndSnapshotDrain(t *testing.T) {
  7. for _, operation := range []string{"remove", "password", "email", "uuid"} {
  8. t.Run(operation, func(t *testing.T) {
  9. server, conn, id, password := startLifecycleTestServer(t, "127.0.0.1:1", "old@audit3")
  10. _, user := authenticatedServerConnection(t, server, id)
  11. user.Traffic.BytesUp.Add(123)
  12. user.Traffic.BytesDown.Add(456)
  13. client := TuicClientSettings{UUID: id.String(), Password: password, Email: "old@audit3"}
  14. switch operation {
  15. case "password":
  16. client.Password = "rotated"
  17. case "email":
  18. client.Email = "new@audit3"
  19. case "uuid":
  20. client.UUID = "10000000-0000-0000-0000-000000000001"
  21. }
  22. if operation == "remove" {
  23. server.UpdateUsers(nil)
  24. } else {
  25. server.UpdateUsers([]TuicClientSettings{client})
  26. }
  27. select {
  28. case <-conn.Context().Done():
  29. case <-time.After(time.Second):
  30. t.Fatal("revoked QUIC remains connected")
  31. }
  32. deadline := time.Now().Add(time.Second)
  33. for user.sessions.Load() > 0 && time.Now().Before(deadline) {
  34. time.Sleep(time.Millisecond)
  35. }
  36. deltas := server.CollectClientTraffic()
  37. if len(deltas) != 1 || deltas[0].Email != "old@audit3" || deltas[0].UUID != id.String() || deltas[0].Up != 123 || deltas[0].Down != 456 {
  38. t.Fatalf("retired snapshot=%+v", deltas)
  39. }
  40. if again := server.CollectClientTraffic(); len(again) != 0 {
  41. t.Fatalf("double drain=%+v", again)
  42. }
  43. })
  44. }
  45. }