Skip to content

Commit a8b0579

Browse files
authored
sessions: must provide cookie factory to sessions manager (#3)
1 parent 9aec54f commit a8b0579

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

middles/oauth/sessions.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ type Sessions struct {
3232
CookieFactory *CookieFactory
3333
}
3434

35-
func NewSessions(cache Cache[*conceal.Text, Identity]) *Sessions {
35+
// NewSessions creates a new Sessions for managing sessions and cookies
36+
// associated with those sessions.
37+
func NewSessions(cookies *CookieFactory, cache Cache[*conceal.Text, Identity]) *Sessions {
3638
return &Sessions{
37-
Cache: cache,
39+
Cache: cache,
40+
CookieFactory: cookies,
3841
}
3942
}
4043

middles/oauth/sessions_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ func TestSessions_Create(t *testing.T) {
2929

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

32-
// initialize the cookie factory
33-
sessions := &Sessions{
34-
Cache: cache,
35-
CookieFactory: &CookieFactory{
36-
Name: "session-token",
37-
Secure: true,
38-
Clock: testNow,
39-
},
40-
}
32+
// initialize the sessions manager with the cache and a cookie factory
33+
sessions := NewSessions(&CookieFactory{
34+
Name: "session-token",
35+
Secure: true,
36+
Clock: testNow,
37+
}, cache)
4138

4239
id := Identity(12345)
4340
ttl := 1 * time.Hour
@@ -66,8 +63,9 @@ func TestSessions_Create(t *testing.T) {
6663
func TestSessions_Match(t *testing.T) {
6764
t.Parallel()
6865

66+
cookies := (*CookieFactory)(nil)
6967
cache := &mockCache{storage: make(map[string]Identity)}
70-
sessions := NewSessions(cache)
68+
sessions := NewSessions(cookies, cache)
7169

7270
id := Identity(12345)
7371
token := conceal.UUIDv4()

0 commit comments

Comments
 (0)