diff options
Diffstat (limited to 'internal/game/login_offowner_regression_test.go')
| -rw-r--r-- | internal/game/login_offowner_regression_test.go | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/internal/game/login_offowner_regression_test.go b/internal/game/login_offowner_regression_test.go index fa8324c..4826c4c 100644 --- a/internal/game/login_offowner_regression_test.go +++ b/internal/game/login_offowner_regression_test.go @@ -6,8 +6,6 @@ package game // transition on the owner. The observable login behavior is unchanged. import ( - "crypto/sha256" - "encoding/base64" "strings" "testing" "time" @@ -29,26 +27,13 @@ func waitForOutput(t *testing.T, conn *chanConn, substr string) { } } -// TestLoginThroughServerEntryUsesOffOwnerPathAndUpgradesLegacyHash drives -// the real server entry point (HandleSessionOnOwner) through: legacy-hash -// account creation, a WRONG password attempt, and a correct login that -// rehashes the legacy SHA-256 hash to Argon2id durably. -func TestLoginThroughServerEntryUsesOffOwnerPathAndUpgradesLegacyHash(t *testing.T) { +// TestLoginThroughServerEntryUsesOffOwnerPath drives the real server entry +// point (HandleSessionOnOwner) through a WRONG password attempt and a correct +// login, exercising the off-owner verification path. +func TestLoginThroughServerEntryUsesOffOwnerPath(t *testing.T) { h := newHarness(t) h.seedAccount("alice") h.seedCharacter("alice", "alice") - acc, err := h.g.AccountStore.LoadAccount("alice") - if err != nil { - t.Fatal(err) - } - // Downgrade to a legacy salted SHA-256 hash so the login exercises the - // transparent rehash. - salt := []byte("0123456789abcdef") - sum := sha256.Sum256(append(append([]byte{}, salt...), []byte("pw")...)) - acc.PasswordHash = "sha256:" + base64.RawStdEncoding.EncodeToString(salt) + ":" + strings.ToLower(sha256HashHex(sum)) - if err := h.g.AccountStore.SaveAccount(acc); err != nil { - t.Fatal(err) - } conn := newChanConn() sess := &net.Session{Conn: conn} @@ -67,15 +52,12 @@ func TestLoginThroughServerEntryUsesOffOwnerPathAndUpgradesLegacyHash(t *testing if sess.Account == nil || sess.Account.Name != "alice" || len(sess.Account.Characters) != 1 { t.Fatalf("login did not complete: %+v", sess.Account) } - upgraded, err := h.g.AccountStore.LoadAccount("alice") + loaded, err := h.g.AccountStore.LoadAccount("alice") if err != nil { t.Fatal(err) } - if !strings.HasPrefix(upgraded.PasswordHash, "argon2id:") { - t.Errorf("legacy hash not upgraded on login: %s", upgraded.PasswordHash[:12]) - } - if !player.CheckPassword("pw", upgraded.PasswordHash) { - t.Error("upgraded hash no longer verifies the password") + if !player.CheckPassword("pw", loaded.PasswordHash) { + t.Error("stored hash no longer verifies the password") } } @@ -111,14 +93,3 @@ func TestNewAccountThroughServerEntryHashesOffOwner(t *testing.T) { t.Error("created hash does not verify the password") } } - -// sha256HashHex formats like hex.EncodeToString for the legacy hash check. -func sha256HashHex(sum [32]byte) string { - const hexdigits = "0123456789abcdef" - out := make([]byte, 64) - for i, b := range sum { - out[i*2] = hexdigits[b>>4] - out[i*2+1] = hexdigits[b&0x0f] - } - return string(out) -} |
