Don't map the "self" team in unauthenticated states

This commit is contained in:
Neale Pickett 2020-10-14 10:04:13 -06:00
parent 60d7192e04
commit 5fe464acbc
2 changed files with 55 additions and 41 deletions

View File

@ -183,13 +183,18 @@ func (mh *MothRequestHandler) exportStateIfRegistered(override bool) *StateExpor
registered := override || (err == nil)
export.Messages = mh.State.Messages()
export.TeamNames = map[string]string{"self": teamName}
inin export.TeamNames = make(map[string]string)
// Anonymize team IDs in points log, and write out team names
pointsLog := mh.State.PointsLog()
exportIDs := map[string]string{mh.teamID: "self"}
maxSolved := map[string]int{}
exportIDs := make(map[string]string)
maxSolved := make(map[string]int)
export.PointsLog = make(award.List, len(pointsLog))
if registered {
export.TeamNames["self"] = teamName
exportIDs[mh.teamID] = "self"
}
for logno, awd := range pointsLog {
if id, ok := exportIDs[awd.TeamID]; ok {
awd.TeamID = id

View File

@ -64,6 +64,7 @@ func TestServer(t *testing.T) {
t.Error("index.html wrong contents", contents)
}
{
es := handler.ExportState()
if es.Config.Devel {
t.Error("Marked as development server", es.Config)
@ -83,6 +84,7 @@ func TestServer(t *testing.T) {
if es.TeamNames["self"] != teamName {
t.Error("TeamNames['self'] wrong")
}
}
if r, _, err := handler.PuzzlesOpen("pategory", 1, "moo.txt"); err != nil {
t.Error(err)
@ -112,7 +114,8 @@ func TestServer(t *testing.T) {
time.Sleep(TestMaintenanceInterval)
es = handler.ExportState()
{
es := handler.ExportState()
if len(es.PointsLog) != 1 {
t.Error("I didn't get my points!")
}
@ -121,6 +124,7 @@ func TestServer(t *testing.T) {
} else if es.Puzzles["pategory"][1] != 2 {
t.Error("The 2-point puzzle should have unlocked!")
}
}
if r, _, err := handler.PuzzlesOpen("pategory", 2, "puzzle.json"); err != nil {
t.Error("Opening unlocked puzzle should work")
@ -138,8 +142,10 @@ func TestServer(t *testing.T) {
}
time.Sleep(TestMaintenanceInterval)
es = anonHandler.ExportState()
if len(es.TeamNames) != 2 {
{
es := anonHandler.ExportState()
if len(es.TeamNames) != 1 {
t.Error("Anonymous TeamNames is wrong:", es.TeamNames)
}
if len(es.PointsLog) != 2 {
@ -148,11 +154,14 @@ func TestServer(t *testing.T) {
if es.PointsLog[1].TeamID != "0" {
t.Error("Second point log didn't anonymize team ID correctly:", es.PointsLog[1])
}
}
es = handler.ExportState()
{
es := handler.ExportState()
if len(es.TeamNames) != 1 {
t.Error("TeamNames is wrong:", es.TeamNames)
}
}
// BUG(neale): We aren't currently testing the various ways to disable the server
}