MCPcopy
hub / github.com/cli/cli / TestMigrationSecureStorage

Function TestMigrationSecureStorage

internal/config/migration/multi_account_test.go:45–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestMigrationSecureStorage(t *testing.T) {
46 cfg := config.ReadFromString(`
47hosts:
48 github.com:
49 user: userOne
50 git_protocol: ssh
51 enterprise.com:
52 user: userTwo
53 git_protocol: https
54`)
55
56 userOneToken := "userOne-token"
57 userTwoToken := "userTwo-token"
58
59 keyring.MockInit()
60 require.NoError(t, keyring.Set("gh:github.com", "", userOneToken))
61 require.NoError(t, keyring.Set("gh:enterprise.com", "", userTwoToken))
62
63 var m migration.MultiAccount
64 require.NoError(t, m.Do(cfg))
65
66 // Verify token gets stored with host and username
67 gotUserOneToken, err := keyring.Get("gh:github.com", "userOne")
68 require.NoError(t, err)
69 require.Equal(t, userOneToken, gotUserOneToken)
70
71 // Verify token still exists with only host
72 gotUserOneToken, err = keyring.Get("gh:github.com", "")
73 require.NoError(t, err)
74 require.Equal(t, userOneToken, gotUserOneToken)
75
76 // Verify token gets stored with host and username
77 gotUserTwoToken, err := keyring.Get("gh:enterprise.com", "userTwo")
78 require.NoError(t, err)
79 require.Equal(t, userTwoToken, gotUserTwoToken)
80
81 // Verify token still exists with only host
82 gotUserTwoToken, err = keyring.Get("gh:enterprise.com", "")
83 require.NoError(t, err)
84 require.Equal(t, userTwoToken, gotUserTwoToken)
85
86 // First we'll check that the users have been created with no config underneath them
87 requireKeyExists(t, cfg, []string{"hosts", "github.com", "users", "userOne"})
88 requireKeyExists(t, cfg, []string{"hosts", "enterprise.com", "users", "userTwo"})
89
90 // Then we'll check that the old data has been left alone
91 requireKeyWithValue(t, cfg, []string{"hosts", "github.com", "user"}, "userOne")
92 requireKeyWithValue(t, cfg, []string{"hosts", "github.com", "git_protocol"}, "ssh")
93
94 requireKeyWithValue(t, cfg, []string{"hosts", "enterprise.com", "user"}, "userTwo")
95 requireKeyWithValue(t, cfg, []string{"hosts", "enterprise.com", "git_protocol"}, "https")
96}
97
98func TestPreVersionIsEmptyString(t *testing.T) {
99 var m migration.MultiAccount

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
MockInitFunction · 0.92
SetFunction · 0.92
GetFunction · 0.92
requireKeyExistsFunction · 0.85
EqualMethod · 0.80
requireKeyWithValueFunction · 0.70

Tested by

no test coverage detected