MCPcopy Create free account
hub / github.com/cli/cli / preMigrationLogin

Function preMigrationLogin

internal/config/auth_config_test.go:978–998  ·  view source on GitHub ↗

Copied and pasted directly from the trunk branch before doing any work on login, plus the addition of AuthConfig as the first arg since it is a method receiver in the real implementation.

(c *AuthConfig, hostname, username, token, gitProtocol string, secureStorage bool)

Source from the content-addressed store, hash-verified

976// login, plus the addition of AuthConfig as the first arg since it is a method
977// receiver in the real implementation.
978func preMigrationLogin(c *AuthConfig, hostname, username, token, gitProtocol string, secureStorage bool) (bool, error) {
979 var setErr error
980 if secureStorage {
981 if setErr = keyring.Set(keyringServiceName(hostname), "", token); setErr == nil {
982 // Clean up the previous oauth_token from the config file.
983 _ = c.cfg.Remove([]string{hostsKey, hostname, oauthTokenKey})
984 }
985 }
986 insecureStorageUsed := false
987 if !secureStorage || setErr != nil {
988 c.cfg.Set([]string{hostsKey, hostname, oauthTokenKey}, token)
989 insecureStorageUsed = true
990 }
991
992 c.cfg.Set([]string{hostsKey, hostname, userKey}, username)
993
994 if gitProtocol != "" {
995 c.cfg.Set([]string{hostsKey, hostname, gitProtocolKey}, gitProtocol)
996 }
997 return insecureStorageUsed, ghConfig.Write(c.cfg)
998}
999
1000func TestActiveTokenType(t *testing.T) {
1001 tests := []struct {

Calls 5

SetFunction · 0.92
keyringServiceNameFunction · 0.70
RemoveMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected