MCPcopy
hub / github.com/larksuite/cli / TestSafeUploadPath_AcceptsRelativePath

Function TestSafeUploadPath_AcceptsRelativePath

internal/validate/path_test.go:242–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

240}
241
242func TestSafeUploadPath_AcceptsRelativePath(t *testing.T) {
243 // GIVEN: a clean temp CWD with a real file
244 dir := t.TempDir()
245 dir, _ = filepath.EvalSymlinks(dir)
246 orig, _ := os.Getwd()
247 defer os.Chdir(orig)
248 os.Chdir(dir)
249
250 os.WriteFile(filepath.Join(dir, "upload.bin"), []byte("data"), 0600)
251
252 // WHEN: SafeUploadPath validates a relative path to an existing file
253 got, err := SafeInputPath("upload.bin")
254
255 // THEN: accepted and returned as absolute canonical path
256 if err != nil {
257 t.Fatalf("SafeUploadPath(relative) error = %v", err)
258 }
259 want := filepath.Join(dir, "upload.bin")
260 if got != want {
261 t.Errorf("SafeUploadPath(relative) = %q, want %q", got, want)
262 }
263}
264
265func TestSafeInputPath_ErrorMessageContainsCorrectFlagName(t *testing.T) {
266 // GIVEN: an absolute path

Callers

nothing calls this directly

Calls 4

SafeInputPathFunction · 0.70
EvalSymlinksMethod · 0.65
GetwdMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected