Set host level git_protocol on login
This commit is contained in:
parent
eb771aecc9
commit
38b73e3f85
3 changed files with 30 additions and 7 deletions
|
|
@ -298,12 +298,19 @@ func TestLoginSetsGitProtocolForProvidedHost(t *testing.T) {
|
|||
_, err := authCfg.Login("github.com", "test-user", "test-token", "ssh", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// When we get the git protocol
|
||||
protocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", gitProtocolKey})
|
||||
// When we get the host git protocol
|
||||
hostProtocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", gitProtocolKey})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then it returns the git protocol we provided on login
|
||||
require.Equal(t, "ssh", protocol)
|
||||
require.Equal(t, "ssh", hostProtocol)
|
||||
|
||||
// When we get the users git protocol
|
||||
userProtocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", gitProtocolKey})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then it returns the git protocol we provided on login
|
||||
require.Equal(t, "ssh", userProtocol)
|
||||
}
|
||||
|
||||
func TestLoginAddsHostIfNotAlreadyAdded(t *testing.T) {
|
||||
|
|
@ -535,12 +542,19 @@ func TestLoginPostMigrationSetsGitProtocol(t *testing.T) {
|
|||
_, err := authCfg.Login("github.com", "test-user", "test-token", "ssh", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// When we get the git protocol
|
||||
gitProtocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", gitProtocolKey})
|
||||
// When we get the host git protocol
|
||||
hostProtocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", gitProtocolKey})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then it returns the git protocol we provided on login
|
||||
require.Equal(t, "ssh", gitProtocol)
|
||||
require.Equal(t, "ssh", hostProtocol)
|
||||
|
||||
// When we get the user git protocol
|
||||
userProtocol, err := authCfg.cfg.Get([]string{hostsKey, "github.com", usersKey, "test-user", gitProtocolKey})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then it returns the git protocol we provided on login
|
||||
require.Equal(t, "ssh", userProtocol)
|
||||
}
|
||||
|
||||
func TestLoginPostMigrationSetsUser(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -322,6 +322,10 @@ func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secure
|
|||
c.cfg.Set([]string{hostsKey, hostname, userKey}, username)
|
||||
|
||||
if gitProtocol != "" {
|
||||
// Set the git protocol
|
||||
c.cfg.Set([]string{hostsKey, hostname, gitProtocolKey}, gitProtocol)
|
||||
// And set the git protocol under the user to support later auth switch
|
||||
// and logout switch without another migration.
|
||||
c.cfg.Set([]string{hostsKey, hostname, usersKey, username, gitProtocolKey}, gitProtocol)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ func Test_loginRun_nontty(t *testing.T) {
|
|||
httpmock.GraphQL(`query UserCurrent\b`),
|
||||
httpmock.StringResponse(`{"data":{"viewer":{"login":"monalisa"}}}`))
|
||||
},
|
||||
wantHosts: "github.com:\n oauth_token: abc123\n users:\n monalisa:\n oauth_token: abc123\n git_protocol: https\n user: monalisa\n",
|
||||
wantHosts: "github.com:\n oauth_token: abc123\n users:\n monalisa:\n oauth_token: abc123\n git_protocol: https\n user: monalisa\n git_protocol: https\n",
|
||||
},
|
||||
{
|
||||
name: "with token and non-default host",
|
||||
|
|
@ -507,6 +507,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
|||
oauth_token: def456
|
||||
git_protocol: https
|
||||
user: jillv
|
||||
git_protocol: https
|
||||
`),
|
||||
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||
pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) {
|
||||
|
|
@ -541,6 +542,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
|||
oauth_token: def456
|
||||
git_protocol: https
|
||||
user: jillv
|
||||
git_protocol: https
|
||||
`),
|
||||
opts: &LoginOptions{
|
||||
Interactive: true,
|
||||
|
|
@ -584,6 +586,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
|||
oauth_token: def456
|
||||
git_protocol: https
|
||||
user: jillv
|
||||
git_protocol: https
|
||||
`),
|
||||
opts: &LoginOptions{
|
||||
Interactive: true,
|
||||
|
|
@ -618,6 +621,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
|||
oauth_token: def456
|
||||
git_protocol: ssh
|
||||
user: jillv
|
||||
git_protocol: ssh
|
||||
`),
|
||||
opts: &LoginOptions{
|
||||
Interactive: true,
|
||||
|
|
@ -662,6 +666,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
|||
wantHosts: heredoc.Doc(`
|
||||
github.com:
|
||||
user: jillv
|
||||
git_protocol: https
|
||||
users:
|
||||
jillv:
|
||||
git_protocol: https
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue