Skip to content

Commit

Permalink
Update GoTrue version under test and fix tests (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Kieron Woodhouse <[email protected]>
  • Loading branch information
kwoodhouse93 and kwoodhouse93 authored Jul 28, 2024
1 parent 6883139 commit d98ca77
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion endpoints/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Client) Signup(req types.SignupRequest) (*types.SignupResponse, error)
}

// To make the response easier to consume, if autoconfirm was enabled, the
// session user should be popuated. Copy that into the embedded user type
// session user should be populated. Copy that into the embedded user type
// so it's easier to access.
//
// i.e. we can access user fields like res.Email regardless of whether
Expand Down
27 changes: 14 additions & 13 deletions integration_test/adminaudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"github.com/supabase-community/gotrue-go/types"
)

// This test relies on running with an empty audit log.
// This appears to be fine with the default test settings, but if it becomes an
// issue locally or in CI, we can add a cleanup step to all tests, or rewrite
// to stop looking at specific numbers of log entries.
// This test creates some audit logs, then retrieves them with pagination.
// However, other tests running in parallel may also create logs, so we only
// check that _at least_ the logs we create here are returned.
//
// In order to test this functionality exactly, we need to run this test against
// a fresh database with an empty audit log table.
func TestAdminAudit(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
Expand Down Expand Up @@ -45,29 +47,28 @@ func TestAdminAudit(t *testing.T) {
})
require.NoError(err)
assert.Len(resp.Logs, 4)
assert.EqualValues(10, resp.TotalCount)
assert.GreaterOrEqual(resp.TotalCount, 10)
assert.EqualValues(2, resp.NextPage)
assert.EqualValues(3, resp.TotalPages)
assert.GreaterOrEqual(resp.TotalPages, uint(3))

resp, err = client.AdminAudit(types.AdminAuditRequest{
Page: 2,
PerPage: 4,
})
require.NoError(err)
assert.Len(resp.Logs, 4)
assert.EqualValues(10, resp.TotalCount)
assert.GreaterOrEqual(resp.TotalCount, 10)
assert.EqualValues(3, resp.NextPage)
assert.EqualValues(3, resp.TotalPages)
assert.GreaterOrEqual(resp.TotalPages, uint(3))

resp, err = client.AdminAudit(types.AdminAuditRequest{
Page: 3,
PerPage: 4,
})
require.NoError(err)
assert.Len(resp.Logs, 2)
assert.EqualValues(10, resp.TotalCount)
assert.EqualValues(0, resp.NextPage)
assert.EqualValues(3, resp.TotalPages)
assert.GreaterOrEqual(len(resp.Logs), 2)
assert.GreaterOrEqual(resp.TotalCount, 10)
assert.GreaterOrEqual(resp.TotalPages, uint(3))

// Invalid - empty query
_, err = client.AdminAudit(types.AdminAuditRequest{
Expand Down Expand Up @@ -100,7 +101,7 @@ func TestAdminAudit(t *testing.T) {
},
})
require.NoError(err)
assert.Len(resp.Logs, 10)
assert.GreaterOrEqual(len(resp.Logs), 10)

resp, err = client.AdminAudit(types.AdminAuditRequest{
Query: &types.AuditQuery{
Expand Down
4 changes: 2 additions & 2 deletions integration_test/admingeneratelink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAdminGenerateLink(t *testing.T) {
require.NoError(err)

assert.EqualValues(resp.VerificationType, "signup")
linkRegexp := regexp.MustCompile(`^http://localhost:9999/\?token=[a-zA-Z0-9_-]+&type=signup&redirect_to=http://localhost:3000$`)
linkRegexp := regexp.MustCompile(`^http://localhost:9999/verify\?token=[a-zA-Z0-9_-]+&type=signup&redirect_to=http://localhost:3000$`)
assert.Regexp(linkRegexp, resp.ActionLink)
assert.NotEmpty(resp.HashedToken)
assert.NotEmpty(resp.EmailOTP)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestAdminGenerateLink(t *testing.T) {
require.NoError(err)
assert.Equal("http://localhost:3000", resp.RedirectTo)
assert.EqualValues(resp.VerificationType, "email_change_current")
linkRegexp = regexp.MustCompile(`^http://localhost:9999/\?token=[a-zA-Z0-9_-]+&type=email_change&redirect_to=http://localhost:3000$`)
linkRegexp = regexp.MustCompile(`^http://localhost:9999/verify\?token=[a-zA-Z0-9_-]+&type=email_change&redirect_to=http://localhost:3000$`)
assert.Regexp(linkRegexp, resp.ActionLink)
assert.NotEmpty(resp.HashedToken)
assert.NotEmpty(resp.EmailOTP)
Expand Down
14 changes: 7 additions & 7 deletions integration_test/setup/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ services:
container_name: gotrue
depends_on:
- postgres
image: supabase/gotrue:v2.86.0
image: supabase/gotrue:v2.157.0
restart: on-failure
ports:
- '9999:9999'
- "9999:9999"
environment:
GOTRUE_JWT_SECRET: "secret"
GOTRUE_DB_DRIVER: "postgres"
Expand All @@ -30,10 +30,10 @@ services:
container_name: gotrue_autoconfirm
depends_on:
- postgres
image: supabase/gotrue:v2.86.0
image: supabase/gotrue:v2.157.0
restart: on-failure
ports:
- '9998:9998'
- "9998:9998"
environment:
GOTRUE_JWT_SECRET: "secret"
GOTRUE_DB_DRIVER: "postgres"
Expand Down Expand Up @@ -62,10 +62,10 @@ services:
container_name: gotrue_signup_disabled
depends_on:
- postgres
image: supabase/gotrue:v2.86.0
image: supabase/gotrue:v2.157.0
restart: on-failure
ports:
- '9997:9997'
- "9997:9997"
environment:
GOTRUE_JWT_SECRET: "secret"
GOTRUE_DB_DRIVER: "postgres"
Expand All @@ -90,7 +90,7 @@ services:
dockerfile: Dockerfile.postgres.dev
container_name: gotrue_postgres
ports:
- '5432:5432'
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
Expand Down
4 changes: 2 additions & 2 deletions integration_test/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestVerify(t *testing.T) {
})
require.NoError(err)
assert.NotEmpty(vResp.URL)
assert.Equal("401", vResp.ErrorCode)
assert.Equal("unauthorized_client", vResp.Error)
assert.Equal("403", vResp.ErrorCode)
assert.Equal("access_denied", vResp.Error)

// Test Verify, invalid request
_, err = client.Verify(types.VerifyRequest{})
Expand Down

0 comments on commit d98ca77

Please sign in to comment.