(t *testing.T)
| 2291 | } |
| 2292 | |
| 2293 | func 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 | |
| 2321 | func TestStoreTemplateFile(t *testing.T) { |
| 2322 | testTemplateDir := filepath.Join(t.TempDir(), templatesDir) |
nothing calls this directly
no test coverage detected