perf: sync protocol and core hardening updates
This commit is contained in:
parent
152fed3b87
commit
4390ebf5a9
283 changed files with 29231 additions and 2295 deletions
|
|
@ -13,6 +13,7 @@ func TestCodeStoreScopedRotationAndSingleConsume(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
codes := NewCodeStore()
|
||||
rec := store.PhoneCode{
|
||||
Version: store.PhoneCodeVersionCurrent,
|
||||
Phone: "15550015001",
|
||||
Code: "12345",
|
||||
Purpose: store.PhoneCodePurposeChangePhone,
|
||||
|
|
@ -68,7 +69,7 @@ func TestCodeStoreScopedRotationAndSingleConsume(t *testing.T) {
|
|||
func TestCodeStoreScopedIsolation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
codes := NewCodeStore()
|
||||
a := store.PhoneCode{Phone: "15550015002", Code: "12345", Purpose: store.PhoneCodePurposeChangePhone, UserID: 42, AuthKeyID: [8]byte{1}}
|
||||
a := store.PhoneCode{Version: store.PhoneCodeVersionCurrent, Phone: "15550015002", Code: "12345", Purpose: store.PhoneCodePurposeChangePhone, UserID: 42, AuthKeyID: [8]byte{1}}
|
||||
b := a
|
||||
b.AuthKeyID = [8]byte{2}
|
||||
if err := codes.Set(ctx, "hash-a", a, time.Minute); err != nil {
|
||||
|
|
@ -90,3 +91,24 @@ func TestCodeStoreScopedIsolation(t *testing.T) {
|
|||
t.Fatal("other scope was removed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodeStoreConsumeScopedRejectsAndDeletesLegacyVersion(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
codes := NewCodeStore()
|
||||
rec := store.PhoneCode{
|
||||
Version: 0, Phone: "15550015003", Code: "12345",
|
||||
Purpose: store.PhoneCodePurposeChangePhone, UserID: 43, AuthKeyID: [8]byte{3},
|
||||
}
|
||||
if err := codes.Set(ctx, "legacy-scope", rec, time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found, err := codes.ConsumeScoped(ctx, "legacy-scope", rec.Scope()); err != nil || found {
|
||||
t.Fatalf("legacy scoped consume found=%v err=%v, want false/nil", found, err)
|
||||
}
|
||||
if _, found, _ := codes.Get(ctx, "legacy-scope"); found {
|
||||
t.Fatal("legacy scoped code remains after fail-closed consume")
|
||||
}
|
||||
if _, ok := codes.scopes[rec.Scope()]; ok {
|
||||
t.Fatal("legacy scoped index remains after fail-closed consume")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue