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

Rework first auth tests with new gitcredential abstractions #9095

Merged

Conversation

williammartin
Copy link
Member

@williammartin williammartin commented May 17, 2024

Description

This is a follow up to #9089 as progress towards #8875.

In #9089 new abstractions were introduced to more clearly separate the configuration of git credentials configuration, and informing the helpers of updated credentials.

This PR now cleaves GitCredentialFlow and gitcredentials.HelperConfig by introducing a HelperConfig interface on the consumer side. We introduce a contract test that can be run by concrete implementations of this interface to ensure they are able to be test doubled with confidence. That is, a new gitcredentials.FakeHelperConfig can be used in place of the gitcredentials.HelperConfig without requiring git and an isolated config (instead, that is only needed for the HelperConfig at the leaf of the dependency graph).

This FakeHelperConfig can then be used in the LoginFlow tests, of which I have created exactly one to demonstrate this pattern. The purpose of this new test is to ensure that when no credential helper is found for the targeted host, the user is presented with a prompt, and when they accept that prompt, gh is configured as their credential helper.

Summed up, it makes this branch go from red to green:

Login Flow:

image showing test coverage of the previous links code

And therefore all of this GitCredentialFlow code goes green too:

image showing test coverage of the previous links code

Why now?

In #8875 I want to lean on these abstractions to ensure that auth switch exhibits similar behaviour but it should be easier to develop and review in smaller incremental steps demonstrating the pattern with existing code.

@williammartin williammartin requested a review from a team as a code owner May 17, 2024 12:47
@williammartin williammartin changed the title Rework first auth tests with new gitcredential abstractions" Rework first auth tests with new gitcredential abstractions May 17, 2024
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI May 17, 2024
@@ -33,105 +35,40 @@ func configureTestCredentialHelper(t *testing.T, key string) {
require.NoError(t, cmd.Run())
}

func TestConfigureOursNoPreexistingHelpersConfigured(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These became part of the contract

// Then gh is configured as their credential helper for that host
ios, _, _, _ := iostreams.Test()

reg := &httpmock.Registry{}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm happy to look into figuring out how this test would fit into the table tests but I wanted it to be very clear in exactly what it was doing for this review.

Copy link
Contributor

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

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

shipit-squirrel-stareyes

Having read through it 2-3 times, looks good; nothing stands out so let's go!

@williammartin williammartin merged commit 3b9f9a8 into trunk May 17, 2024
16 checks passed
@williammartin williammartin deleted the wm/rework-auth-tests-with-new-credential-abstractions branch May 17, 2024 13:26
izumin5210 pushed a commit to izumin5210/dotfiles that referenced this pull request Jun 2, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://togithub.com/cli/cli) | minor | `v2.49.2` ->
`v2.50.0` |

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.50.0`](https://togithub.com/cli/cli/releases/tag/v2.50.0):
GitHub CLI 2.50.0

[Compare Source](https://togithub.com/cli/cli/compare/v2.49.2...v2.50.0)

#### What's Changed

- Refactor git credential flow code by
[@&#8203;williammartin](https://togithub.com/williammartin) in
[cli/cli#9089
- feat: add json output for `gh pr checks` by
[@&#8203;nobe4](https://togithub.com/nobe4) in
[cli/cli#9079
- Rework first auth tests with new gitcredential abstractions by
[@&#8203;williammartin](https://togithub.com/williammartin) in
[cli/cli#9095
- list the various alias permutations for the command and subcommands,
via '--help' and 'gh reference' by
[@&#8203;gabemontero](https://togithub.com/gabemontero) in
[cli/cli#8824
- Removed tty message when checking for extension upgrades by
[@&#8203;leevic31](https://togithub.com/leevic31) in
[cli/cli#9088
- Fix doc bug for gh run watch by
[@&#8203;jasonodonnell](https://togithub.com/jasonodonnell) in
[cli/cli#9052
- feat: add support for stateReason in `gh pr view` by
[@&#8203;nobe4](https://togithub.com/nobe4) in
[cli/cli#9080
- fix: rename the `Attempts` field to `Attempt`; expose in `gh run view`
and `gh run ls` by [@&#8203;cawfeecake](https://togithub.com/cawfeecake)
in
[cli/cli#8905
- Update regex in changedFilesNames to handle quoted paths by
[@&#8203;anda3](https://togithub.com/anda3) in
[cli/cli#9115
- Add a `gh variable get FOO` command by
[@&#8203;arnested](https://togithub.com/arnested) in
[cli/cli#9106
- Add macOS pkg installer to deployment
([#&#8203;7554](https://togithub.com/cli/cli/issues/7554)) by
[@&#8203;paulober](https://togithub.com/paulober) in
[cli/cli#7555
- Add integration tests for `gh attestation verify` shared workflow use
case by [@&#8203;malancas](https://togithub.com/malancas) in
[cli/cli#9107
- Add build provenance for gh CLI releases by
[@&#8203;malancas](https://togithub.com/malancas) in
[cli/cli#9087
- build(deps): bump github.com/gabriel-vasile/mimetype from 1.4.3 to
1.4.4 by [@&#8203;dependabot](https://togithub.com/dependabot) in
[cli/cli#9124
- Build completions during release on macos by
[@&#8203;williammartin](https://togithub.com/williammartin) in
[cli/cli#9136
- Clarify Mac OS Installer packages are unsigned by
[@&#8203;andyfeller](https://togithub.com/andyfeller) in
[cli/cli#9140

#### New Contributors

- [@&#8203;gabemontero](https://togithub.com/gabemontero) made their
first contribution in
[cli/cli#8824
- [@&#8203;jasonodonnell](https://togithub.com/jasonodonnell) made their
first contribution in
[cli/cli#9052
- [@&#8203;anda3](https://togithub.com/anda3) made their first
contribution in
[cli/cli#9115
- [@&#8203;arnested](https://togithub.com/arnested) made their first
contribution in
[cli/cli#9106
- [@&#8203;paulober](https://togithub.com/paulober) made their first
contribution in
[cli/cli#7555

**Full Changelog**: cli/cli@v2.49.2...v2.50.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/izumin5210/dotfiles).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: izumin5210-update-aqua-checksum[bot] <169593670+izumin5210-update-aqua-checksum[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Needs review 🤔
Development

Successfully merging this pull request may close these issues.

None yet

2 participants