Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions middles/oauth/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ type Sessions struct {
CookieFactory *CookieFactory
}

func NewSessions(cache Cache[*conceal.Text, Identity]) *Sessions {
// NewSessions creates a new Sessions for managing sessions and cookies
// associated with those sessions.
func NewSessions(cookies *CookieFactory, cache Cache[*conceal.Text, Identity]) *Sessions {
return &Sessions{
Cache: cache,
Cache: cache,
CookieFactory: cookies,
}
}

Expand Down
18 changes: 8 additions & 10 deletions middles/oauth/sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ func TestSessions_Create(t *testing.T) {

cache := &mockCache{storage: make(map[string]Identity)}

// initialize the cookie factory
sessions := &Sessions{
Cache: cache,
CookieFactory: &CookieFactory{
Name: "session-token",
Secure: true,
Clock: testNow,
},
}
// initialize the sessions manager with the cache and a cookie factory
sessions := NewSessions(&CookieFactory{
Name: "session-token",
Secure: true,
Clock: testNow,
}, cache)

id := Identity(12345)
ttl := 1 * time.Hour
Expand Down Expand Up @@ -66,8 +63,9 @@ func TestSessions_Create(t *testing.T) {
func TestSessions_Match(t *testing.T) {
t.Parallel()

cookies := (*CookieFactory)(nil)
cache := &mockCache{storage: make(map[string]Identity)}
sessions := NewSessions(cache)
sessions := NewSessions(cookies, cache)

id := Identity(12345)
token := conceal.UUIDv4()
Expand Down