photoprism/pkg/rnd/crc_test.go
Michael Mayer f5a8c5a45d Auth: Session and ACL enhancements #98 #1746
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-09-28 09:01:17 +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"))
})
}