Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the test suite writes garbage to ~/.gitconfig #2604

Closed
tpickett66 opened this issue Oct 19, 2022 · 2 comments · Fixed by #3262
Closed

Running the test suite writes garbage to ~/.gitconfig #2604

tpickett66 opened this issue Oct 19, 2022 · 2 comments · Fixed by #3262
Labels
bug Something isn't working help wanted Good feature for contributors

Comments

@tpickett66
Copy link
Contributor

While working on PR #2599 I ran the test suite several times. Later, when I moved on to other work, I found myself unable to run terraform init due to git wanting a password to clone repositories. After looking through my git config I found the following new entries:

[url "https://user@hostname/"]
	insteadOf = ssh://git@hostname
[url "https://x-access-token/@github.com"]
	insteadOf = ssh://[email protected]
[url "https://x-access-token/@127.0.0.1:50571"]
	insteadOf = ssh://[email protected]:50571
[url "https://x-access-token/@some-host"]
	insteadOf = ssh://git@some-host
[url "https://x-access-token/@127.0.0.1:53454"]
	insteadOf = ssh://[email protected]:53454

Which traced back to Atlantis' test suite. Rather than overwriting developers config files the test suite should set some combination of GIT_CONFIG and GIT_CONFIG_GLOBAL to point git at a clean, temporary location.

@jamengual jamengual added bug Something isn't working help wanted Good feature for contributors labels Oct 20, 2022
@mrwacky42
Copy link
Contributor

mrwacky42 commented Oct 21, 2022

Looks like the culprit is the tests here: https://github.com/runatlantis/atlantis/blob/master/server/events/git_cred_writer_test.go#L128-L154

Based on git-config docs, how about something like this:

diff --git a/server/events/git_cred_writer_test.go b/server/events/git_cred_writer_test.go
index 9d9583ab..48533a5a 100644
--- a/server/events/git_cred_writer_test.go
+++ b/server/events/git_cred_writer_test.go
@@ -134,7 +134,9 @@ func TestWriteGitCreds_ConfigureGitCredentialHelper(t *testing.T) {
        Ok(t, err)

        expOutput := `store`
-       actOutput, err := exec.Command("git", "config", "--global", "credential.helper").Output()
+       cmd := exec.Command("git", "config", "--global", "credential.helper")
+       cmd.Env = append(os.Environ(), fmt.Sprintf("GIT_CONFIG_GLOBAL=%s", filepath.Join(tmp, "gitconfig")))
+       actOutput, err := cmd.Output()
        Ok(t, err)
        Equals(t, expOutput+"\n", string(actOutput))
 }

Well, running in Docker gets me this result, so .. Close but no cigar.

--- FAIL: TestWriteGitCreds_ErrIfCannotRead (0.04s)
    git_cred_writer_test.go:117: exp err to contain "open /tmp/2289098227/.git-credentials: permission denied" but err was nil

EDIT: Paying attention, I see this is a different test that's failing and the test also fails on unmodified code. I'll try again later, or make an actual PR.

@mrwacky42
Copy link
Contributor

mrwacky42 commented Oct 21, 2022

(And no, this is only part of the solution because this only reads from a new place, and WriteGitCreds() would need to be updated when testing.)

finnag added a commit to finnag/atlantis that referenced this issue Mar 24, 2023
The tests would mutate $HOME/.gitconfig and $HOME/.git-credentials.
Set the HOME environment variable to a suitable temporary
directory before running git commands that mutate the global config.

Fixes runatlantis#2604
jamengual pushed a commit that referenced this issue Mar 24, 2023
The tests would mutate $HOME/.gitconfig and $HOME/.git-credentials.
Set the HOME environment variable to a suitable temporary
directory before running git commands that mutate the global config.

Fixes #2604
nitrocode pushed a commit that referenced this issue May 5, 2023
The tests would mutate $HOME/.gitconfig and $HOME/.git-credentials.
Set the HOME environment variable to a suitable temporary
directory before running git commands that mutate the global config.

Fixes #2604
ijames-gc pushed a commit to gocardless/atlantis that referenced this issue Feb 13, 2024
)

The tests would mutate $HOME/.gitconfig and $HOME/.git-credentials.
Set the HOME environment variable to a suitable temporary
directory before running git commands that mutate the global config.

Fixes runatlantis#2604
ijames-gc pushed a commit to gocardless/atlantis that referenced this issue Feb 13, 2024
)

The tests would mutate $HOME/.gitconfig and $HOME/.git-credentials.
Set the HOME environment variable to a suitable temporary
directory before running git commands that mutate the global config.

Fixes runatlantis#2604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Good feature for contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants