Signed-off-by: Vikram Vaswani <2571660+vvaswani@users.noreply.github.com> Signed-off-by: Jakob Borg <jakob@kastelo.net> Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -786,6 +786,32 @@ func TestGUIConfigURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGUISessionCookiePathPrepare(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{name: "empty stays empty", in: "", out: ""},
|
||||
{name: "already rooted", in: " /gui ", out: "/gui"},
|
||||
{name: "needs slash", in: "gui", out: "/gui"},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := GUIConfiguration{SessionCookiePath: tc.in}
|
||||
c.prepare()
|
||||
if c.SessionCookiePath != tc.out {
|
||||
t.Fatalf("unexpected path %q != %q", c.SessionCookiePath, tc.out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGUIPasswordHash(t *testing.T) {
|
||||
var c GUIConfiguration
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ type GUIConfiguration struct {
|
||||
InsecureSkipHostCheck bool `json:"insecureSkipHostcheck" xml:"insecureSkipHostcheck,omitempty"`
|
||||
InsecureAllowFrameLoading bool `json:"insecureAllowFrameLoading" xml:"insecureAllowFrameLoading,omitempty"`
|
||||
SendBasicAuthPrompt bool `json:"sendBasicAuthPrompt" xml:"sendBasicAuthPrompt,attr"`
|
||||
SessionCookieDurationS int `json:"sessionCookieDurationS" xml:"sessionCookieDurationS,omitempty" default:"604800"`
|
||||
SessionCookiePath string `json:"sessionCookiePath" xml:"sessionCookiePath,omitempty" default:"/"`
|
||||
}
|
||||
|
||||
func (c GUIConfiguration) IsAuthEnabled() bool {
|
||||
@@ -176,6 +178,12 @@ func (c *GUIConfiguration) prepare() {
|
||||
if c.APIKey == "" {
|
||||
c.APIKey = rand.String(32)
|
||||
}
|
||||
if path := strings.TrimSpace(c.SessionCookiePath); path != "" {
|
||||
if !strings.HasPrefix(path, "/") {
|
||||
path = "/" + path
|
||||
}
|
||||
c.SessionCookiePath = path
|
||||
}
|
||||
}
|
||||
|
||||
func (c GUIConfiguration) Copy() GUIConfiguration {
|
||||
|
||||
Reference in New Issue
Block a user