Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions internal/gitserver/gitdomain/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestIsAllowedGitCmd(t *testing.T) {
allowed := [][]string{
isAllowed := [][]string{
// Required for code monitors
{"rev-parse", "HEAD"},
{"rev-parse", "83838383"},
Expand All @@ -27,15 +27,28 @@ func TestIsAllowedGitCmd(t *testing.T) {
{"push", "--force", "git@github.com:repo/name", "f22cfd066432e382c24f1eaa867444671e23a136:refs/heads/a-branch"},
{"update-ref", "--"},
}
notAllowed := [][]string{
{"commit", "-F", "/etc/passwd"},
{"commit", "--file=/absolute/path"},
{"commit", "-F", "relative/passwd"},
{"commit", "--file=relative/path"},
}

logger := logtest.Scoped(t)
for _, args := range allowed {
for _, args := range isAllowed {
t.Run("", func(t *testing.T) {
if !IsAllowedGitCmd(logger, args, "/fake/path") {
t.Fatalf("expected args to be allowed: %q", args)
}
})
}
for _, args := range notAllowed {
t.Run("", func(t *testing.T) {
if IsAllowedGitCmd(logger, args, "/fake/path") {
t.Fatalf("expected args to NOT be allowed: %q", args)
}
})
}
}

func TestIsAllowedDiffGitCmd(t *testing.T) {
Expand Down