-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent git commands in dangerous dirs (#222)
* Prevent git commands in dangerous dirs * Try E2E * Go fix * Fix vendoring and lint * Tweak message * lint * Tweak message * Fix fmt * Add escape hatch
- Loading branch information
Showing
12 changed files
with
3,711 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package step | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/bitrise-io/go-steputils/v2/stepconf" | ||
"github.com/bitrise-io/go-utils/v2/command" | ||
"github.com/bitrise-io/go-utils/v2/env" | ||
"github.com/bitrise-io/go-utils/v2/log" | ||
"github.com/bitrise-io/go-utils/v2/pathutil" | ||
"github.com/bitrise-steplib/steps-git-clone/gitclone/tracker" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GitCloneStep_IsCloneDirDangerous(t *testing.T) { | ||
home, err := os.UserHomeDir() | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
path string | ||
expected bool | ||
}{ | ||
{ | ||
name: "Safe path in temp dir", | ||
path: "$TMPDIR/clone", | ||
expected: false, | ||
}, | ||
{ | ||
name: "Safe path in home", | ||
path: filepath.Join(home, "clone"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "Home as env var", | ||
path: "$HOME", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Home as tilde", | ||
path: "~", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Home as absolute path", | ||
path: home, | ||
expected: true, | ||
}, | ||
{ | ||
name: "Dangerous path with tilde", | ||
path: "~/Documents", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Dangerous absolute path", | ||
path: filepath.Join(home, ".ssh"), | ||
expected: true, | ||
}, | ||
{ | ||
name: "Nonexistent env var only", | ||
path: "$NONEXISTENT", | ||
expected: false, | ||
}, | ||
} | ||
|
||
logger := log.NewLogger() | ||
envRepo := env.NewRepository() | ||
tracker := tracker.NewStepTracker(envRepo, logger) | ||
inputParser := stepconf.NewInputParser(envRepo) | ||
cmdFactory := command.NewFactory(envRepo) | ||
pathModifier := pathutil.NewPathModifier() | ||
|
||
gitCloneStep := NewGitCloneStep(logger, tracker, inputParser, envRepo, cmdFactory, pathModifier) | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result := gitCloneStep.isCloneDirDangerous(test.path) | ||
require.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
vendor/github.com/stretchr/testify/require/forward_requirements.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.