func TestEarliestCommits(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt")
	initialCommit := git.EarliestCommit(repo.root)
	git.AppendFileContent(repo.root, "a.txt", "\nmonkey see.\n", "monkey do.")
	git.AddAndcommit(repo.root, "a.txt", "modified content")
	assert.Equal(t, initialCommit, git.EarliestCommit(repo.root), "First commit is not expected to change on repo modifications")
}
Beispiel #2
0
func TestAddingSimpleFileShouldExitZero(t *testing.T) {
	withNewTmpGitRepo(func(gitPath string) {
		git.SetupBaselineFiles(gitPath, "simple-file")
		exitStatus := runTalisman(gitPath, git.EarliestCommit(gitPath), git.LatestCommit(gitPath))
		assert.Equal(t, 0, exitStatus, "Expected run() to return 0 and pass as no suspicious files are in the repo")
	})
}
Beispiel #3
0
func TestAddingSecretKeyShouldExitOne(t *testing.T) {
	withNewTmpGitRepo(func(gitPath string) {
		git.SetupBaselineFiles(gitPath, "simple-file")
		git.CreateFileWithContents(gitPath, "private.pem", "secret")
		git.AddAndcommit(gitPath, "*", "add private key")

		exitStatus := runTalisman(gitPath, git.EarliestCommit(gitPath), git.LatestCommit(gitPath))
		assert.Equal(t, 1, exitStatus, "Expected run() to return 1 and fail as pem file was present in the repo")
	})
}
func TestLatestCommits(t *testing.T) {
	cleanTestData()
	repo := RepoLocatedAt("data/testLocation1")
	git.Init(repo.root)
	git.SetupBaselineFiles(repo.root, "a.txt")
	git.AppendFileContent(repo.root, "a.txt", "\nmonkey see.\n", "monkey do.")
	git.AddAndcommit(repo.root, "a.txt", "modified content")
	git.AppendFileContent(repo.root, "a.txt", "\nline n-1.\n", "line n.")
	git.AddAndcommit(repo.root, "a.txt", "more modified content")
	assert.NotEqual(t, git.EarliestCommit(repo.root), git.LatestCommit(repo.root)) //bad test.
}
Beispiel #5
0
func TestAddingSecretKeyShouldExitZeroIfPEMFilesAreIgnored(t *testing.T) {
	withNewTmpGitRepo(func(gitPath string) {
		git.SetupBaselineFiles(gitPath, "simple-file")
		git.CreateFileWithContents(gitPath, "private.pem", "secret")
		git.CreateFileWithContents(gitPath, ".talismanignore", "*.pem")
		git.AddAndcommit(gitPath, "*", "add private key")

		exitStatus := runTalisman(gitPath, git.EarliestCommit(gitPath), git.LatestCommit(gitPath))
		assert.Equal(t, 0, exitStatus, "Expected run() to return 0 and pass as pem file was ignored")
	})
}
Beispiel #6
0
func runTalisman(gitPath, oldCommit, newCommit string) int {
	os.Chdir(gitPath)
	return run(mockStdIn(git.EarliestCommit(gitPath), git.LatestCommit(gitPath)))
}