From 0db42459ce59786a8559785f090501eaeba3bf15 Mon Sep 17 00:00:00 2001 From: Spencer Schrock Date: Thu, 2 Jan 2025 11:03:25 -0700 Subject: [PATCH] add path traversal test Signed-off-by: Spencer Schrock --- internal/gitfile/gitfile_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/gitfile/gitfile_test.go b/internal/gitfile/gitfile_test.go index 2592ddb2348..01ecb144e0b 100644 --- a/internal/gitfile/gitfile_test.go +++ b/internal/gitfile/gitfile_test.go @@ -16,6 +16,7 @@ package gitfile import ( "context" + "errors" "io" "os" "path/filepath" @@ -69,6 +70,19 @@ func TestHandler(t *testing.T) { } } +func TestHandlerPathTraversal(t *testing.T) { + t.Parallel() + dir := setupGitRepo(t) + + var h Handler + h.Init(context.Background(), dir, "HEAD") + + _, err := h.GetFile("../example.txt") + if !errors.Is(err, errPathTraversal) { + t.Fatalf("expected path traversal error: got %v", err) + } +} + func setupGitRepo(t *testing.T) string { t.Helper()