diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 85a8999eab5..002c2006396 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -645,7 +645,7 @@ Secret key. e.g. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Url to where Grafana will send PUT request with images ### public_url -Url to send to users in notifications, directly appended with the resulting uploaded file name +Optional parameter. Url to send to users in notifications, directly appended with the resulting uploaded file name. ### username basic auth username diff --git a/pkg/components/imguploader/s3uploader_test.go b/pkg/components/imguploader/s3uploader_test.go index 1204a2db4e2..f75ad05af64 100644 --- a/pkg/components/imguploader/s3uploader_test.go +++ b/pkg/components/imguploader/s3uploader_test.go @@ -8,7 +8,7 @@ import ( ) func TestUploadToS3(t *testing.T) { - SkipConvey("[Integration test] for external_image_store.webdav", t, func() { + SkipConvey("[Integration test] for external_image_store.s3", t, func() { setting.NewConfigContext(&setting.CommandLineArgs{ HomePath: "../../../", }) diff --git a/pkg/components/imguploader/webdavuploader.go b/pkg/components/imguploader/webdavuploader.go index 250b76165fe..ae3c5b5e194 100644 --- a/pkg/components/imguploader/webdavuploader.go +++ b/pkg/components/imguploader/webdavuploader.go @@ -56,10 +56,12 @@ func (u *WebdavUploader) Upload(pa string) (string, error) { } if u.public_url != "" { - return (u.public_url + filename), nil - } else { - return url.String(), nil + publicURL, _ := url.Parse(u.public_url) + publicURL.Path = path.Join(publicURL.Path, filename) + return publicURL.String(), nil } + + return url.String(), nil } func NewWebdavImageUploader(url, username, password, public_url string) (*WebdavUploader, error) { diff --git a/pkg/components/imguploader/webdavuploader_test.go b/pkg/components/imguploader/webdavuploader_test.go index 93813791de5..e88e28bd712 100644 --- a/pkg/components/imguploader/webdavuploader_test.go +++ b/pkg/components/imguploader/webdavuploader_test.go @@ -7,12 +7,21 @@ import ( ) func TestUploadToWebdav(t *testing.T) { - webdavUploader, _ := NewWebdavImageUploader("http://localhost:9998/dav/", "username", "password", "") + // Can be tested with this docker container: https://hub.docker.com/r/morrisjobke/webdav/ SkipConvey("[Integration test] for external_image_store.webdav", t, func() { + webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "") path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png") So(err, ShouldBeNil) - So(path, ShouldNotEqual, "") + So(path, ShouldStartWith, "http://localhost:8888/webdav/") + }) + + SkipConvey("[Integration test] for external_image_store.webdav with public url", t, func() { + webdavUploader, _ := NewWebdavImageUploader("http://localhost:8888/webdav/", "test", "test", "http://publicurl:8888/webdav") + path, err := webdavUploader.Upload("../../../public/img/logo_transparent_400x.png") + + So(err, ShouldBeNil) + So(path, ShouldStartWith, "http://publicurl:8888/webdav/") }) }