Skip to content

Commit

Permalink
fix: test db naming, improved telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
davenewza committed Nov 10, 2023
1 parent f55d774 commit 77e03a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions runtime/oauth/refresh_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (
// NewRefreshToken generates a new refresh token for the identity using the
// configured or default expiry time.
func NewRefreshToken(ctx context.Context, identityId string) (string, error) {
ctx, span := tracer.Start(ctx, "New Refresh Token")
defer span.End()

if identityId == "" {
return "", errors.New("identity ID cannot be empty when generating new refresh token")
}
Expand Down Expand Up @@ -59,6 +62,9 @@ func NewRefreshToken(ctx context.Context, identityId string) (string, error) {
// and then rotates it for a new refresh token with the exact same expiry time and
// identity. The original refresh token is then revoked from future use.
func RotateRefreshToken(ctx context.Context, refreshTokenRaw string) (isValid bool, refreshToken string, identityId string, err error) {
ctx, span := tracer.Start(ctx, "Rotate Refresh Token")
defer span.End()

tokenHash, err := hashToken(refreshTokenRaw)
if err != nil {
return false, "", "", err
Expand Down Expand Up @@ -116,6 +122,9 @@ func RotateRefreshToken(ctx context.Context, refreshTokenRaw string) (isValid bo
// RevokeRefreshToken will delete (revoke) the provided refresh token,
// which will prevent it from being used again.
func RevokeRefreshToken(ctx context.Context, refreshTokenRaw string) error {
ctx, span := tracer.Start(ctx, "Revoke Refresh Token")
defer span.End()

tokenHash, err := hashToken(refreshTokenRaw)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions testing/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"
"testing"

"github.com/dchest/uniuri"
"github.com/stretchr/testify/require"
"github.com/teamkeel/keel/db"
"github.com/teamkeel/keel/proto"
Expand Down Expand Up @@ -37,8 +36,10 @@ func MakeContext(t *testing.T, keelSchema string, resetDatabase bool) (context.C
ctx, err = testhelpers.WithTracing(ctx)
require.NoError(t, err)

databaseName := strings.ToLower("keel_test_" + t.Name())

// Add database to context
database, err := testhelpers.SetupDatabaseForTestCase(ctx, dbConnInfo, schema, "keel_test_"+strings.ToLower(uniuri.NewLen(8)), resetDatabase)
database, err := testhelpers.SetupDatabaseForTestCase(ctx, dbConnInfo, schema, databaseName, resetDatabase)
require.NoError(t, err)
ctx = db.WithDatabase(ctx, database)

Expand Down

0 comments on commit 77e03a2

Please sign in to comment.