store hashedToken as string

This commit is contained in:
Pascal Fischer 2023-03-08 11:30:09 +01:00
parent ed470d7dbe
commit 83e7e30218
2 changed files with 5 additions and 5 deletions

View File

@ -15,7 +15,7 @@ import (
type PersonalAccessToken struct {
ID string
Description string
HashedToken [32]byte
HashedToken string
ExpirationDate time.Time
// scope could be added in future
CreatedBy string
@ -39,7 +39,7 @@ func CreateNewPAT(description string, expirationInDays int, createdBy string) (*
}, plainToken
}
func generateNewToken() ([32]byte, string) {
func generateNewToken() (string, string) {
secret := randStringRunes(30)
checksum := crc32.ChecksumIEEE([]byte(secret))
@ -47,7 +47,7 @@ func generateNewToken() ([32]byte, string) {
paddedChecksum := fmt.Sprintf("%06s", encodedChecksum)
plainToken := "nbp_" + secret + paddedChecksum
hashedToken := sha256.Sum256([]byte(plainToken))
return hashedToken, plainToken
return string(hashedToken[:]), plainToken
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

View File

@ -12,8 +12,8 @@ import (
func TestPAT_GenerateToken_Hashing(t *testing.T) {
hashedToken, plainToken := generateNewToken()
assert.Equal(t, hashedToken, sha256.Sum256([]byte(plainToken)))
expectedToken := sha256.Sum256([]byte(plainToken))
assert.Equal(t, hashedToken, string(expectedToken[:]))
}
func TestPAT_GenerateToken_Prefix(t *testing.T) {