fix(webdav): trim the Tika thumbnail preset once in Sanitize

The check trimmed the preset but the URL took it untrimmed, so " thumbnail"
started fine and then answered 404 for /unpack/preset/%20thumbnail. Sanitize
trims it now and Validate only compares against "". The tests build their
Tika through a helper that sets the default preset.
This commit is contained in:
Dominik Schmidt committed 2026-12-02 16:43:53 +01:00
1 parent 17a9874be2
commit 0ac1ea8e30
5 files changed
+38 -13

No files matched your search

@@ -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], ",") {
+1 -2
View File
@@ -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
@@ -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")))
})
})
@@ -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"))
})
})
+12 -7
View File
@@ -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) {