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

Function TestTokenRunSecureStorage

pkg/cmd/auth/token/token_test.go:254–486  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

252}
253
254func TestTokenRunSecureStorage(t *testing.T) {
255 tests := []struct {
256 name string
257 opts TokenOptions
258 env map[string]string
259 cfgStubs func(*testing.T, gh.Config)
260 wantStdout string
261 wantErr bool
262 wantErrMsg string
263 wantStderrContains string
264 wantStderrOmits string
265 }{
266 // State 3: --secure-storage without --no-refresh (compatibility mode for go-gh).
267 {
268 name: "state 3: plain token in keyring is returned",
269 opts: TokenOptions{},
270 cfgStubs: func(t *testing.T, cfg gh.Config) {
271 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true)
272 },
273 wantStdout: "gho_ABCDEFG\n",
274 wantStderrOmits: "This token will expire",
275 },
276 {
277 name: "state 3: plain token in keyring by hostname is returned",
278 opts: TokenOptions{
279 Hostname: "mycompany.com",
280 },
281 cfgStubs: func(t *testing.T, cfg gh.Config) {
282 login(t, cfg, "mycompany.com", "test-user", "gho_1234567", "https", true)
283 },
284 wantStdout: "gho_1234567\n",
285 },
286 {
287 name: "state 3: plain token for user in keyring is returned",
288 opts: TokenOptions{
289 Hostname: "github.com",
290 Username: "test-user",
291 },
292 cfgStubs: func(t *testing.T, cfg gh.Config) {
293 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", true)
294 login(t, cfg, "github.com", "test-user-2", "gho_1234567", "https", true)
295 },
296 wantStdout: "gho_ABCDEFG\n",
297 },
298 {
299 name: "state 3: plain token in config is suppressed",
300 opts: TokenOptions{},
301 cfgStubs: func(t *testing.T, cfg gh.Config) {
302 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false)
303 },
304 wantErr: true,
305 wantErrMsg: "no oauth token found for github.com",
306 },
307 {
308 name: "state 3: token from the environment is suppressed",
309 opts: TokenOptions{},
310 env: map[string]string{"GH_TOKEN": "gho_ENVTOKEN"},
311 wantErr: true,

Callers

nothing calls this directly

Calls 11

TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
tokenRunFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
loginFunction · 0.70
loginRefreshableFunction · 0.70
RunMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected