forked from supabase/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cleanup for session timebox and inactivity timeout (supabas…
…e#1298) Builds on top of supabase#1288. Adds cleanup for timeboxed sessions and sessions that have expired due to inactivity timeout. It achieves backward compatibility with sessions that have `null` in `refreshed_at` by looking at the `updated_at` column of the refresh tokens table. This approach is the one that puts the least strain on the database, having considered backfilling (very expensive at least `O(nlogn)` over the whole refresh tokens table).
- Loading branch information
Showing
4 changed files
with
81 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,33 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/supabase/gotrue/internal/conf" | ||
"github.com/supabase/gotrue/internal/storage/test" | ||
) | ||
|
||
func TestCleanupSQL(t *testing.T) { | ||
func TestCleanup(t *testing.T) { | ||
globalConfig, err := conf.LoadGlobal(modelsTestConfig) | ||
require.NoError(t, err) | ||
conn, err := test.SetupDBConnection(globalConfig) | ||
require.NoError(t, err) | ||
|
||
for _, statement := range CleanupStatements { | ||
_, err := conn.RawQuery(statement).ExecWithCount() | ||
require.NoError(t, err, statement) | ||
sessionTimebox := 10 * time.Second | ||
sessionInactivityTimeout := 5 * time.Second | ||
|
||
cleanup := &Cleanup{ | ||
SessionTimebox: &sessionTimebox, | ||
SessionInactivityTimeout: &sessionInactivityTimeout, | ||
} | ||
} | ||
|
||
func TestCleanup(t *testing.T) { | ||
globalConfig, err := conf.LoadGlobal(modelsTestConfig) | ||
require.NoError(t, err) | ||
conn, err := test.SetupDBConnection(globalConfig) | ||
require.NoError(t, err) | ||
cleanup.Setup() | ||
|
||
for _, statement := range CleanupStatements { | ||
_, err := Cleanup(conn) | ||
if err != nil { | ||
fmt.Printf("%v %t\n", err, err) | ||
} | ||
require.NoError(t, err, statement) | ||
for i := 0; i < 100; i += 1 { | ||
_, err := cleanup.Clean(conn) | ||
require.NoError(t, err) | ||
} | ||
} |