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
|
|
@ -15,6 +15,7 @@ func TestResendCodePreservesChangePhoneScopeAndSMSDelivery(t *testing.T) {
|
|||
codes := memory.NewCodeStore()
|
||||
authKeyID := [8]byte{8, 7, 6}
|
||||
rec := store.PhoneCode{
|
||||
Version: store.PhoneCodeVersionCurrent,
|
||||
Phone: "15550014001",
|
||||
Code: "old",
|
||||
Channel: codeChannelPhone,
|
||||
|
|
@ -69,3 +70,34 @@ func TestResendCodePreservesChangePhoneScopeAndSMSDelivery(t *testing.T) {
|
|||
t.Fatal("scoped cancel left hash valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResendAndCancelRejectLegacyChangePhoneCode(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
codes := memory.NewCodeStore()
|
||||
authKeyID := [8]byte{8, 8, 8}
|
||||
legacy := store.PhoneCode{
|
||||
Version: 0, Phone: "15550014002", Code: "12345", Channel: codeChannelPhone,
|
||||
Purpose: store.PhoneCodePurposeChangePhone, UserID: 43, AuthKeyID: authKeyID,
|
||||
}
|
||||
svc := NewService(memory.NewUserStore(), memory.NewAuthorizationStore(), codes, nil, nil, "12345", WithCodeTTL(time.Minute))
|
||||
|
||||
if err := codes.Set(ctx, "legacy-resend", legacy, time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := svc.ResendCodeForAuthKey(ctx, authKeyID, legacy.Phone, "legacy-resend"); err != ErrCodeExpired {
|
||||
t.Fatalf("legacy resend err=%v, want ErrCodeExpired", err)
|
||||
}
|
||||
if _, found, _ := codes.Get(ctx, "legacy-resend"); found {
|
||||
t.Fatal("legacy resend left code active")
|
||||
}
|
||||
|
||||
if err := codes.Set(ctx, "legacy-cancel", legacy, time.Minute); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := svc.CancelCodeForAuthKey(ctx, authKeyID, legacy.Phone, "legacy-cancel"); err != ErrCodeExpired {
|
||||
t.Fatalf("legacy cancel err=%v, want ErrCodeExpired", err)
|
||||
}
|
||||
if _, found, _ := codes.Get(ctx, "legacy-cancel"); found {
|
||||
t.Fatal("legacy cancel left code active")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue