Skip to content

Commit

Permalink
refactor: rename package recoverytoken to link
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 27, 2020
1 parent 4f6bafd commit f87fb54
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions driver/registry_default.go
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ory/kratos/selfservice/flow/verification"
"github.com/ory/kratos/selfservice/hook"
"github.com/ory/kratos/selfservice/strategy/profile"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/x"

"github.com/cenkalti/backoff"
Expand Down Expand Up @@ -248,7 +248,7 @@ func (m *RegistryDefault) selfServiceStrategies() []interface{} {
password2.NewStrategy(m, m.c),
oidc.NewStrategy(m, m.c),
profile.NewStrategy(m, m.c),
recoverytoken.NewStrategy(m, m.c),
link.NewStrategy(m, m.c),
}
}

Expand Down Expand Up @@ -510,7 +510,7 @@ func (m *RegistryDefault) CourierPersister() courier.Persister {
return m.persister
}

func (m *RegistryDefault) RecoveryTokenPersister() recoverytoken.Persister {
func (m *RegistryDefault) RecoveryTokenPersister() link.Persister {
return m.Persister()
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testhelpers/sql.go
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ory/kratos/selfservice/flow/registration"
"github.com/ory/kratos/selfservice/flow/settings"
"github.com/ory/kratos/selfservice/flow/verification"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/session"
)

Expand All @@ -29,7 +29,7 @@ func CleanSQL(t *testing.T, c *pop.Connection) {
new(registration.Flow).TableName(),
new(settings.FlowMethods).TableName(),
new(settings.Flow).TableName(),
new(recoverytoken.Token).TableName(),
new(link.Token).TableName(),
new(recovery.RequestMethods).TableName(),
new(recovery.Flow).TableName(),
new(verification.Request).TableName(),
Expand Down
4 changes: 2 additions & 2 deletions persistence/reference.go
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ory/kratos/selfservice/flow/registration"
"github.com/ory/kratos/selfservice/flow/settings"
"github.com/ory/kratos/selfservice/flow/verification"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/session"
)

Expand All @@ -34,7 +34,7 @@ type Persister interface {
errorx.Persister
verification.Persister
recovery.FlowPersister
recoverytoken.Persister
link.Persister

Close(context.Context) error
Ping(context.Context) error
Expand Down
12 changes: 6 additions & 6 deletions persistence/sql/persister_recovery.go
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/ory/x/sqlcon"

"github.com/ory/kratos/selfservice/flow/recovery"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
)

var _ recovery.FlowPersister = new(Persister)
var _ recoverytoken.Persister = new(Persister)
var _ link.Persister = new(Persister)

func (p Persister) CreateRecoveryFlow(ctx context.Context, r *recovery.Flow) error {
return p.GetConnection(ctx).Eager("MethodsRaw").Create(r)
Expand Down Expand Up @@ -62,7 +62,7 @@ func (p Persister) UpdateRecoveryFlow(ctx context.Context, r *recovery.Flow) err
})
}

