Merge pull request #5186 from cli/credential-helper-fix
Fix authenticating git operations after `auth login --with-token`
This commit is contained in:
commit
c9f44ffda9
2 changed files with 27 additions and 5 deletions
|
|
@ -112,6 +112,9 @@ func helperRun(opts *CredentialOptions) error {
|
|||
gotUser = tokenUser
|
||||
} else {
|
||||
gotUser, _, _ = cfg.GetWithSource(lookupHost, "user")
|
||||
if gotUser == "" {
|
||||
gotUser = tokenUser
|
||||
}
|
||||
}
|
||||
|
||||
if gotUser == "" || gotToken == "" {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,6 @@ func (c tinyConfig) GetWithSource(host, key string) (string, string, error) {
|
|||
return c[fmt.Sprintf("%s:%s", host, key)], c["_source"], nil
|
||||
}
|
||||
|
||||
func (c tinyConfig) Get(host, key string) (val string, err error) {
|
||||
val, _, err = c.GetWithSource(host, key)
|
||||
return
|
||||
}
|
||||
|
||||
func Test_helperRun(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
@ -170,6 +165,30 @@ func Test_helperRun(t *testing.T) {
|
|||
wantStdout: "",
|
||||
wantStderr: "",
|
||||
},
|
||||
{
|
||||
name: "no username configured",
|
||||
opts: CredentialOptions{
|
||||
Operation: "get",
|
||||
Config: func() (config, error) {
|
||||
return tinyConfig{
|
||||
"_source": "/Users/monalisa/.config/gh/hosts.yml",
|
||||
"example.com:oauth_token": "OTOKEN",
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
input: heredoc.Doc(`
|
||||
protocol=https
|
||||
host=example.com
|
||||
`),
|
||||
wantErr: false,
|
||||
wantStdout: heredoc.Doc(`
|
||||
protocol=https
|
||||
host=example.com
|
||||
username=x-access-token
|
||||
password=OTOKEN
|
||||
`),
|
||||
wantStderr: "",
|
||||
},
|
||||
{
|
||||
name: "token from env",
|
||||
opts: CredentialOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue