Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
357 changes: 180 additions & 177 deletions backend/cmd/map/handlers/json.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions backend/cmd/map/handlers/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,42 @@ func TestJSONChallengesFeedCacheServesL1AndInvalidates(t *testing.T) {
handler.invalidateFeed("challenges", jsonTestUUID)
require.Empty(t, fetch(), "invalidated feed should reflect the DB state")
}

func TestJSONWorldDominationFeedCacheKeysPerTeam(t *testing.T) {
handler, sessions, teamManager, userManager, challengeManager := newJSONWorldDominationHandler(t)
handler.feeds = &respCache{} // L1-only, network-free

require.NoError(t, teamManager.Create(teams.PlatformTeam{Model: gorm.Model{ID: 10}, Name: "Blue Team", UUID: jsonTestUUID, Active: true, Visible: true}))
require.NoError(t, teamManager.Create(teams.PlatformTeam{Model: gorm.Model{ID: 11}, Name: "Red Team", UUID: jsonTestUUID, Active: true, Visible: true}))
require.NoError(t, userManager.Create(users.PlatformUser{Username: "alice", TeamID: 10, Active: true, UUID: jsonTestUUID}))
require.NoError(t, userManager.Create(users.PlatformUser{Username: "bob", TeamID: 11, Active: true, UUID: jsonTestUUID}))
require.NoError(t, challengeManager.Create(challenges.Challenge{Model: gorm.Model{ID: 101}, Title: "One", Active: true, UUID: jsonTestUUID}))
require.NoError(t, challengeManager.Create(challenges.Challenge{Model: gorm.Model{ID: 102}, Title: "Two", Active: true, UUID: jsonTestUUID}))
// Blue Team has solved challenge 101.
require.NoError(t, teamManager.CreateScore(teams.TeamScore{TeamID: 10, ChallengeID: 101, Points: 100, UUID: jsonTestUUID, ScoredBy: "alice"}))

fetch := func(username string) JSONWorldDominationResponse {
req := newRequestWithUUID(http.MethodGet, "/json/domination", jsonTestUUID)
ctx, err := sessions.Load(req.Context(), "")
require.NoError(t, err)
sessions.Put(ctx, string(ContextKeyUser), username)
req = req.WithContext(ctx)
rr := httptest.NewRecorder()
handler.JSONWorldDominationHandler(rr, req)
require.Equal(t, http.StatusOK, rr.Code, "body: %s", rr.Body.String())
var resp JSONWorldDominationResponse
require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &resp))
return resp
}

// Alice's team has 1 completed; this misses and caches under (uuid, team 10).
require.Equal(t, 1, fetch("alice").CompletedChallenges)
// Bob's team has 0 completed; a shared cache would have leaked Alice's "1".
// A separate per-team key means this misses and computes 0.
require.Equal(t, 0, fetch("bob").CompletedChallenges, "per-team cache must not leak another team's result")

// Bob's team now solves a challenge, bypassing the cache (no invalidation wired for per-team feeds).
require.NoError(t, teamManager.CreateScore(teams.TeamScore{TeamID: 11, ChallengeID: 102, Points: 100, UUID: jsonTestUUID, ScoredBy: "bob"}))
// Cached read still returns the stale 0, proving the L1 cache served it.
require.Equal(t, 0, fetch("bob").CompletedChallenges, "cached feed should not reflect a bypassing DB write")
}
1 change: 0 additions & 1 deletion backend/cmd/map/handlers/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func TestStaticIncHTMLOnlyKeepsRuntimeModals(t *testing.T) {
removedModals := []string{
"action-error.html",
"action-save.html",
"command-line.html",
"forgot-login-password.html",
"login.html",
"scoreboard-final.html",
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/map/templates/img/bg--world.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion backend/cmd/map/templates/static/img/bg--world.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion backend/cmd/map/templates/static/img/team-logos/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion backend/cmd/map/templates/static/svg/icons/custom/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Loading
Loading