mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat: model asynchronous Steam auth sessions
This commit is contained in:
@@ -61,3 +61,51 @@ func TestSessionIsOpaqueShortLivedAndRevocable(t *testing.T) {
|
||||
t.Fatalf("expired session accepted: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthCoordinatorOnlyReleasesBackendVerifiedIdentity(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
verifier, _ := NewTicketVerifier(480)
|
||||
coordinator := NewAuthCoordinator()
|
||||
ticket := SteamTicket{TicketID: "ticket-1", SteamID: "steam-1", AppID: 480, ExpiresAt: now.Add(time.Minute)}
|
||||
if err := coordinator.Begin("attempt-1", ticket, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := coordinator.Get("attempt-1"); !errors.Is(err, ErrAuthAttemptPending) {
|
||||
t.Fatalf("pending identity exposed: %v", err)
|
||||
}
|
||||
if err := coordinator.Cancel("attempt-1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := coordinator.Complete("attempt-1", ticket, verifier, func(string) (string, bool) { return "player-1", true }, now); !errors.Is(err, ErrAuthAttemptRejected) {
|
||||
t.Fatalf("cancelled attempt completed: %v", err)
|
||||
}
|
||||
if err := coordinator.Begin("attempt-2", ticket, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wrongAttemptTicket := ticket
|
||||
wrongAttemptTicket.TicketID = "ticket-2"
|
||||
if _, err := coordinator.Complete("attempt-2", wrongAttemptTicket, verifier, func(string) (string, bool) { return "player-1", true }, now); !errors.Is(err, ErrAuthAttemptRejected) {
|
||||
t.Fatalf("wrong ticket completed: %v", err)
|
||||
}
|
||||
identity, err := coordinator.Complete("attempt-2", ticket, verifier, func(id string) (string, bool) { return "player-1", id == "steam-1" }, now)
|
||||
if err != nil || identity.PlayerID != "player-1" {
|
||||
t.Fatalf("verified identity = %+v err=%v", identity, err)
|
||||
}
|
||||
attempt, err := coordinator.Get("attempt-2")
|
||||
if err != nil || attempt.State != AuthAccepted || attempt.Identity != identity {
|
||||
t.Fatalf("accepted attempt = %+v err=%v", attempt, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthCoordinatorRejectsExpiredCompletion(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
verifier, _ := NewTicketVerifier(480)
|
||||
coordinator := NewAuthCoordinator()
|
||||
ticket := SteamTicket{TicketID: "ticket-1", SteamID: "steam-1", AppID: 480, ExpiresAt: now.Add(time.Second)}
|
||||
if err := coordinator.Begin("attempt-1", ticket, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := coordinator.Complete("attempt-1", ticket, verifier, func(string) (string, bool) { return "player-1", true }, now.Add(time.Second)); !errors.Is(err, ErrAuthAttemptRejected) {
|
||||
t.Fatalf("expired attempt completed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user