mirror of https://github.com/dirtbags/moth.git
Don't map the "self" team in unauthenticated states
This commit is contained in:
parent
60d7192e04
commit
5fe464acbc
|
@ -183,13 +183,18 @@ func (mh *MothRequestHandler) exportStateIfRegistered(override bool) *StateExpor
|
||||||
registered := override || (err == nil)
|
registered := override || (err == nil)
|
||||||
|
|
||||||
export.Messages = mh.State.Messages()
|
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
|
// Anonymize team IDs in points log, and write out team names
|
||||||
pointsLog := mh.State.PointsLog()
|
pointsLog := mh.State.PointsLog()
|
||||||
exportIDs := map[string]string{mh.teamID: "self"}
|
exportIDs := make(map[string]string)
|
||||||
maxSolved := map[string]int{}
|
maxSolved := make(map[string]int)
|
||||||
export.PointsLog = make(award.List, len(pointsLog))
|
export.PointsLog = make(award.List, len(pointsLog))
|
||||||
|
|
||||||
|
if registered {
|
||||||
|
export.TeamNames["self"] = teamName
|
||||||
|
exportIDs[mh.teamID] = "self"
|
||||||
|
}
|
||||||
for logno, awd := range pointsLog {
|
for logno, awd := range pointsLog {
|
||||||
if id, ok := exportIDs[awd.TeamID]; ok {
|
if id, ok := exportIDs[awd.TeamID]; ok {
|
||||||
awd.TeamID = id
|
awd.TeamID = id
|
||||||
|
|
|
@ -64,24 +64,26 @@ func TestServer(t *testing.T) {
|
||||||
t.Error("index.html wrong contents", contents)
|
t.Error("index.html wrong contents", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
es := handler.ExportState()
|
{
|
||||||
if es.Config.Devel {
|
es := handler.ExportState()
|
||||||
t.Error("Marked as development server", es.Config)
|
if es.Config.Devel {
|
||||||
}
|
t.Error("Marked as development server", es.Config)
|
||||||
if len(es.Puzzles) != 1 {
|
}
|
||||||
t.Error("Puzzle categories wrong length")
|
if len(es.Puzzles) != 1 {
|
||||||
}
|
t.Error("Puzzle categories wrong length")
|
||||||
if es.Messages != "messages.html" {
|
}
|
||||||
t.Error("Messages has wrong contents")
|
if es.Messages != "messages.html" {
|
||||||
}
|
t.Error("Messages has wrong contents")
|
||||||
if len(es.PointsLog) != 0 {
|
}
|
||||||
t.Error("Points log not empty")
|
if len(es.PointsLog) != 0 {
|
||||||
}
|
t.Error("Points log not empty")
|
||||||
if len(es.TeamNames) != 1 {
|
}
|
||||||
t.Error("Wrong number of team names")
|
if len(es.TeamNames) != 1 {
|
||||||
}
|
t.Error("Wrong number of team names")
|
||||||
if es.TeamNames["self"] != teamName {
|
}
|
||||||
t.Error("TeamNames['self'] wrong")
|
if es.TeamNames["self"] != teamName {
|
||||||
|
t.Error("TeamNames['self'] wrong")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r, _, err := handler.PuzzlesOpen("pategory", 1, "moo.txt"); err != nil {
|
if r, _, err := handler.PuzzlesOpen("pategory", 1, "moo.txt"); err != nil {
|
||||||
|
@ -112,14 +114,16 @@ func TestServer(t *testing.T) {
|
||||||
|
|
||||||
time.Sleep(TestMaintenanceInterval)
|
time.Sleep(TestMaintenanceInterval)
|
||||||
|
|
||||||
es = handler.ExportState()
|
{
|
||||||
if len(es.PointsLog) != 1 {
|
es := handler.ExportState()
|
||||||
t.Error("I didn't get my points!")
|
if len(es.PointsLog) != 1 {
|
||||||
}
|
t.Error("I didn't get my points!")
|
||||||
if len(es.Puzzles["pategory"]) != 2 {
|
}
|
||||||
t.Error("The next puzzle didn't unlock!")
|
if len(es.Puzzles["pategory"]) != 2 {
|
||||||
} else if es.Puzzles["pategory"][1] != 2 {
|
t.Error("The next puzzle didn't unlock!")
|
||||||
t.Error("The 2-point puzzle should have unlocked!")
|
} 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 {
|
if r, _, err := handler.PuzzlesOpen("pategory", 2, "puzzle.json"); err != nil {
|
||||||
|
@ -138,20 +142,25 @@ func TestServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(TestMaintenanceInterval)
|
time.Sleep(TestMaintenanceInterval)
|
||||||
es = anonHandler.ExportState()
|
|
||||||
if len(es.TeamNames) != 2 {
|
{
|
||||||
t.Error("Anonymous TeamNames is wrong:", es.TeamNames)
|
es := anonHandler.ExportState()
|
||||||
}
|
if len(es.TeamNames) != 1 {
|
||||||
if len(es.PointsLog) != 2 {
|
t.Error("Anonymous TeamNames is wrong:", es.TeamNames)
|
||||||
t.Error("Points log wrong length")
|
}
|
||||||
}
|
if len(es.PointsLog) != 2 {
|
||||||
if es.PointsLog[1].TeamID != "0" {
|
t.Error("Points log wrong length")
|
||||||
t.Error("Second point log didn't anonymize team ID correctly:", es.PointsLog[1])
|
}
|
||||||
|
if es.PointsLog[1].TeamID != "0" {
|
||||||
|
t.Error("Second point log didn't anonymize team ID correctly:", es.PointsLog[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
es = handler.ExportState()
|
{
|
||||||
if len(es.TeamNames) != 1 {
|
es := handler.ExportState()
|
||||||
t.Error("TeamNames is wrong:", es.TeamNames)
|
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
|
// BUG(neale): We aren't currently testing the various ways to disable the server
|
||||||
|
|
Loading…
Reference in New Issue