func (p *Persister) CreateRecoveryToken(ctx context.Context, token *recoverytoken.Token) error {
func (p *Persister) CreateRecoveryToken(ctx context.Context, token *link.Token) error {
t := token.Token
token.Token = p.hmacValue(t)

Expand All @@ -75,8 +75,8 @@ func (p *Persister) CreateRecoveryToken(ctx context.Context, token *recoverytoke
return nil
}

func (p *Persister) UseRecoveryToken(ctx context.Context, token string) (*recoverytoken.Token, error) {
rt := new(recoverytoken.Token)
func (p *Persister) UseRecoveryToken(ctx context.Context, token string) (*link.Token, error) {
rt := new(link.Token)
if err := sqlcon.HandleError(p.Transaction(ctx, func(ctx context.Context, tx *pop.Connection) (err error) {
for _, secret := range p.cf.SecretsSession() {
if err = tx.Eager().Where("token = ? AND NOT used", p.hmacValueWithSecret(token, secret)).First(rt); err != nil {
Expand All @@ -100,5 +100,5 @@ func (p *Persister) UseRecoveryToken(ctx context.Context, token string) (*recove

func (p *Persister) DeleteRecoveryToken(ctx context.Context, token string) error {
/* #nosec G201 TableName is static */
return p.GetConnection(ctx).RawQuery(fmt.Sprintf("DELETE FROM %s WHERE token=?", new(recoverytoken.Token).TableName()), token).Exec()
return p.GetConnection(ctx).RawQuery(fmt.Sprintf("DELETE FROM %s WHERE token=?", new(link.Token).TableName()), token).Exec()
}
4 changes: 2 additions & 2 deletions persistence/sql/persister_test.go
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/ory/kratos/persistence/sql"
"github.com/ory/kratos/selfservice/errorx"
"github.com/ory/kratos/selfservice/flow/recovery"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/x"

"github.com/gobuffalo/pop/v5"
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestPersister(t *testing.T) {
})
t.Run("contract=recovery.TestPersister", func(t *testing.T) {
pop.SetLogger(pl(t))
recoverytoken.TestPersister(p)(t)
link.TestPersister(p)(t)
})
t.Run("contract=continuity.TestPersister", func(t *testing.T) {
pop.SetLogger(pl(t))
Expand Down
@@ -1,4 +1,4 @@
package recoverytoken
package link

import (
"context"
Expand Down
@@ -1,4 +1,4 @@
package recoverytoken
package link

import (
"context"
Expand Down
@@ -1,4 +1,4 @@
package recoverytoken
package link

import (
"context"
Expand Down
@@ -1,4 +1,4 @@
package recoverytoken_test
package link_test

import (
"context"
Expand Down Expand Up @@ -27,7 +27,7 @@ import (
"github.com/ory/kratos/internal/httpclient/models"
"github.com/ory/kratos/internal/testhelpers"
"github.com/ory/kratos/selfservice/flow/recovery"
"github.com/ory/kratos/selfservice/strategy/recoverytoken"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/text"
"github.com/ory/kratos/x"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestAdminStrategy(t *testing.T) {
adminSDK := testhelpers.NewSDKClient(adminTS)

checkLink := func(t *testing.T, link *admin.CreateRecoveryLinkOK, isBefore time.Time) {
require.Contains(t, *link.Payload.RecoveryLink, publicTS.URL+recoverytoken.PublicPath)
require.Contains(t, *link.Payload.RecoveryLink, publicTS.URL+link.PublicPath)
rl := urlx.ParseOrPanic(*link.Payload.RecoveryLink)
assert.NotEmpty(t, rl.Query().Get("token"))
assert.NotEmpty(t, rl.Query().Get("request"))
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestStrategy(t *testing.T) {
assert.EqualValues(t, models.FormFields{csrfField,
{Name: pointerx.String("email"), Required: true, Type: pointerx.String("email")},
}, method.Config.Fields)
assert.EqualValues(t, public.URL+recoverytoken.PublicPath+"?request="+string(rs.Payload.ID), *method.Config.Action)
assert.EqualValues(t, public.URL+link.PublicPath+"?request="+string(rs.Payload.ID), *method.Config.Action)
assert.Empty(t, method.Config.Messages)
assert.Empty(t, rs.Payload.Messages)
})
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestStrategy(t *testing.T) {

recoveryLink := testhelpers.CourierExpectLinkInMessage(t, message, 1)

assert.Contains(t, recoveryLink, public.URL+recoverytoken.PublicPath)
assert.Contains(t, recoveryLink, public.URL+link.PublicPath)
assert.Contains(t, recoveryLink, "token=")
res, err := c.Get(recoveryLink)
require.NoError(t, err)
Expand All @@ -248,7 +248,7 @@ func TestStrategy(t *testing.T) {

t.Run("description=should not be able to use an invalid link", func(t *testing.T) {
c := testhelpers.NewClientWithCookies(t)
res, err := c.Get(public.URL + recoverytoken.PublicPath + "?token=i-do-not-exist")
res, err := c.Get(public.URL + link.PublicPath + "?token=i-do-not-exist")
require.NoError(t, err)

assert.Equal(t, http.StatusNoContent, res.StatusCode)
Expand Down
@@ -1,4 +1,4 @@
package recoverytoken
package link

import (
"time"
Expand Down

0 comments on commit f87fb54

Please sign in to comment.