Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/cloudfront/sign: allow setting cookie expiration in CookieOptions #1122

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions feature/cloudfront/sign/sign_cookie.go
Expand Up @@ -20,9 +20,10 @@ const (
// A CookieOptions optional additional options that can be applied to the signed
// cookies.
type CookieOptions struct {
Path string
Domain string
Secure bool
Path string
Domain string
Secure bool
Expires time.Time
}

// apply will integration the options provided into the base cookie options
Expand Down Expand Up @@ -230,11 +231,12 @@ func createCookies(p *Policy, keyID string, privKey *rsa.PrivateKey, opt CookieO

cookies := []*http.Cookie{cPolicy, cSignature, cKey}

// Applie the cookie options
// Apply the cookie options
for _, c := range cookies {
c.Path = opt.Path
c.Domain = opt.Domain
c.Secure = opt.Secure
c.Expires = opt.Expires
}

return cookies, nil
Expand Down
5 changes: 4 additions & 1 deletion feature/cloudfront/sign/sign_cookie_test.go
Expand Up @@ -91,7 +91,7 @@ func TestSignCookie_WithCookieOptions(t *testing.T) {
o.Path = "/"
o.Domain = ".example.com"
o.Secure = true

o.Expires = expires
})

if err != nil {
Expand All @@ -117,5 +117,8 @@ func TestSignCookie_WithCookieOptions(t *testing.T) {
if !c.Secure {
t.Errorf("expect to be true")
}
if e, a := expires, c.Expires; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
}