Files
archie/internal/pairing/hash_test.go
T
sam f73b2d1c8c feat: memory manager sync/prefetch/scan/shutdown + broad in-flight epic work
Checkpoint commit covering concurrent work across several archie-core-abg
epics to avoid losing in-progress state:

- Memory manager (18.7-18.16): background sync pipeline, prefetch with
  timeout, memory-write notification, threat scanning, shutdown drain
  with abandoned-write tracking, frozen snapshot pattern. Wired
  ScanContent and NotifyMemoryToolWrite into HandleToolCall so scanning
  and notification actually apply to writes, not just exist as unused
  primitives.
- Fixed a literal unresolved merge-conflict that had been committed to
  internal/memory/scrubber/scrubber.go.
- Tool provider/registry, MCP client/transport (stdio, HTTP, SSE),
  multimodal results, disclosure.
- Pairing device auth store, rate limiting.
- Gateway compression, session store, tasks.
- Various workflow, plugin host, and agentexec updates.
2026-07-27 03:34:46 +10:00

84 lines
2.0 KiB
Go

package pairing
import (
"testing"
)
func TestHashCodeProducesVerifiableHash(t *testing.T) {
hashed, err := HashCode("ABCD2345")
if err != nil {
t.Fatal(err)
}
if len(hashed.Salt) == 0 {
t.Error("Salt is empty")
}
if len(hashed.Hash) == 0 {
t.Error("Hash is empty")
}
if !hashed.Verify("ABCD2345") {
t.Error("Verify(correct code) = false, want true")
}
}
func TestHashCodeRejectsWrongCode(t *testing.T) {
hashed, err := HashCode("ABCD2345")
if err != nil {
t.Fatal(err)
}
if hashed.Verify("WRONGCOD") {
t.Error("Verify(wrong code) = true, want false")
}
}
func TestHashCodeUsesDistinctSaltsPerCall(t *testing.T) {
// Two hashes of the SAME code must differ -- otherwise the salt
// isn't actually random, which defeats its purpose (identical codes
// would produce identical hashes, leaking equality via a hash
// comparison / rainbow-table risk).
h1, err := HashCode("SAMECODE")
if err != nil {
t.Fatal(err)
}
h2, err := HashCode("SAMECODE")
if err != nil {
t.Fatal(err)
}
if string(h1.Salt) == string(h2.Salt) {
t.Error("two calls produced the same salt")
}
if string(h1.Hash) == string(h2.Hash) {
t.Error("two calls produced the same hash for the same code (salt not actually varying the digest)")
}
// But each must still verify against its own code.
if !h1.Verify("SAMECODE") || !h2.Verify("SAMECODE") {
t.Error("a hash failed to verify against the code it was created from")
}
}
func TestHashedCodeVerifyIsCaseSensitive(t *testing.T) {
hashed, err := HashCode("ABCD2345")
if err != nil {
t.Fatal(err)
}
if hashed.Verify("abcd2345") {
t.Error("Verify matched a lowercase variant of an uppercase code")
}
}
func TestHashedCodeVerifyEmptyInputDoesNotPanic(t *testing.T) {
hashed, err := HashCode("ABCD2345")
if err != nil {
t.Fatal(err)
}
if hashed.Verify("") {
t.Error("Verify(\"\") = true, want false")
}
}
func TestVerifyOnZeroValueHashedCodeDoesNotPanic(t *testing.T) {
var hashed HashedCode
if hashed.Verify("anything") {
t.Error("zero-value HashedCode.Verify should never return true")
}
}