mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: add custom samesite options to auth cookies (#16885)
Allows controlling `samesite` cookie settings from the deployment config
This commit is contained in:
33
coderd/coderdtest/testjar/cookiejar.go
Normal file
33
coderd/coderdtest/testjar/cookiejar.go
Normal file
@ -0,0 +1,33 @@
|
||||
package testjar
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func New() *Jar {
|
||||
return &Jar{}
|
||||
}
|
||||
|
||||
// Jar exists because 'cookiejar.New()' strips many of the http.Cookie fields
|
||||
// that are needed to assert. Such as 'Secure' and 'SameSite'.
|
||||
type Jar struct {
|
||||
m sync.Mutex
|
||||
perURL map[string][]*http.Cookie
|
||||
}
|
||||
|
||||
func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
j.m.Lock()
|
||||
defer j.m.Unlock()
|
||||
if j.perURL == nil {
|
||||
j.perURL = make(map[string][]*http.Cookie)
|
||||
}
|
||||
j.perURL[u.Host] = append(j.perURL[u.Host], cookies...)
|
||||
}
|
||||
|
||||
func (j *Jar) Cookies(u *url.URL) []*http.Cookie {
|
||||
j.m.Lock()
|
||||
defer j.m.Unlock()
|
||||
return j.perURL[u.Host]
|
||||
}
|
Reference in New Issue
Block a user