mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-18 04:41:19 +02:00
feat: support for cookie in alpha config and legacy file structure refactoring
Signed-off-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
|
||||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/util/ptr"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
@@ -66,8 +67,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -81,8 +82,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -98,8 +99,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -115,8 +116,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -130,8 +131,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -147,8 +148,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -164,8 +165,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -181,8 +182,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: 15 * time.Minute,
|
||||
Refresh: time.Hour,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -198,8 +199,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "none",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -213,8 +214,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "none",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -228,8 +229,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "none",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -243,8 +244,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: time.Hour,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "invalid",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -260,8 +261,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: 15 * time.Minute,
|
||||
Refresh: time.Hour,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "invalid",
|
||||
},
|
||||
errStrings: []string{
|
||||
@@ -280,8 +281,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: 0,
|
||||
Refresh: 15 * time.Minute,
|
||||
Secure: true,
|
||||
HTTPOnly: false,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(false),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -296,8 +297,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: 24 * time.Hour,
|
||||
Refresh: 0,
|
||||
Secure: true,
|
||||
HTTPOnly: true,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(true),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{},
|
||||
@@ -312,8 +313,8 @@ func TestValidateCookie(t *testing.T) {
|
||||
Path: "",
|
||||
Expire: 24 * time.Hour,
|
||||
Refresh: 0,
|
||||
Secure: true,
|
||||
HTTPOnly: true,
|
||||
Secure: ptr.To(true),
|
||||
HTTPOnly: ptr.To(true),
|
||||
SameSite: "",
|
||||
},
|
||||
errStrings: []string{"could not read cookie secret file: /nonexistent/file.txt"},
|
||||
|
||||
@@ -74,7 +74,7 @@ func Validate(o *options.Options) error {
|
||||
var redirectURL *url.URL
|
||||
redirectURL, msgs = parseURL(o.RawRedirectURL, "redirect", msgs)
|
||||
o.SetRedirectURL(redirectURL)
|
||||
if o.RawRedirectURL == "" && !o.Cookie.Secure && !o.ReverseProxy {
|
||||
if o.RawRedirectURL == "" && !ptr.Deref(o.Cookie.Secure, options.DefaultCookieSecure) && !o.ReverseProxy {
|
||||
logger.Print("WARNING: no explicit redirect URL: redirects will default to insecure HTTP")
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ func testOptions() *options.Options {
|
||||
o.Providers[0].ClientID = clientID
|
||||
o.Providers[0].ClientSecret = clientSecret
|
||||
o.EmailDomains = []string{"*"}
|
||||
o.EnsureDefaults()
|
||||
return o
|
||||
}
|
||||
|
||||
@@ -45,6 +46,8 @@ func errorMsg(msgs []string) string {
|
||||
func TestNewOptions(t *testing.T) {
|
||||
o := options.NewOptions()
|
||||
o.EmailDomains = []string{"*"}
|
||||
o.EnsureDefaults()
|
||||
|
||||
err := Validate(o)
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user