From 688313947907df4c9f73ddaaebade4fc47ee8a1d Mon Sep 17 00:00:00 2001 From: Jamie <697955+JamieCrisman@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:35:52 +0900 Subject: [PATCH] Add ExpiresAt to Session struct (#4) * Add ExpiresAt to Session struct * Update testing image of supabase/gotrue to v2.86.0 * Improve ExpiresAt value checks in tests --- integration_test/setup/docker-compose.yaml | 6 +++--- integration_test/signup_test.go | 1 + integration_test/token_test.go | 7 +++++++ types/session.go | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/integration_test/setup/docker-compose.yaml b/integration_test/setup/docker-compose.yaml index 3aab60a..1f696bb 100644 --- a/integration_test/setup/docker-compose.yaml +++ b/integration_test/setup/docker-compose.yaml @@ -5,7 +5,7 @@ services: container_name: gotrue depends_on: - postgres - image: supabase/gotrue:v2.32.0 + image: supabase/gotrue:v2.86.0 restart: on-failure ports: - '9999:9999' @@ -30,7 +30,7 @@ services: container_name: gotrue_autoconfirm depends_on: - postgres - image: supabase/gotrue:v2.32.0 + image: supabase/gotrue:v2.86.0 restart: on-failure ports: - '9998:9998' @@ -62,7 +62,7 @@ services: container_name: gotrue_signup_disabled depends_on: - postgres - image: supabase/gotrue:v2.32.0 + image: supabase/gotrue:v2.86.0 restart: on-failure ports: - '9997:9997' diff --git a/integration_test/signup_test.go b/integration_test/signup_test.go index 0b75aa2..5d2fe73 100644 --- a/integration_test/signup_test.go +++ b/integration_test/signup_test.go @@ -66,6 +66,7 @@ func TestSignup(t *testing.T) { assert.NotEmpty(session.RefreshToken) assert.Equal("bearer", session.TokenType) assert.Equal(3600, session.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), session.ExpiresAt, float64(time.Second)) // Sign up with signups disabled email = randomEmail() diff --git a/integration_test/token_test.go b/integration_test/token_test.go index 71963a6..5f4ab12 100644 --- a/integration_test/token_test.go +++ b/integration_test/token_test.go @@ -2,6 +2,7 @@ package integration_test import ( "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -36,6 +37,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Signin with email convenience method token, err = client.SignInWithEmailPassword(email, password) @@ -45,6 +47,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Test login with phone phone := randomPhoneNumber() @@ -67,6 +70,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Signin with phone convenience method token, err = client.SignInWithPhonePassword(phone, password) @@ -76,6 +80,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Incorrect password _, err = client.Token(types.TokenRequest{ @@ -104,6 +109,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Refresh token convenience method token, err = client.RefreshToken(token.RefreshToken) @@ -113,6 +119,7 @@ func TestToken(t *testing.T) { assert.NotEmpty(token.RefreshToken) assert.Equal("bearer", token.TokenType) assert.Equal(3600, token.ExpiresIn) + assert.InDelta(time.Now().Add(3600*time.Second).Unix(), token.ExpiresAt, float64(time.Second)) // Invalid input tests tests := map[string]types.TokenRequest{ diff --git a/types/session.go b/types/session.go index c449682..c3ea86a 100644 --- a/types/session.go +++ b/types/session.go @@ -5,5 +5,6 @@ type Session struct { RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type"` ExpiresIn int `json:"expires_in"` + ExpiresAt int64 `json:"expires_at"` User User `json:"user"` }