2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-11 10:08:51 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleauth
|
2019-01-11 10:08:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-06-26 11:38:51 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testrand"
|
2019-01-11 10:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClaims(t *testing.T) {
|
2020-04-02 15:18:08 +01:00
|
|
|
id := testrand.UUID()
|
2019-01-11 10:08:51 +00:00
|
|
|
|
|
|
|
claims := Claims{
|
2019-06-26 11:38:51 +01:00
|
|
|
ID: id,
|
2019-06-18 01:28:40 +01:00
|
|
|
Email: "alice@mail.test",
|
2019-01-11 10:08:51 +00:00
|
|
|
Expiration: time.Now(),
|
|
|
|
}
|
|
|
|
|
|
|
|
claimsBytes, err := claims.JSON()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, claimsBytes)
|
|
|
|
|
|
|
|
parsedClaims, err := FromJSON(claimsBytes)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, parsedClaims)
|
|
|
|
|
|
|
|
assert.Equal(t, parsedClaims.Email, claims.Email)
|
|
|
|
assert.Equal(t, parsedClaims.ID, claims.ID)
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Year(), claims.Expiration.Year())
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Month(), claims.Expiration.Month())
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Day(), claims.Expiration.Day())
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Hour(), claims.Expiration.Hour())
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Minute(), claims.Expiration.Minute())
|
|
|
|
assert.Equal(t, parsedClaims.Expiration.Second(), claims.Expiration.Second())
|
|
|
|
}
|