From d16524510a7788a1e2016313c991c31d4f3aed69 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Mon, 6 Oct 2025 16:04:35 +0200 Subject: [PATCH] adapt tests Signed-off-by: Christian Richter --- services/proxy/pkg/middleware/security.go | 1 + services/proxy/pkg/middleware/security_test.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/services/proxy/pkg/middleware/security.go b/services/proxy/pkg/middleware/security.go index 1422d927b..ca117c38e 100644 --- a/services/proxy/pkg/middleware/security.go +++ b/services/proxy/pkg/middleware/security.go @@ -32,6 +32,7 @@ func loadCSPConfig(presetYamlContent, customYamlContent []byte) (*config.CSP, er // or load preset first and then custom to override values // especially in hindsight that there will be autoloaded config files from webapps // in the future + // TIL: gofig does not merge, it overwrites values from later sources err := gofig.LoadSources("yaml", presetYamlContent, customYamlContent) if err != nil { return nil, err diff --git a/services/proxy/pkg/middleware/security_test.go b/services/proxy/pkg/middleware/security_test.go index 01accf2c2..18b73308f 100644 --- a/services/proxy/pkg/middleware/security_test.go +++ b/services/proxy/pkg/middleware/security_test.go @@ -8,7 +8,7 @@ import ( func TestLoadCSPConfig(t *testing.T) { // setup test env - yaml := ` + presetYaml := ` directives: frame-src: - '''self''' @@ -17,12 +17,24 @@ directives: - 'https://${COLLABORA_DOMAIN|collabora.opencloud.test}/' ` - config, err := loadCSPConfig([]byte(yaml)) + customYaml := ` +directives: + img-src: + - '''self''' + - 'data:' + frame-src: + - 'https://some.custom.domain/' +` + config, err := loadCSPConfig([]byte(presetYaml), []byte(customYaml)) if err != nil { t.Error(err) } + // TODO: this needs to be reworked into some contains assertion assert.Equal(t, config.Directives["frame-src"][0], "'self'") assert.Equal(t, config.Directives["frame-src"][1], "https://embed.diagrams.net/") assert.Equal(t, config.Directives["frame-src"][2], "https://onlyoffice.opencloud.test/") assert.Equal(t, config.Directives["frame-src"][3], "https://collabora.opencloud.test/") + + assert.Equal(t, config.Directives["img-src"][0], "'self'") + assert.Equal(t, config.Directives["img-src"][1], "data:") }