diff --git a/services/webdav/pkg/config/defaults/defaultconfig.go b/services/webdav/pkg/config/defaults/defaultconfig.go index 7105473cb1..9110d4937b 100644 --- a/services/webdav/pkg/config/defaults/defaultconfig.go +++ b/services/webdav/pkg/config/defaults/defaultconfig.go @@ -83,6 +83,8 @@ func Sanitize(cfg *config.Config) { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } + cfg.TikaThumbnailPreset = strings.TrimSpace(cfg.TikaThumbnailPreset) + // a yaml configuration that joined the resolutions into one entry kept // working in the thumbnails service, so it keeps working here if len(cfg.Thumbnails.Resolutions) == 1 && strings.Contains(cfg.Thumbnails.Resolutions[0], ",") { diff --git a/services/webdav/pkg/config/parser/parse.go b/services/webdav/pkg/config/parser/parse.go index 4d7d4a94dd..2faacfb0c3 100644 --- a/services/webdav/pkg/config/parser/parse.go +++ b/services/webdav/pkg/config/parser/parse.go @@ -2,7 +2,6 @@ package parser import ( "errors" - "strings" occfg "github.com/opencloud-eu/opencloud/pkg/config" "github.com/opencloud-eu/opencloud/services/webdav/pkg/config" @@ -34,7 +33,7 @@ func ParseConfig(cfg *config.Config) error { } func Validate(cfg *config.Config) error { - if strings.TrimSpace(cfg.TikaThumbnailPreset) == "" { + if cfg.TikaThumbnailPreset == "" { return errors.New("OC_TIKA_THUMBNAIL_PRESET must not be empty") } return nil diff --git a/services/webdav/pkg/config/parser/parse_test.go b/services/webdav/pkg/config/parser/parse_test.go index 882e8d8ae6..d8af382dbf 100644 --- a/services/webdav/pkg/config/parser/parse_test.go +++ b/services/webdav/pkg/config/parser/parse_test.go @@ -62,4 +62,18 @@ var _ = Describe("ParseConfig", func() { Expect(parser.ParseConfig(cfg)).To(Succeed()) Expect(cfg.TikaThumbnailPreset).To(Equal("previews")) }) + + It("trims the Tika thumbnail preset, so it reaches the URL as configured", func() { + GinkgoT().Setenv("OC_TIKA_THUMBNAIL_PRESET", " previews ") + + cfg := defaults.DefaultConfig() + Expect(parser.ParseConfig(cfg)).To(Succeed()) + Expect(cfg.TikaThumbnailPreset).To(Equal("previews")) + }) + + It("refuses a Tika thumbnail preset of only blanks", func() { + GinkgoT().Setenv("OC_TIKA_THUMBNAIL_PRESET", " ") + + Expect(parser.ParseConfig(defaults.DefaultConfig())).To(MatchError(ContainSubstring("OC_TIKA_THUMBNAIL_PRESET"))) + }) }) diff --git a/services/webdav/pkg/preprocessor/tika_test.go b/services/webdav/pkg/preprocessor/tika_test.go index 3b6820ec53..897463aa6d 100644 --- a/services/webdav/pkg/preprocessor/tika_test.go +++ b/services/webdav/pkg/preprocessor/tika_test.go @@ -16,6 +16,11 @@ import ( "github.com/opencloud-eu/opencloud/services/webdav/pkg/thumbnail" ) +// newTika builds a Tika with the default preset, which these tests do not vary. +func newTika(url string, mimeTypes, additional []string) thumbnail.Tika { + return thumbnail.NewTika(url, "thumbnail", mimeTypes, additional) +} + // presetZip builds what /unpack/preset/thumbnail returns: the image the preset // selected, and whatever bookkeeping the package carries beside it. func presetZip(entries map[string][]byte) []byte { @@ -148,9 +153,9 @@ var _ = Describe("TikaThumbnail", func() { var _ = Describe("ForType with a Tika server", func() { const tikaURL = "http://tika:9998" - named := thumbnail.NewTika(tikaURL, "thumbnail", thumbnail.DefaultTikaTypes, nil) - everything := thumbnail.NewTika(tikaURL, "thumbnail", []string{"*"}, nil) - off := thumbnail.NewTika("", "thumbnail", thumbnail.DefaultTikaTypes, nil) + named := newTika(tikaURL, thumbnail.DefaultTikaTypes, nil) + everything := newTika(tikaURL, []string{"*"}, nil) + off := newTika("", thumbnail.DefaultTikaTypes, nil) tika := BeAssignableToTypeOf(TikaThumbnail{}) generator := BeNil() @@ -183,7 +188,7 @@ var _ = Describe("ForType with a Tika server", func() { } It("hands the mapped type to Tika", func() { - t := thumbnail.NewTika(tikaURL, "thumbnail", []string{"application/pdf", "image/x-nikon-nef:image/x-raw-nikon"}, nil) + t := newTika(tikaURL, []string{"application/pdf", "image/x-nikon-nef:image/x-raw-nikon"}, nil) Expect(ForType("image/x-nikon-nef", Options{Tika: t}).(TikaThumbnail).contentType).To(Equal("image/x-raw-nikon")) }) }) diff --git a/services/webdav/pkg/thumbnail/tika_test.go b/services/webdav/pkg/thumbnail/tika_test.go index 5de95dacc2..d5d362fe2f 100644 --- a/services/webdav/pkg/thumbnail/tika_test.go +++ b/services/webdav/pkg/thumbnail/tika_test.go @@ -7,14 +7,19 @@ import ( "github.com/opencloud-eu/opencloud/services/webdav/pkg/thumbnail" ) +// newTika builds a Tika with the default preset, which these tests do not vary. +func newTika(url string, mimeTypes, additional []string) thumbnail.Tika { + return thumbnail.NewTika(url, "thumbnail", mimeTypes, additional) +} + var _ = Describe("Tika", func() { - none := thumbnail.NewTika("", "thumbnail", thumbnail.DefaultTikaTypes, nil) - all := thumbnail.NewTika("http://tika:9998", "thumbnail", []string{"*"}, nil) - nothing := thumbnail.NewTika("http://tika:9998", "thumbnail", nil, nil) - some := thumbnail.NewTika("http://tika:9998", "thumbnail", []string{" Application/PDF ", "audio/mpeg", "image/x-nikon-nef:image/x-raw-nikon"}, nil) - built := thumbnail.NewTika("http://tika:9998", "thumbnail", thumbnail.DefaultTikaTypes, nil) - extended := thumbnail.NewTika("http://tika:9998", "thumbnail", thumbnail.DefaultTikaTypes, []string{"application/zip", "image/heic"}) - extendedAll := thumbnail.NewTika("http://tika:9998", "thumbnail", thumbnail.DefaultTikaTypes, []string{"*"}) + none := newTika("", thumbnail.DefaultTikaTypes, nil) + all := newTika("http://tika:9998", []string{"*"}, nil) + nothing := newTika("http://tika:9998", nil, nil) + some := newTika("http://tika:9998", []string{" Application/PDF ", "audio/mpeg", "image/x-nikon-nef:image/x-raw-nikon"}, nil) + built := newTika("http://tika:9998", thumbnail.DefaultTikaTypes, nil) + extended := newTika("http://tika:9998", thumbnail.DefaultTikaTypes, []string{"application/zip", "image/heic"}) + extendedAll := newTika("http://tika:9998", thumbnail.DefaultTikaTypes, []string{"*"}) DescribeTable("Supports", func(tika thumbnail.Tika, mimeType string, want bool) {