fix: normalize admin config checksums

This commit is contained in:
youfak 2026-07-29 20:04:09 +08:00
parent 363d217c35
commit beaf4c9c38
2 changed files with 4 additions and 1 deletions

View File

@ -36,7 +36,7 @@ func Run(t *testing.T, factory Factory) {
func runConfigContract(t *testing.T, store adminstate.Store) { func runConfigContract(t *testing.T, store adminstate.Store) {
t.Helper() t.Helper()
command := configCommand("req-config", "cfg-1", strings.Repeat("a", adminstate.SHA256HexBytes)) command := configCommand("req-config", "cfg-1", strings.Repeat("ab", adminstate.SHA256HexBytes/2))
result, err := store.CommitConfig(context.Background(), command) result, err := store.CommitConfig(context.Background(), command)
if err != nil || !result.Changed || result.Revision != 1 || result.RequestID != command.RequestID { if err != nil || !result.Changed || result.Revision != 1 || result.RequestID != command.RequestID {
t.Fatalf("CommitConfig(first) = %+v, %v", result, err) t.Fatalf("CommitConfig(first) = %+v, %v", result, err)
@ -58,6 +58,7 @@ func runConfigContract(t *testing.T, store adminstate.Store) {
command.RequestID = "req-config-replay" command.RequestID = "req-config-replay"
command.OccurredAt = command.OccurredAt.Add(time.Second) command.OccurredAt = command.OccurredAt.Add(time.Second)
command.Checksum = strings.ToUpper(command.Checksum)
replayed, err := store.CommitConfig(context.Background(), command) replayed, err := store.CommitConfig(context.Background(), command)
if err != nil || replayed.Changed || replayed.Revision != 1 { if err != nil || replayed.Changed || replayed.Revision != 1 {
t.Fatalf("CommitConfig(replay) = %+v, %v", replayed, err) t.Fatalf("CommitConfig(replay) = %+v, %v", replayed, err)

View File

@ -6,6 +6,7 @@ import (
"math" "math"
"net/netip" "net/netip"
"sort" "sort"
"strings"
"sync" "sync"
"time" "time"
) )
@ -42,6 +43,7 @@ func (store *MemoryStore) CommitConfig(ctx context.Context, command CommitConfig
return result, ErrInvalidCommand return result, ErrInvalidCommand
} }
command = cloneCommitConfigCommand(command) command = cloneCommitConfigCommand(command)
command.Checksum = strings.ToLower(command.Checksum)
store.mu.Lock() store.mu.Lock()
defer store.mu.Unlock() defer store.mu.Unlock()