feat: sync configurable OTP delivery providers
This commit is contained in:
parent
c18f773701
commit
6af61f26ba
28 changed files with 2100 additions and 118 deletions
36
internal/otpdelivery/delivery_test.go
Normal file
36
internal/otpdelivery/delivery_test.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package otpdelivery
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNewDeliveryIDIsOpaqueAndUnique(t *testing.T) {
|
||||
first, err := NewDeliveryID()
|
||||
if err != nil {
|
||||
t.Fatalf("first id: %v", err)
|
||||
}
|
||||
second, err := NewDeliveryID()
|
||||
if err != nil {
|
||||
t.Fatalf("second id: %v", err)
|
||||
}
|
||||
if first == second || !strings.HasPrefix(first, "otp_") || len(first) != len("otp_")+32 {
|
||||
t.Fatalf("ids = %q / %q", first, second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestRejectsExpiredCode(t *testing.T) {
|
||||
now := time.Now()
|
||||
err := (Request{
|
||||
DeliveryID: "otp_expired",
|
||||
Purpose: PurposeLoginEmail,
|
||||
Channel: ChannelEmail,
|
||||
Recipient: "a@example.test",
|
||||
Code: "123456",
|
||||
ExpiresAt: now,
|
||||
}).Validate(now)
|
||||
if err == nil {
|
||||
t.Fatal("expired request accepted")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue