photoprism/pkg/rnd/crc_token_test.go
Michael Mayer 0852e659c2 API: Improve logs and add /api/v1/connect endpoint for auth callbacks
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-07-19 16:58:43 +02:00

33 lines
773 B
Go

package rnd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCrcToken(t *testing.T) {
t.Run("size 4", func(t *testing.T) {
token := CrcToken()
t.Logf("CrcToken: %s", token)
assert.NotEmpty(t, token)
})
}
func TestValidateCrcToken(t *testing.T) {
t.Run("Static", func(t *testing.T) {
assert.True(t, ValidateCrcToken("8yva-2ni4-385e"))
})
t.Run("Generated", func(t *testing.T) {
assert.True(t, ValidateCrcToken(CrcToken()))
})
t.Run("InvalidChecksum", func(t *testing.T) {
assert.False(t, ValidateCrcToken("8yva-2ni4-185e"))
})
t.Run("InvalidToken", func(t *testing.T) {
assert.False(t, ValidateCrcToken("8ava-2ni4-385e"))
})
t.Run("ValidToken", func(t *testing.T) {
assert.True(t, ValidateCrcToken("hsqq-181q-13ed"))
})
}