Translate remaining Go source and overlay.html comments to English
Identifiers, comments, and log/console messages in auth.go, i18n.go, counter.go, totals.go, and overlay.html's script/CSS comments — the files the TLS commit didn't already touch. No functional changes. locales/*.json and overlay.html's own FALLBACK/data-i18n strings stay bilingual on purpose: that's end-user text for the overlay/panel, a different audience than the source code, served by the existing i18n system rather than this convention.
This commit is contained in:
1 parent
e9fe10f0f7
commit
5a2c3272e9
7 files changed
+213
-211
No files matched your search
+50
-48
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// arrancaHub levanta un hub con un token dado y devuelve su direccion.
|
||||
func arrancaHub(t *testing.T, token string) (*peerRegistry, string) {
|
||||
// startHub spins up a hub with a given token and returns its address.
|
||||
func startHub(t *testing.T, token string) (*peerRegistry, string) {
|
||||
t.Helper()
|
||||
reg := newPeerRegistry()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
@@ -26,92 +26,94 @@ func arrancaHub(t *testing.T, token string) (*peerRegistry, string) {
|
||||
|
||||
func peers(reg *peerRegistry) int { return len(reg.views()) }
|
||||
|
||||
// El token correcto entra y sus datos llegan.
|
||||
func TestTokenCorrectoEntra(t *testing.T) {
|
||||
reg, addr := arrancaHub(t, "el-bueno")
|
||||
// The correct token gets in and its data arrives.
|
||||
func TestCorrectTokenGetsIn(t *testing.T) {
|
||||
reg, addr := startHub(t, "the-right-one")
|
||||
c, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
if err := authenticate(c, config{Token: "el-bueno", clientID: "abc"}); err != nil {
|
||||
t.Fatalf("deberia haber autenticado: %v", err)
|
||||
if err := authenticate(c, config{Token: "the-right-one", clientID: "abc"}); err != nil {
|
||||
t.Fatalf("should have authenticated: %v", err)
|
||||
}
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "abc", Name: "Fulano", Deaths: 7})
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "abc", Name: "Somebody", Deaths: 7})
|
||||
if err := c.WriteText(msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
esperarHasta(t, func() bool { return peers(reg) == 1 }, "el peer nunca aparecio")
|
||||
waitUntil(t, func() bool { return peers(reg) == 1 }, "the peer never showed up")
|
||||
if got := reg.views()[0].Deaths; got != 7 {
|
||||
t.Fatalf("esperaba 7 muertes, dio %d", got)
|
||||
t.Fatalf("expected 7 deaths, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
// El token equivocado NO entra y no deja rastro.
|
||||
func TestTokenEquivocadoNoEntra(t *testing.T) {
|
||||
reg, addr := arrancaHub(t, "el-bueno")
|
||||
// The wrong token does NOT get in, and leaves no trace.
|
||||
func TestWrongTokenDoesNotGetIn(t *testing.T) {
|
||||
reg, addr := startHub(t, "the-right-one")
|
||||
c, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
_ = authenticate(c, config{Token: "el-malo", clientID: "x"})
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Intruso", Deaths: 999})
|
||||
_ = authenticate(c, config{Token: "the-wrong-one", clientID: "x"})
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Intruder", Deaths: 999})
|
||||
c.WriteText(msg)
|
||||
time.Sleep(700 * time.Millisecond)
|
||||
if peers(reg) != 0 {
|
||||
t.Fatalf("el hub acepto datos con el token equivocado: %+v", reg.views())
|
||||
t.Fatalf("the hub accepted data with the wrong token: %+v", reg.views())
|
||||
}
|
||||
}
|
||||
|
||||
// Mandar datos SIN autenticarse tampoco funciona.
|
||||
func TestSinAutenticarNoEntra(t *testing.T) {
|
||||
reg, addr := arrancaHub(t, "el-bueno")
|
||||
// Sending data WITHOUT authenticating doesn't work either.
|
||||
func TestUnauthenticatedDoesNotGetIn(t *testing.T) {
|
||||
reg, addr := startHub(t, "the-right-one")
|
||||
c, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Intruso", Deaths: 999})
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Intruder", Deaths: 999})
|
||||
c.WriteText(msg)
|
||||
time.Sleep(700 * time.Millisecond)
|
||||
if peers(reg) != 0 {
|
||||
t.Fatalf("el hub acepto datos sin autenticacion: %+v", reg.views())
|
||||
t.Fatalf("the hub accepted data with no authentication: %+v", reg.views())
|
||||
}
|
||||
}
|
||||
|
||||
// El token no viaja: lo unico que sale del peer es un HMAC del desafio.
|
||||
func TestElTokenNoViajaPorLaRed(t *testing.T) {
|
||||
_, addr := arrancaHub(t, "secreto-muy-secreto")
|
||||
// The token never travels: the only thing that leaves the peer is an
|
||||
// HMAC of the challenge.
|
||||
func TestTheTokenNeverTravelsOverTheWire(t *testing.T) {
|
||||
_, addr := startHub(t, "very-secret-secret")
|
||||
c, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
raw, err := c.ReadMessage() // el desafio
|
||||
raw, err := c.ReadMessage() // the challenge
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var ch authChallenge
|
||||
json.Unmarshal(raw, &ch)
|
||||
if ch.Nonce == "" {
|
||||
t.Fatal("el hub no mando desafio")
|
||||
t.Fatal("the hub didn't send a challenge")
|
||||
}
|
||||
reply, _ := json.Marshal(authReply{Type: "auth", ID: "x", Proof: proofFor("secreto-muy-secreto", ch.Nonce)})
|
||||
reply, _ := json.Marshal(authReply{Type: "auth", ID: "x", Proof: proofFor("very-secret-secret", ch.Nonce)})
|
||||
if string(reply) == "" {
|
||||
t.Fatal("respuesta vacia")
|
||||
t.Fatal("empty reply")
|
||||
}
|
||||
for _, b := range [][]byte{raw, reply} {
|
||||
if contiene(string(b), "secreto-muy-secreto") {
|
||||
t.Fatalf("el token aparece en el trafico: %s", b)
|
||||
if contains(string(b), "very-secret-secret") {
|
||||
t.Fatalf("the token shows up in the traffic: %s", b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Una respuesta capturada no sirve en otra conexion: el desafio cambia.
|
||||
func TestNoSePuedeRepetirUnaRespuestaVieja(t *testing.T) {
|
||||
reg, addr := arrancaHub(t, "el-bueno")
|
||||
// A captured response can't be replayed on another connection: the
|
||||
// challenge changes.
|
||||
func TestAnOldResponseCannotBeReplayed(t *testing.T) {
|
||||
reg, addr := startHub(t, "the-right-one")
|
||||
|
||||
c1, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
if err != nil {
|
||||
@@ -120,7 +122,7 @@ func TestNoSePuedeRepetirUnaRespuestaVieja(t *testing.T) {
|
||||
raw, _ := c1.ReadMessage()
|
||||
var ch1 authChallenge
|
||||
json.Unmarshal(raw, &ch1)
|
||||
proofViejo := proofFor("el-bueno", ch1.Nonce)
|
||||
oldProof := proofFor("the-right-one", ch1.Nonce)
|
||||
c1.Close()
|
||||
|
||||
c2, err := wsDial(addr, "/ws", 3*time.Second)
|
||||
@@ -132,43 +134,43 @@ func TestNoSePuedeRepetirUnaRespuestaVieja(t *testing.T) {
|
||||
var ch2 authChallenge
|
||||
json.Unmarshal(raw2, &ch2)
|
||||
if ch2.Nonce == ch1.Nonce {
|
||||
t.Fatal("el desafio se repitio entre conexiones: el nonce tiene que ser distinto")
|
||||
t.Fatal("the challenge repeated across connections: the nonce has to differ")
|
||||
}
|
||||
reply, _ := json.Marshal(authReply{Type: "auth", ID: "x", Proof: proofViejo})
|
||||
reply, _ := json.Marshal(authReply{Type: "auth", ID: "x", Proof: oldProof})
|
||||
c2.WriteText(reply)
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Repetidor", Deaths: 1})
|
||||
msg, _ := json.Marshal(peerMessage{Type: "state", ID: "x", Name: "Replayer", Deaths: 1})
|
||||
c2.WriteText(msg)
|
||||
time.Sleep(700 * time.Millisecond)
|
||||
if peers(reg) != 0 {
|
||||
t.Fatalf("el hub acepto una respuesta repetida: %+v", reg.views())
|
||||
t.Fatalf("the hub accepted a replayed response: %+v", reg.views())
|
||||
}
|
||||
}
|
||||
|
||||
// El token generado es aleatorio y de largo razonable.
|
||||
func TestTokenGeneradoEsFuerte(t *testing.T) {
|
||||
// The generated token is random and of a reasonable length.
|
||||
func TestGeneratedTokenIsStrong(t *testing.T) {
|
||||
testExeDir = t.TempDir()
|
||||
a, gen, err := resolveToken(config{})
|
||||
if err != nil || !gen {
|
||||
t.Fatalf("deberia haber generado uno: gen=%v err=%v", gen, err)
|
||||
t.Fatalf("should have generated one: gen=%v err=%v", gen, err)
|
||||
}
|
||||
if len(a) != tokenBytes*2 {
|
||||
t.Fatalf("largo inesperado: %d", len(a))
|
||||
t.Fatalf("unexpected length: %d", len(a))
|
||||
}
|
||||
// la segunda vez lo lee del archivo, no genera otro
|
||||
// the second time it reads it from the file, doesn't generate another
|
||||
b, gen2, _ := resolveToken(config{})
|
||||
if gen2 || a != b {
|
||||
t.Fatalf("deberia reusar el guardado: %q vs %q (gen=%v)", a, b, gen2)
|
||||
t.Fatalf("should reuse the saved one: %q vs %q (gen=%v)", a, b, gen2)
|
||||
}
|
||||
// y en otra instalacion sale distinto
|
||||
// and a different installation gets a different one
|
||||
testExeDir = t.TempDir()
|
||||
c, _, _ := resolveToken(config{})
|
||||
if c == a {
|
||||
t.Fatal("dos instalaciones generaron el mismo token")
|
||||
t.Fatal("two installations generated the same token")
|
||||
}
|
||||
testExeDir = ""
|
||||
}
|
||||
|
||||
func contiene(s, sub string) bool {
|
||||
func contains(s, sub string) bool {
|
||||
return len(sub) > 0 && len(s) >= len(sub) && (func() bool {
|
||||
for i := 0; i+len(sub) <= len(s); i++ {
|
||||
if s[i:i+len(sub)] == sub {
|
||||
@@ -179,7 +181,7 @@ func contiene(s, sub string) bool {
|
||||
})()
|
||||
}
|
||||
|
||||
func esperarHasta(t *testing.T, cond func() bool, msg string) {
|
||||
func waitUntil(t *testing.T, cond func() bool, msg string) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(4 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
|
||||
Reference in new issue
Block a user