MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestAuthFileUnchangedUsesHash

Function TestAuthFileUnchangedUsesHash

internal/watcher/watcher_test.go:596–624  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

594}
595
596func TestAuthFileUnchangedUsesHash(t *testing.T) {
597 tmpDir := t.TempDir()
598 authFile := filepath.Join(tmpDir, "sample.json")
599 content := []byte(`{"type":"demo"}`)
600 if err := os.WriteFile(authFile, content, 0o644); err != nil {
601 t.Fatalf("failed to write auth file: %v", err)
602 }
603
604 w := &Watcher{lastAuthHashes: make(map[string]string)}
605 unchanged, err := w.authFileUnchanged(authFile)
606 if err != nil {
607 t.Fatalf("unexpected error: %v", err)
608 }
609 if unchanged {
610 t.Fatal("expected first check to report changed")
611 }
612
613 sum := sha256.Sum256(content)
614 // Use normalizeAuthPath to match how authFileUnchanged looks up the key
615 w.lastAuthHashes[w.normalizeAuthPath(authFile)] = hexString(sum[:])
616
617 unchanged, err = w.authFileUnchanged(authFile)
618 if err != nil {
619 t.Fatalf("unexpected error: %v", err)
620 }
621 if !unchanged {
622 t.Fatal("expected hash match to report unchanged")
623 }
624}
625
626func TestAuthFileUnchangedEmptyAndMissing(t *testing.T) {
627 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 3

authFileUnchangedMethod · 0.95
normalizeAuthPathMethod · 0.95
hexStringFunction · 0.85

Tested by

no test coverage detected