Skip to content

Commit c230d8a

Browse files
committed
bump up coverage, change slightly always allow implementation
1 parent 0ad7fa5 commit c230d8a

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

internal/api/token_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/stretchr/testify/suite"
2020
"github.com/supabase/auth/internal/api/apierrors"
2121
"github.com/supabase/auth/internal/conf"
22+
"github.com/supabase/auth/internal/crypto"
2223
"github.com/supabase/auth/internal/models"
2324
)
2425

@@ -890,3 +891,26 @@ $$;`
890891
})
891892
}
892893
}
894+
895+
func TestRefreshTokenGrantParamsValidate(t *testing.T) {
896+
examples := []string{
897+
"",
898+
"01234567890",
899+
"AAAAAAAAAAAA",
900+
"------------",
901+
"0000000000000",
902+
}
903+
904+
p := &RefreshTokenGrantParams{}
905+
906+
for _, example := range examples {
907+
p.RefreshToken = example
908+
require.Error(t, p.Validate())
909+
}
910+
911+
p.RefreshToken = "0123456abcde"
912+
require.NoError(t, p.Validate())
913+
914+
p.RefreshToken = (&crypto.RefreshToken{}).Encode(make([]byte, 32))
915+
require.NoError(t, p.Validate())
916+
}

internal/models/sessions.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ func (s *Session) GetRefreshTokenHmacKey(dbEncryption conf.DatabaseEncryptionCon
123123
return hmacKey, dbEncryption.Encrypt && es.ShouldReEncrypt(dbEncryption.EncryptionKeyID), nil
124124
}
125125

126-
if s.RefreshTokenHmacKey == nil {
127-
return nil, false, nil
128-
}
129-
130126
hmacKey, err := base64.RawURLEncoding.DecodeString(*s.RefreshTokenHmacKey)
131127
if err != nil {
132128
return nil, false, err

internal/models/sessions_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package models
22

33
import (
4+
"encoding/base64"
45
"strings"
56
"testing"
67
"time"
78

9+
"github.com/gofrs/uuid"
810
"github.com/stretchr/testify/require"
911
"github.com/stretchr/testify/suite"
1012
"github.com/supabase/auth/internal/conf"
@@ -160,3 +162,21 @@ func TestCheckValidity(t *testing.T) {
160162
})
161163
}
162164
}
165+
166+
func TestSessionGetRefreshTokenHmacKey(t *testing.T) {
167+
s, err := NewSession(uuid.Must(uuid.NewV4()), nil)
168+
require.NoError(t, err)
169+
170+
hmacKey, shouldReEncrypt, err := s.GetRefreshTokenHmacKey(conf.DatabaseEncryptionConfiguration{})
171+
require.NoError(t, err)
172+
require.Nil(t, hmacKey)
173+
require.False(t, shouldReEncrypt)
174+
175+
key := base64.RawURLEncoding.EncodeToString(make([]byte, 32))
176+
s.RefreshTokenHmacKey = &key
177+
178+
hmacKey, shouldReEncrypt, err = s.GetRefreshTokenHmacKey(conf.DatabaseEncryptionConfiguration{})
179+
require.NoError(t, err)
180+
require.Equal(t, make([]byte, 32), hmacKey)
181+
require.False(t, shouldReEncrypt)
182+
}

internal/tokens/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func (s *Service) RefreshTokenGrant(ctx context.Context, db *storage.Connection,
356356
if counterDifference < 0 {
357357
// refresh token was not issued by this server
358358
return apierrors.NewBadRequestError(apierrors.ErrorCodeValidationFailed, "Invalid Refresh Token: Not Issued By This Server").WithInternalMessage("Refresh token for session %s has a counter that's ahead %d of the database state", session.ID.String(), -counterDifference)
359-
} else if counterDifference == 0 || config.Security.RefreshTokenAllowReuse {
359+
} else if counterDifference == 0 {
360360
// normal refresh token use
361361
counter := *session.RefreshTokenCounter + 1
362362
session.RefreshTokenCounter = &counter

0 commit comments

Comments
 (0)