Skip to content

Commit

Permalink
add path traversal test
Browse files Browse the repository at this point in the history
Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock committed Jan 2, 2025
1 parent 498e3c5 commit 0db4245
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/gitfile/gitfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gitfile

import (
"context"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 0db4245

Please sign in to comment.