~thecashewtrader/minv__server

0008141148a07506e73937b9511832e4807b376e — thecashewtrader 1 year, 9 months ago 61e5361
Clean up tests
2 files changed, 30 insertions(+), 16 deletions(-)

A config.toml
M token/paseto_test.go
A config.toml => config.toml +8 -0
@@ 0,0 1,8 @@
allowed_origins = ["http://localhost:*", "https://localhost:*", "http://127.0.0.1:*", "https://127.0.0.1:*"]
base_url = "http://localhost:8001"
db_time_format = "2006-01-02 15:04:05"
paseto_duration = "720h"
paseto_key = "Vmtab2QxSnJNSGRQVlZaWFZsaE9URU5u"
port = "8001"
resolution = [768, 432]
secret_key = "VmtkMFUxUnJNVlpOVnpWcFpXcENURU5u"

M token/paseto_test.go => token/paseto_test.go +22 -16
@@ 18,6 18,8 @@ func TestMain(m *testing.M) {
}

func TestNormalPASETO(t *testing.T) {
	require := require.New(t)

	username := util.RandomUsername()
	duration := time.Minute



@@ 25,35 27,39 @@ func TestNormalPASETO(t *testing.T) {
	expiredAt := issuedAt.Add(duration)

	token, err := CreateToken(username, duration)
	require.NoError(t, err)
	require.NotEmpty(t, token)
	require.NoError(err)
	require.NotEmpty(token)

	payload, err := VerifyToken(token)
	require.NoError(t, err)
	require.NotEmpty(t, payload)
	require.NoError(err)
	require.NotEmpty(payload)

	require.NotZero(t, payload.ID)
	require.Equal(t, username, payload.Username)
	require.WithinDuration(t, issuedAt, payload.IssuedAt, time.Second)
	require.WithinDuration(t, expiredAt, payload.ExpiredAt, time.Second)
	require.NotZero(payload.ID)
	require.Equal(username, payload.Username)
	require.WithinDuration(issuedAt, payload.IssuedAt, time.Second)
	require.WithinDuration(expiredAt, payload.ExpiredAt, time.Second)
}

func TestExpiredPASETO(t *testing.T) {
	require := require.New(t)

	token, err := CreateToken(util.RandomUsername(), -time.Minute)
	require.NoError(t, err)
	require.NotEmpty(t, token)
	require.NoError(err)
	require.NotEmpty(token)

	payload, err := VerifyToken(token)
	require.Error(t, err)
	require.EqualError(t, err, ErrExpiredToken.Error())
	require.Nil(t, payload)
	require.Error(err)
	require.EqualError(err, ErrExpiredToken.Error())
	require.Nil(payload)
}

func TestInvalidPASETO(t *testing.T) {
	require := require.New(t)

	token := util.RandomString(20)

	payload, err := VerifyToken(token)
	require.Error(t, err)
	require.EqualError(t, err, ErrInvalidToken.Error())
	require.Nil(t, payload)
	require.Error(err)
	require.EqualError(err, ErrInvalidToken.Error())
	require.Nil(payload)
}