Skip to content

Commit

Permalink
refactor: rename recovery request to flow internally
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 25, 2020
1 parent db178b7 commit 16c5618
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions internal/faker.go
Expand Up @@ -116,7 +116,7 @@ func RegisterFakes() {
panic(err)
}

if err := faker.AddProvider("settings_request_methods", func(v reflect.Value) (interface{}, error) {
if err := faker.AddProvider("settings_flow_methods", func(v reflect.Value) (interface{}, error) {
var methods = make(map[string]*settings.RequestMethod)
for _, ct := range []string{settings.StrategyProfile, string(identity.CredentialsTypePassword), string(identity.CredentialsTypeOIDC)} {
var f form.HTMLForm
Expand All @@ -133,7 +133,7 @@ func RegisterFakes() {
panic(err)
}

if err := faker.AddProvider("recovery_request_methods", func(v reflect.Value) (interface{}, error) {
if err := faker.AddProvider("recovery_flow_methods", func(v reflect.Value) (interface{}, error) {
var methods = make(map[string]*recovery.RequestMethod)
for _, ct := range []string{recovery.StrategyRecoveryTokenName} {
var f form.HTMLForm
Expand Down
6 changes: 3 additions & 3 deletions selfservice/flow/recovery/request.go
Expand Up @@ -65,10 +65,10 @@ type Request struct {
// processed, but for example the password is incorrect, this will contain error messages.
//
// required: true
Methods map[string]*RequestMethod `json:"methods" faker:"recovery_request_methods" db:"-"`
Methods map[string]*RequestMethod `json:"methods" faker:"recovery_flow_methods" db:"-"`

// MethodsRaw is a helper struct field for gobuffalo.pop.
MethodsRaw RequestMethodsRaw `json:"-" faker:"-" has_many:"selfservice_recovery_request_methods" fk_id:"selfservice_recovery_request_id"`
MethodsRaw RequestMethodsRaw `json:"-" faker:"-" has_many:"selfservice_recovery_flow_methods" fk_id:"selfservice_recovery_flow_id"`

// State represents the state of this request:
//
Expand Down Expand Up @@ -113,7 +113,7 @@ func NewRequest(exp time.Duration, csrf string, r *http.Request, strategies Stra
}

func (r Request) TableName() string {
return "selfservice_recovery_requests"
return "selfservice_recovery_flows"
}

func (r *Request) URL(recoveryURL *url.URL) *url.URL {
Expand Down
12 changes: 6 additions & 6 deletions selfservice/flow/recovery/request_method.go
Expand Up @@ -23,11 +23,11 @@ type RequestMethod struct {
// ID is a helper struct field for gobuffalo.pop.
ID uuid.UUID `json:"-" db:"id"`

// RequestID is a helper struct field for gobuffalo.pop.
RequestID uuid.UUID `json:"-" db:"selfservice_recovery_request_id"`
// FlowID is a helper struct field for gobuffalo.pop.
FlowID uuid.UUID `json:"-" db:"selfservice_flow_request_id"`

// Request is a helper struct field for gobuffalo.pop.
Request *Request `json:"-" belongs_to:"selfservice_recovery_request" fk_id:"RequestID"`
// Flow is a helper struct field for gobuffalo.pop.
Flow *Request `json:"-" belongs_to:"selfservice_flow_request" fk_id:"FlowID"`

// CreatedAt is a helper struct field for gobuffalo.pop.
CreatedAt time.Time `json:"-" db:"created_at"`
Expand All @@ -45,12 +45,12 @@ type RequestMethods map[string]*RequestMethod

func (u RequestMethods) TableName() string {
// This must be stay a value receiver, using a pointer receiver will cause issues with pop.
return "selfservice_recovery_request_methods"
return "selfservice_recovery_flow_methods"
}

func (u RequestMethodsRaw) TableName() string {
// This must be stay a value receiver, using a pointer receiver will cause issues with pop.
return "selfservice_recovery_request_methods"
return "selfservice_recovery_flow_methods"
}

// swagger:ignore
Expand Down
2 changes: 1 addition & 1 deletion selfservice/flow/settings/strategy_helper.go
Expand Up @@ -76,7 +76,7 @@ func PrepareUpdate(d interface {
WithField("stack_trace", fmt.Sprintf("%s", debug.Stack())).
WithField("expected_request_id", payload.GetRequestID()).
WithField("actual_request_id", rid).
Debug("Request ID from continuity manager does not match Request ID from request.")
Debug("Flow ID from continuity manager does not match Flow ID from request.")
return c, nil
} else if !errors.Is(err, &continuity.ErrNotResumable) {
return new(UpdateContext), err
Expand Down
8 changes: 4 additions & 4 deletions selfservice/strategy/password/login_test.go
Expand Up @@ -112,7 +112,7 @@ func TestCompleteLogin(t *testing.T) {
res, err := c.Do(req)
require.NoError(t, err)
defer res.Body.Close()
require.EqualValues(t, esc, res.StatusCode, "Request: %+v\n\t\tResponse: %s", res.Request, res)
require.EqualValues(t, esc, res.StatusCode, "Flow: %+v\n\t\tResponse: %s", res.Request, res)
body, err := ioutil.ReadAll(res.Body)
require.NoError(t, err)
return res, body
Expand All @@ -131,7 +131,7 @@ func TestCompleteLogin(t *testing.T) {

res, err := c.Get(u)
require.NoError(t, err)
require.EqualValues(t, http.StatusOK, res.StatusCode, "Request: %+v\n\t\tResponse: %s", res.Request, res)
require.EqualValues(t, http.StatusOK, res.StatusCode, "Flow: %+v\n\t\tResponse: %s", res.Request, res)
assert.NotEmpty(t, res.Request.URL.Query().Get("flow"))

return makeRequestRaw(t, false, payload, res.Request.URL.Query().Get("flow"), c, esc)
Expand Down Expand Up @@ -229,15 +229,15 @@ func TestCompleteLogin(t *testing.T) {
res, body := run(t, false)
require.Contains(t, res.Request.URL.Path, "error-ts")
assert.Equal(t, int64(http.StatusBadRequest), gjson.GetBytes(body, "0.code").Int(), "%s", body)
assert.Equal(t, "Bad Request", gjson.GetBytes(body, "0.status").String(), "%s", body)
assert.Equal(t, "Bad Flow", gjson.GetBytes(body, "0.status").String(), "%s", body)
assert.Contains(t, gjson.GetBytes(body, "0.reason").String(), "request query parameter is missing or invalid", "%s", body)
})

t.Run("type=api", func(t *testing.T) {
res, body := run(t, true)
require.Contains(t, res.Request.URL.Path, password.RouteLogin, res.Request.URL)
assert.Equal(t, int64(http.StatusBadRequest), gjson.GetBytes(body, "error.code").Int(), "%s", body)
assert.Equal(t, "Bad Request", gjson.GetBytes(body, "error.status").String(), "%s", body)
assert.Equal(t, "Bad Flow", gjson.GetBytes(body, "error.status").String(), "%s", body)
assert.Contains(t, gjson.GetBytes(body, "error.reason").String(), "request query parameter is missing or invalid", "%s", body)
})
})
Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/password/registration_test.go
Expand Up @@ -124,7 +124,7 @@ func TestRegistration(t *testing.T) {
require.NoError(t, res.Body.Close())
require.NoError(t, err)

require.EqualValues(t, expectedStatusCode, res.StatusCode, "Request: %+v\n\t\tResponse: %+v\n\t\tResponse Headers: %+v\n\t\tBody: %s", res.Request, res, res.Header, result)
require.EqualValues(t, expectedStatusCode, res.StatusCode, "Flow: %+v\n\t\tResponse: %+v\n\t\tResponse Headers: %+v\n\t\tBody: %s", res.Request, res, res.Header, result)
return result, res
}

Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/recoverytoken/token.go
Expand Up @@ -27,7 +27,7 @@ type Token struct {
RecoveryAddress *identity.RecoveryAddress `json:"recovery_address" belongs_to:"identity_recovery_addresses" fk_id:"RecoveryAddressID"`

// RecoveryAddress links this token to a recovery request.
Request *recovery.Request `json:"request" belongs_to:"identity_recovery_requests" fk_id:"RequestID"`
Request *recovery.Request `json:"request" belongs_to:"identity_recovery_requests" fk_id:"FlowID"`

// CreatedAt is a helper struct field for gobuffalo.pop.
CreatedAt time.Time `json:"-" faker:"-" db:"created_at"`
Expand Down

0 comments on commit 16c5618

Please sign in to comment.