Files
felhom.eu/hub/internal/web/selfbind_words_test.go
T

42 lines
1.7 KiB
Go

package web
import (
"fmt"
"strings"
"testing"
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
)
// W4 (rehearsal word table, night 2026-10-21): a wrong try says how many tries are left before the link locks — the
// fifth locks it and only support can open it. The count is the same for a wrong code and a wrong passphrase, so the
// no-oracle rule (TestSelfBind_B_NoOracle) holds.
// RED-PROOF: with AttemptsLeft not set on the failure render the „Még N" sentence is missing → fails at attempt 1.
func TestW4_AWrongTrySaysHowManyTriesAreLeft(t *testing.T) {
s, st := newTestServer(t)
selfBindSetup(t, st, "acme", testCode)
token := mintLink(t, st, "acme", selfBindTTL)
for i := 1; i < store.SelfBindMaxAttempts; i++ {
body := bindPOST(t, s, token, "ZZZ999", "definitely wrong words indeed").Body.String()
want := fmt.Sprintf("Még %d próbálkozásod van", store.SelfBindMaxAttempts-i)
if !strings.Contains(body, want) {
t.Fatalf("attempt %d: the page must say %q", i, want)
}
}
}
// W5: on a used or expired link the page says to use the newer mail before „Új linket kérek" (a new link kills the
// one the household may be about to use — TestSelfBind_C4_SingleActive).
func TestW5_AnOldLinkPointsToTheNewerMail(t *testing.T) {
s, st := newTestServer(t)
selfBindSetup(t, st, "acme", testCode)
token := mintLink(t, st, "acme", -1) // already expired
body := bindGET(t, s, token).Body.String()
if !strings.Contains(body, "újabb leveled") || !strings.Contains(body, "Új linket kérek") {
t.Fatalf("an expired link must point to the newer mail above the button: %q", body)
}
if strings.Index(body, "újabb leveled") > strings.Index(body, "Új linket kérek") {
t.Fatal("the newer-mail hint must come BEFORE the button")
}
}