MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestSafeTemplateFilepath

Function TestSafeTemplateFilepath

pkg/alertmanager/multitenant_test.go:2293–2319  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2291}
2292
2293func TestSafeTemplateFilepath(t *testing.T) {
2294 tests := map[string]struct {
2295 dir string
2296 template string
2297 expectedPath string
2298 expectedErr error
2299 }{
2300 "should succeed if the provided template is a filename": {
2301 dir: "/data/tenant",
2302 template: "test.tmpl",
2303 expectedPath: "/data/tenant/test.tmpl",
2304 },
2305 "should fail if the provided template is escaping the dir": {
2306 dir: "/data/tenant",
2307 template: "../test.tmpl",
2308 expectedErr: errors.New(`invalid template name "../test.tmpl": the template filepath is escaping the per-tenant local directory`),
2309 },
2310 }
2311
2312 for testName, testData := range tests {
2313 t.Run(testName, func(t *testing.T) {
2314 actualPath, actualErr := safeTemplateFilepath(testData.dir, testData.template)
2315 assert.Equal(t, testData.expectedErr, actualErr)
2316 assert.Equal(t, testData.expectedPath, actualPath)
2317 })
2318 }
2319}
2320
2321func TestStoreTemplateFile(t *testing.T) {
2322 testTemplateDir := filepath.Join(t.TempDir(), templatesDir)

Callers

nothing calls this directly

Calls 3

safeTemplateFilepathFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected