55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPersonalAppearanceIsolationAndCAS(t *testing.T) {
|
|
s, admin, domain := configFixture(t)
|
|
p, err := s.store.CreatePasswordAccount(domain, "appearanceuser", "long test password", "Member", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
token, err := s.store.CreateAuthSession(domain, p.UUID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
endpoint := "/-/sys/config?panel=organizer§ion=appearance"
|
|
form := url.Values{"version": {"0"}, "home_wallpaper_path": {""}, "home_wallpaper_opacity": {"50"}, "home_glass_transparency": {"71"}, "home_palette_mode": {"accent"}, "home_palette_strength": {"55"}, "home_palette_brightness": {"preserve"}}
|
|
w := configRequest(s, token, "POST", endpoint, form)
|
|
if w.Code != 303 || w.Header().Get("Location") != "/-/sys/config?panel=organizer#appearance" {
|
|
t.Fatal(w.Code, w.Body)
|
|
}
|
|
if w = configRequest(s, token, "POST", endpoint, form); w.Code != 409 {
|
|
t.Fatal("stale write", w.Code, w.Body)
|
|
}
|
|
w = configRequest(s, token, "GET", "/-/sys/config?panel=organizer", nil)
|
|
if w.Code != 200 || !strings.Contains(w.Body.String(), `name="home_glass_transparency" type="number" min="0" max="85" value="71"`) {
|
|
t.Fatal("personal value missing", w.Code, w.Body)
|
|
}
|
|
w = configRequest(s, admin, "GET", "/-/sys/config?panel=organizer", nil)
|
|
if w.Code != 200 || strings.Contains(w.Body.String(), `max="85" value="71"`) {
|
|
t.Fatal("owner leakage", w.Code)
|
|
}
|
|
raw, _ := s.store.GetConfigInDomain(domain, "home_glass_transparency")
|
|
if raw == "71" {
|
|
t.Fatal("changed domain settings")
|
|
}
|
|
if w = configRequest(s, "", "POST", endpoint, form); w.Code == 303 && w.Header().Get("Location") == "/-/sys/config?panel=organizer#appearance" {
|
|
t.Fatal("anonymous write")
|
|
}
|
|
if err = s.store.SetPrincipalState(domain, p.UUID, "readonly"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
token, err = s.store.CreateAuthSession(domain, p.UUID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
form.Set("version", "1")
|
|
if w = configRequest(s, token, "POST", endpoint, form); w.Code != 403 {
|
|
t.Fatal("readonly write", w.Code)
|
|
}
|
|
}
|