Skip to content

Authenticate network git commands - #6541

Merged
samcoe merged 5 commits into
trunkfrom
git-auth-commands
Nov 15, 2022
Merged

samcoe merged 5 commits into
trunkfrom
git-auth-commands

Conversation

@samcoe

@samcoe samcoe commented Oct 31, 2022 •

Copy link
Copy Markdown
Contributor

The PR changes git client to now use gh as the default credential manager for authentication. For now, this is only applying to network git commands such as Fetch, Pull, Pull, Clone, AddRemote. The majority of the line changes in this PR are fixing up tests.

cc #2944

@samcoe samcoe self-assigned this Oct 31, 2022
Comment thread git/client.go
Comment thread pkg/cmd/pr/checkout/checkout.go Outdated
@samcoe
samcoe marked this pull request as ready for review November 1, 2022 05:30
@samcoe
samcoe requested a review from a team as a code owner November 1, 2022 05:30
@samcoe
samcoe requested review from vilmibm and removed request for a team November 1, 2022 05:30
Base automatically changed from git-client-cleanup-2 to trunk November 3, 2022 10:58
@samcoe
samcoe force-pushed the git-auth-commands branch from 3b813e8 to 4da8cd2 Compare November 3, 2022 11:14

@slumericanbds slumericanbds left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks great but the diff in tests seems excessive. A potential solution proposed in comments

Comment thread pkg/cmd/gist/clone/clone_test.go Outdated
name: "shorthand",
args: "GIST",
want: "git clone https://gist.github.com/GIST.git",
want: `git -c credential.helper= -c credential.helper=!"some/path/gh" auth git-credential clone https://gist.github.com/GIST.git`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's potentially worrying that this implementation detail is now added to the expectation in so many tests unrelated to authentication itself. If we ever change a single character of this, all these tests will also have to be updated.

Should these test assertions attempt to normalize the git invocation line with a single shared helper that can be kept to sync with the authentication implementation?

@samcoe samcoe Nov 9, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree it is not great. It is a product of how these tests were written in the past. Two solutions I can think of:

  1. Modify all these commands to use an interface which is fulfilled by git.Client and then in tests mock out the method calls. This would be a good amount of work, but is also probably the most "go" way.
  2. Add a function to the CommandStubber specific for registering git commands which would create a single place where the authentication string would be.

What are your thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed option (1) would be the most "correct" but perhaps infeasible for this PR. How about option 3: make a test helper that converts a string like git -c credential.helper= -c credential.helper=... <command> <args> to git <command> <args> and use that in equality assertions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily like that approach as it weakens the assertions about the git commands being invoked and would no longer assert that gh was set as the credential helper, which is the purpose of this PR.

@samcoe
samcoe requested a review from mislav November 10, 2022 11:09

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig the workaround you ended up on; thanks. Only optional suggestions remain

Comment thread pkg/cmd/repo/create/create.go Outdated
Comment thread internal/run/stub.go Outdated
Comment thread internal/run/stub.go Outdated
@samcoe
samcoe merged commit 98ab1f2 into trunk Nov 15, 2022
@samcoe
samcoe deleted the git-auth-commands branch November 15, 2022 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants