-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add acceptance tests for gh auth commands
#9787
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
Merged
Merged
Conversation
This file contains hidden or 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
77bde46 to
76c2e08
Compare
jtmcg
commented
Oct 21, 2024
Additionally, this commit adds acceptance testing for `gh auth login` and `gh auth logout`. The --token flag was necessary for adding testing for `gh auth login` because the current implementation with `--with-token` appears to be broken. It hangs, waiting for user input, but user input doesn't exit it. Additionally, it appears that `--with-token` is intended to allow for TTY input of an auth token, but it isn't implemented. `--with-token` does work when used with the redirect operator `<` when the token is saved in a file. However, due to limitations of testscripts, I could not use a file for saving the token in a repeatable manner. Thus, implementing the `--token` flag seemed like a quick solution to validate that the direction I was going during testing was valid. Whether the flag stays or not is up for discussion, and I'd love to get input on that from the team.
The previous commit introduced two new functions, setEnvVar and deleteEnvVar that are duplicative of functionality native to testscripts. This commit switches to the native functionality and removes the duplicative functions introduced in the previous commit. Additionally, it removes the `--token` flag that was added to `gh auth login`
f78a727 to
98d20e6
Compare
98d20e6 to
0be0fd2
Compare
gh auth commands
williammartin
requested changes
Oct 23, 2024
…er func To test this, I decided to look into the .gitconfig used for the test and examine the credential helpers. However, the format of the git command is `git config --get credential.<URL>.helper` What's awkward about this is that the <URL> depends on the host the user specified when running the tests, meaning I'd need to create a key like credential.https://github.com.helper to access what I need while setting this up. There was no functionality for string formatting before, so I added the command formattedStringToEnv which essentially wraps fmt.Sprintf() and saves the string to an environment variable. This allowed me to dynamically create the config key in the test.
6f06eac to
6f707c9
Compare
6f707c9 to
2b480da
Compare
williammartin
approved these changes
Oct 24, 2024
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
➜ cli git:(jtmcg/testscripts-auth) set -o pipefail && GH_ACCEPTANCE_HOST=github.com GH_ACCEPTANCE_ORG=gh-acceptance-testing go test -tags acceptance -json -coverprofile=coverage.out -coverpkg=./... -run ^TestAuth$ github.com/cli/cli/v2/acceptance | tparse --all go test
┌────────────────────────────────────────────────────────────────────────────────────┐
│ STATUS │ ELAPSED │ TEST │ PACKAGE │
│─────────┼─────────┼────────────────────────────┼───────────────────────────────────│
│ PASS │ 1.67 │ TestAuth/auth-login-logout │ github.com/cli/cli/v2/acceptance │
│ PASS │ 1.12 │ TestAuth/auth-status │ github.com/cli/cli/v2/acceptance │
│ PASS │ 0.72 │ TestAuth/auth-setup-git │ github.com/cli/cli/v2/acceptance │
│ PASS │ 0.64 │ TestAuth/auth-token │ github.com/cli/cli/v2/acceptance │
│ PASS │ 0.00 │ TestAuth │ github.com/cli/cli/v2/acceptance │
└────────────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────────────┐
│ STATUS │ ELAPSED │ PACKAGE │ COVER │ PASS │ FAIL │ SKIP │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│ PASS │ 2.30s │ github.com/cli/cli/v2/acceptance │ 9.1% │ 5 │ 0 │ 0 │
└────────────────────────────────────────────────────────────────────────────────────┘
LGTM!
tmeijn
pushed a commit
to tmeijn/dotfiles
that referenced
this pull request
Nov 21, 2024
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [cli/cli](https://github.com/cli/cli) | minor | `v2.59.0` -> `v2.62.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>cli/cli (cli/cli)</summary> ### [`v2.62.0`](https://github.com/cli/cli/releases/tag/v2.62.0): GitHub CLI 2.62.0 [Compare Source](cli/cli@v2.61.0...v2.62.0) #### What's Changed - Update monotonic verification logic and testing by [@​malancas](https://github.com/malancas) in cli/cli#9856 - Check extension for latest version when executed by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9866 - Shorten extension release checking from 3s to 1s by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9914 - Mention GitHub CLI team on discussion issues by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9920 **Full Changelog**: cli/cli@v2.61.0...v2.62.0 #### Security - A security vulnerability has been identified in GitHub CLI that could allow remote code execution (RCE) when users connect to a malicious Codespace SSH server and use the `gh codespace ssh` or `gh codespace logs` commands. For more information, see GHSA-p2h2-3vg9-4p87 #### GitHub CLI notifies users about latest extension upgrades Similar to the notification of latest `gh` releases, the `v2.62.0` version of GitHub CLI will notify users about latest extension upgrades when the extension is used: ```shell $ gh ado2gh ... A new release of ado2gh is available: 1.7.0 → 1.8.0 To upgrade, run: gh extension upgrade ado2gh --force https://github.com/github/gh-ado2gh ``` ##### Why does this matter? This removes a common pain point of extension authors as they have had to reverse engineer and implement a similar mechanism within their extensions directly. With this quality of life improvement, there are 2 big benefits: 1. Extension authors will hopefully see increased adoption of newer releases while having lower bar to maintaining their extensions. 2. GitHub CLI users will have greater awareness of new features, bug fixes, and security fixes to the extensions used. ##### What do you need to do? Extension authors should review their extensions and consider removing any custom logic previously implemented to notify users of new releases. ### [`v2.61.0`](https://github.com/cli/cli/releases/tag/v2.61.0): GitHub CLI 2.61.0 [Compare Source](cli/cli@v2.60.1...v2.61.0) #### Ensure users understand consequences before making repository visibility changes In `v2.61.0`, `gh repo edit` command has been enhanced to inform users about [consequences of changing visibility](https://gh.io/setting-repository-visibility) and ensure users are intentional before making irreversible changes: 1. Interactive `gh repo edit` visibility change requires confirmation when changing from `public`, `private`, or `internal` 2. Non-interactive `gh repo edit --visibility` change requires new `--accept-visibility-change-consequences` flag to confirm 3. New content to inform users of consequences - Incorporate [GitHub Docs content](https://gh.io/setting-repository-visibility) into help usage and interactive `gh repo edit` experience - Expanded help usage to call out most concerning consequences - Display repository star and watcher counts to understand impact before confirming #### What's Changed - Add acceptance test for `project` command by [@​jtmcg](https://github.com/jtmcg) in cli/cli#9816 - Add comprehensive testscript for `gh ruleset` by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9815 - Add comprehensive testscript for gh ext commandset by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9810 - Require visibility confirmation in `gh repo edit` by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9845 - Clean up skipped online tests for `gh attestation verify` by [@​malancas](https://github.com/malancas) in cli/cli#9838 - `gh attestation verify` should only verify provenance attestations by default by [@​malancas](https://github.com/malancas) in cli/cli#9825 - Set `dnf5` commands as default by [@​its-miroma](https://github.com/its-miroma) in cli/cli#9844 - Fix verbiage for deleting workflow runs by [@​akx](https://github.com/akx) in cli/cli#9876 - Bump github.com/creack/pty from 1.1.23 to 1.1.24 by [@​dependabot](https://github.com/dependabot) in cli/cli#9862 - `gh attestation verify` policy enforcement refactor by [@​malancas](https://github.com/malancas) in cli/cli#9848 - Simplify Sigstore verification result handling in `gh attestation verify` by [@​malancas](https://github.com/malancas) in cli/cli#9877 - Print empty array for `gh cache list` when `--json` is provided by [@​williammartin](https://github.com/williammartin) in cli/cli#9883 - Bump actions/attest-build-provenance from 1.4.3 to 1.4.4 by [@​dependabot](https://github.com/dependabot) in cli/cli#9884 - Create the automatic key when specified with -i by [@​cmbrose](https://github.com/cmbrose) in cli/cli#9881 - fix: `gh pr create -w` ignore template flag by [@​nilvng](https://github.com/nilvng) in cli/cli#9863 #### New Contributors - [@​akx](https://github.com/akx) made their first contribution in cli/cli#9876 - [@​nilvng](https://github.com/nilvng) made their first contribution in cli/cli#9863 **Full Changelog**: cli/cli@v2.60.1...v2.61.0 ### [`v2.60.1`](https://github.com/cli/cli/releases/tag/v2.60.1): GitHub CLI 2.60.1 [Compare Source](cli/cli@v2.60.0...v2.60.1) This is a small patch release to fix installing `gh` via `go install` which was broken with v2.60.0. #### What's Changed - Update testscript to use hard fork by [@​williammartin](https://github.com/williammartin) in cli/cli#9821 **Full Changelog**: cli/cli@v2.60.0...v2.60.1 ### [`v2.60.0`](https://github.com/cli/cli/releases/tag/v2.60.0): GitHub CLI 2.60.0 [Compare Source](cli/cli@v2.59.0...v2.60.0) #### What's Changed - Add ArchivedAt field by [@​tsukasaI](https://github.com/tsukasaI) in cli/cli#9790 - Include startedAt, completedAt in run steps data by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9774 - Adjust environment help for host and tokens by [@​williammartin](https://github.com/williammartin) in cli/cli#9809 - Add handling of empty titles for Issues and MRs by [@​jtmcg](https://github.com/jtmcg) in cli/cli#9701 - `LiveSigstoreVerifier.Verify` should error if no attestations are present by [@​phillmv](https://github.com/phillmv) in cli/cli#9742 - `gh at verify` retries fetching attestations if it receives a 5xx by [@​phillmv](https://github.com/phillmv) in cli/cli#9797 - Prevent local extension installations with invalid names and conflicts with core commands and other extensions by [@​BagToad](https://github.com/BagToad) in cli/cli#9794 - Rewrite a sentence in CONTRIBUTING.md by [@​muzimuzhi](https://github.com/muzimuzhi) in cli/cli#9772 - Use new GitHub preview terms in `working-with-us.md` by [@​BagToad](https://github.com/BagToad) in cli/cli#9800 - Use new GitHub previews terminology in attestation commands' help docs by [@​BagToad](https://github.com/BagToad) in cli/cli#9799 - Clarify in README that `gh` is supported on GitHub Enterprise Cloud by [@​BagToad](https://github.com/BagToad) in cli/cli#9805 - build(deps): bump github.com/gabriel-vasile/mimetype from 1.4.5 to 1.4.6 by [@​dependabot](https://github.com/dependabot) in cli/cli#9752 ##### Acceptance Test Changes - Add acceptance tests for `workflow`, `run`, and `cache` commands by [@​BagToad](https://github.com/BagToad) in cli/cli#9766 - Add basic `api` acceptance tests by [@​BagToad](https://github.com/BagToad) in cli/cli#9770 - Add acceptance tests for `release` commands by [@​BagToad](https://github.com/BagToad) in cli/cli#9771 - Add acceptance tests for `org` and `ssh-key` commands by [@​BagToad](https://github.com/BagToad) in cli/cli#9812 - Add acceptance tests for `gh auth` commands by [@​jtmcg](https://github.com/jtmcg) in cli/cli#9787 - Add acceptance tests for `repo` commands by [@​jtmcg](https://github.com/jtmcg) in cli/cli#9783 - Add acceptance tests for `search` command by [@​BagToad](https://github.com/BagToad) in cli/cli#9786 - Add acceptance tests for `variable` commands by [@​andyfeller](https://github.com/andyfeller) in cli/cli#978 - Add testscripts for gpg-key and label commands by [@​williammartin](https://github.com/williammartin) in cli/cli#9811 - Use forked testscript for token redaction by [@​williammartin](https://github.com/williammartin) in cli/cli#9804 - Add acceptance tests for `secret` commands by [@​andyfeller](https://github.com/andyfeller) in cli/cli#9782 - Note token redaction in Acceptance test README by [@​williammartin](https://github.com/williammartin) in cli/cli#9813 #### New Contributors - [@​tsukasaI](https://github.com/tsukasaI) made their first contribution in cli/cli#9790 **Full Changelog**: cli/cli@v2.59.0...v2.60.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 MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Adds acceptance tests for some of the
gh authcommands. Some of them are very straight forward while others require a bit more setup to understand. I'll do my best to add that context here:gh auth statusandgh auth tokenWork as expected without any additional setup
gh auth setup-gitTo test this, I decided to look into the .gitconfig used for the test and examine the credential helpers. However, the format of the git command is
What's awkward about this is that the
<URL>depends on the host the user specified when running the tests, meaning I'd need to create a key likecredential.https://github.com.helperto access what I need while setting this up.There was no functionality for string formatting before, so I added the command
formattedStringToEnvwhich essentially wrapsfmt.Sprintf()and saves the string to an environment variable.This allowed me to dynamically create the config key in the test.
gh auth loginThe auth used in all the tests up until this point has used the
GH_TOKENenv var to override the need to log in. Since we want to test logging in with this command directly, I've had to delete theGH_TOKENenv var but still save the token value so I can auth using the--with-tokenflag available withgh auth login.Notably, the UX for the
gh auth login --with-tokencommand is pretty bad, but for now it works by specifying the token value tostdinjust before running thegh auth login --with-tokencommand. There is an issue to address this bad UX.gh auth switchThis test has been removed for two reasons:
gh auth switchis a local command (doesn't interact with the API)The work for
gh auth switchis now captured in this branch: jtmcg/testscripts-auth-switchThis is the trickiest command of them all, requiring us to log in using 2 sets of credentials. Thus, I've implemented some optional env vars that can be specified when a command is run to make this one work:GH_ACCEPTANCE_USER,GH_ACCEPTANCE_HOST_ALT,GH_ACCEPTANCE_USER_ALT, andGH_ACCEPTANCE_TOKEN_ALT, andGH_ACCEPTANCE_TOKEN_ALT. All of theALTvariables correspond to a second user account you are currently logged in to for testing.With these additional variables, the test logs in to both instances and then tests thatgh auth switchworks to go between the two. I think the test is rather straight forward if the setup is not.Testing
Directions to run the testscripts are in the README. Here's the command to run just the auth tests, for convenience: