diff --git a/selfservice/flow/registration/error.go b/selfservice/flow/registration/error.go index bbf4d1e3b76c..f14163180cf1 100644 --- a/selfservice/flow/registration/error.go +++ b/selfservice/flow/registration/error.go @@ -47,7 +47,8 @@ type ( } ) -func NewFlowExpiredError(ago time.Duration) *FlowExpiredError { +func NewFlowExpiredError(at time.Time) *FlowExpiredError { + ago := time.Since(at) return &FlowExpiredError{ ago: ago, DefaultError: herodot.ErrBadRequest. diff --git a/selfservice/flow/registration/error_test.go b/selfservice/flow/registration/error_test.go index 441cf49f3da7..d235ff3141ad 100644 --- a/selfservice/flow/registration/error_test.go +++ b/selfservice/flow/registration/error_test.go @@ -86,6 +86,8 @@ func TestHandleError(t *testing.T) { return sse.Payload.Errors, nil } + anHourAgo := time.Now().Add(-time.Hour) + t.Run("case=error with nil flow defaults to error ui redirect", func(t *testing.T) { t.Cleanup(reset) @@ -118,7 +120,7 @@ func TestHandleError(t *testing.T) { t.Cleanup(reset) registrationFlow = newFlow(t, time.Minute, flow.TypeAPI) - flowError = registration.NewFlowExpiredError(time.Hour) + flowError = registration.NewFlowExpiredError(anHourAgo) ct = identity.CredentialsTypePassword res, err := ts.Client().Do(testhelpers.NewHTTPGetJSONRequest(t, ts.URL+"/error")) @@ -203,7 +205,7 @@ func TestHandleError(t *testing.T) { t.Cleanup(reset) registrationFlow = ®istration.Flow{Type: flow.TypeBrowser} - flowError = registration.NewFlowExpiredError(time.Hour) + flowError = registration.NewFlowExpiredError(anHourAgo) ct = identity.CredentialsTypePassword lf, _ := expectRegistrationUI(t) diff --git a/selfservice/flow/registration/flow.go b/selfservice/flow/registration/flow.go index 306c964d554d..7598567e4312 100644 --- a/selfservice/flow/registration/flow.go +++ b/selfservice/flow/registration/flow.go @@ -125,7 +125,7 @@ func (f *Flow) GetID() uuid.UUID { func (f *Flow) Valid() error { if f.ExpiresAt.Before(time.Now()) { - return errors.WithStack(NewFlowExpiredError(time.Since(f.ExpiresAt))) + return errors.WithStack(NewFlowExpiredError(f.ExpiresAt)) } return nil } diff --git a/selfservice/flow/registration/handler.go b/selfservice/flow/registration/handler.go index 5c5b6face05f..0e8f26bc4386 100644 --- a/selfservice/flow/registration/handler.go +++ b/selfservice/flow/registration/handler.go @@ -5,9 +5,10 @@ import ( "time" "github.com/julienschmidt/httprouter" - "github.com/ory/x/urlx" "github.com/pkg/errors" + "github.com/ory/x/urlx" + "github.com/ory/kratos/driver/configuration" "github.com/ory/kratos/selfservice/errorx" "github.com/ory/kratos/selfservice/flow"