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
|
|
@ -27,6 +27,7 @@ func TestRedisCodeStoreScopedRotationAndSingleConsume(t *testing.T) {
|
|||
oldHash := fmt.Sprintf("scope-old-%d", suffix)
|
||||
newHash := fmt.Sprintf("scope-new-%d", suffix)
|
||||
rec := store.PhoneCode{
|
||||
Version: store.PhoneCodeVersionCurrent,
|
||||
Phone: fmt.Sprintf("1555%d", suffix),
|
||||
Code: "12345",
|
||||
Purpose: store.PhoneCodePurposeChangePhone,
|
||||
|
|
@ -81,3 +82,34 @@ func TestRedisCodeStoreScopedRotationAndSingleConsume(t *testing.T) {
|
|||
t.Fatalf("remaining redis keys=%d err=%v", exists, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedisCodeStoreConsumeScopedRejectsAndDeletesLegacyVersion(t *testing.T) {
|
||||
addr := os.Getenv("TELESRV_TEST_REDIS_ADDR")
|
||||
if addr == "" {
|
||||
t.Skip("set TELESRV_TEST_REDIS_ADDR to run redis integration test")
|
||||
}
|
||||
ctx := context.Background()
|
||||
c, err := Open(ctx, addr, "", 0)
|
||||
if err != nil {
|
||||
t.Fatalf("open: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = c.Close() })
|
||||
|
||||
hash := fmt.Sprintf("legacy-scope-%d", time.Now().UnixNano())
|
||||
rec := store.PhoneCode{
|
||||
Version: 0, Phone: "15550015004", Code: "12345",
|
||||
Purpose: store.PhoneCodePurposeChangePhone, UserID: 44, AuthKeyID: [8]byte{4},
|
||||
}
|
||||
scopeKey := codeScopeKey(rec.Scope())
|
||||
t.Cleanup(func() { _ = c.Del(ctx, codeKey(hash), scopeKey).Err() })
|
||||
codes := NewCodeStore(c)
|
||||
if err := codes.Set(ctx, hash, rec, time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found, err := codes.ConsumeScoped(ctx, hash, rec.Scope()); err != nil || found {
|
||||
t.Fatalf("legacy scoped consume found=%v err=%v, want false/nil", found, err)
|
||||
}
|
||||
if exists, err := c.Exists(ctx, codeKey(hash), scopeKey).Result(); err != nil || exists != 0 {
|
||||
t.Fatalf("legacy scoped keys remain=%d err=%v", exists, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue