Storage: externalize allow_unsanitized_svg_upload (#52703)
This commit is contained in:
@@ -194,9 +194,7 @@ func ProvideService(sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles,
|
||||
}
|
||||
})
|
||||
|
||||
return newStandardStorageService(sql, globalRoots, initializeOrgStorages, authService, storageServiceConfig{
|
||||
allowUnsanitizedSvgUpload: false,
|
||||
})
|
||||
return newStandardStorageService(sql, globalRoots, initializeOrgStorages, authService, cfg)
|
||||
}
|
||||
|
||||
func createSystemBrandingPathFilter() filestorage.PathFilter {
|
||||
@@ -207,7 +205,7 @@ func createSystemBrandingPathFilter() filestorage.PathFilter {
|
||||
nil)
|
||||
}
|
||||
|
||||
func newStandardStorageService(sql *sqlstore.SQLStore, globalRoots []storageRuntime, initializeOrgStorages func(orgId int64) []storageRuntime, authService storageAuthService, cfg storageServiceConfig) *standardStorageService {
|
||||
func newStandardStorageService(sql *sqlstore.SQLStore, globalRoots []storageRuntime, initializeOrgStorages func(orgId int64) []storageRuntime, authService storageAuthService, cfg *setting.Cfg) *standardStorageService {
|
||||
rootsByOrgId := make(map[int64][]storageRuntime)
|
||||
rootsByOrgId[ac.GlobalOrgID] = globalRoots
|
||||
|
||||
@@ -220,7 +218,9 @@ func newStandardStorageService(sql *sqlstore.SQLStore, globalRoots []storageRunt
|
||||
sql: sql,
|
||||
tree: res,
|
||||
authService: authService,
|
||||
cfg: cfg,
|
||||
cfg: storageServiceConfig{
|
||||
allowUnsanitizedSvgUpload: cfg.Storage.AllowUnsanitizedSvgUpload,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,18 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/filestorage"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg = &setting.Cfg{
|
||||
Storage: setting.StorageSettings{
|
||||
AllowUnsanitizedSvgUpload: true,
|
||||
},
|
||||
}
|
||||
htmlBytes, _ = ioutil.ReadFile("testdata/page.html")
|
||||
jpgBytes, _ = ioutil.ReadFile("testdata/image.jpg")
|
||||
svgBytes, _ = ioutil.ReadFile("testdata/image.svg")
|
||||
@@ -57,7 +63,7 @@ func TestListFiles(t *testing.T) {
|
||||
|
||||
store := newStandardStorageService(sqlstore.InitTestDB(t), roots, func(orgId int64) []storageRuntime {
|
||||
return make([]storageRuntime, 0)
|
||||
}, allowAllAuthService, storageServiceConfig{})
|
||||
}, allowAllAuthService, cfg)
|
||||
frame, err := store.List(context.Background(), dummyUser, "public/testdata")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -77,7 +83,7 @@ func TestListFilesWithoutPermissions(t *testing.T) {
|
||||
|
||||
store := newStandardStorageService(sqlstore.InitTestDB(t), roots, func(orgId int64) []storageRuntime {
|
||||
return make([]storageRuntime, 0)
|
||||
}, denyAllAuthService, storageServiceConfig{})
|
||||
}, denyAllAuthService, cfg)
|
||||
frame, err := store.List(context.Background(), dummyUser, "public/testdata")
|
||||
require.NoError(t, err)
|
||||
rowLen, err := frame.RowLen()
|
||||
@@ -102,7 +108,7 @@ func setupUploadStore(t *testing.T, authService storageAuthService) (StorageServ
|
||||
}
|
||||
store := newStandardStorageService(sqlstore.InitTestDB(t), []storageRuntime{sqlStorage}, func(orgId int64) []storageRuntime {
|
||||
return make([]storageRuntime, 0)
|
||||
}, authService, storageServiceConfig{allowUnsanitizedSvgUpload: true})
|
||||
}, authService, cfg)
|
||||
|
||||
return store, mockStorage, storageName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user