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

Function TestLogoutWithCredential

internal/config/refreshable_test.go:391–550  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

389}
390
391func TestLogoutWithCredential(t *testing.T) {
392 callbackErr := errors.New("revocation failed")
393 lockErr := errors.New("locking unavailable")
394 reloadErr := errors.New("cannot reload")
395 tests := []struct {
396 name string
397 secure bool
398 refreshable bool
399 callbackErr error
400 lockErr error
401 reloadErr error
402 removeUser bool
403 removeToken bool
404 wantErr string
405 wantCallback bool
406 replace bool
407 invalidPair bool
408 }{
409 {name: "fresh plaintext credential", wantCallback: true},
410 {name: "fresh keyring credential", secure: true, wantCallback: true},
411 {name: "fresh plaintext refreshable credential", refreshable: true, wantCallback: true},
412 {name: "fresh keyring refreshable credential", secure: true, refreshable: true, wantCallback: true},
413 {name: "failed revocation retains plaintext pair", refreshable: true, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
414 {name: "failed revocation retains keyring pair", secure: true, refreshable: true, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
415 {name: "failed revocation retains replacement plaintext pair", refreshable: true, replace: true, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
416 {name: "failed revocation retains replacement keyring pair", secure: true, refreshable: true, replace: true, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
417 {name: "replacement proceeds without the advisory lock", refreshable: true, replace: true, lockErr: lockErr, wantCallback: true},
418 {name: "failed revocation retains renewed keyring pair without advisory locking", secure: true, refreshable: true, replace: true, lockErr: lockErr, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
419 {name: "read-only state directory does not prevent saving the replacement", refreshable: true, replace: true, lockErr: &fs.PathError{Op: "mkdir", Path: "state", Err: syscall.EROFS}, callbackErr: callbackErr, wantErr: "revocation failed", wantCallback: true},
420 {name: "replacement requires a refreshable original credential", replace: true, wantErr: "cannot replace a non-refreshable logout credential", wantCallback: true},
421 {name: "incomplete replacement preserves the original pair", refreshable: true, replace: true, invalidPair: true, wantErr: "refresh token is empty", wantCallback: true},
422 {name: "callback can reject an unavailable lock", lockErr: lockErr, callbackErr: lockErr, wantErr: "locking unavailable", wantCallback: true},
423 {name: "callback can allow local cleanup without the advisory lock", lockErr: lockErr, wantCallback: true},
424 {name: "failed reload retains credentials", reloadErr: reloadErr, wantErr: "could not reload configuration: cannot reload"},
425 {name: "removed selection does not remove another account", removeUser: true, wantErr: "not logged in to github.com account test-user"},
426 {name: "lookup failure does not use active token", removeToken: true, wantErr: "no token found for 'test-user'"},
427 }
428 for _, tt := range tests {
429 t.Run(tt.name, func(t *testing.T) {
430 authCfg := newTestAuthConfig(t)
431 _, err := authCfg.Login("github.com", "other-user", "other-token", "https", false)
432 require.NoError(t, err)
433 if tt.refreshable {
434 _, err = authCfg.LoginRefreshable("github.com", "test-user",
435 gh.Credential{Token: "gho_old", RefreshToken: "ghr_old"}, "https", tt.secure)
436 } else {
437 _, err = authCfg.Login("github.com", "test-user", "gho_old", "https", tt.secure)
438 }
439 require.NoError(t, err)
440
441 locked, unlocked := false, false
442 authCfg.acquireRefreshLock = func(context.Context, string) (func(), error) {
443 if tt.lockErr != nil {
444 return nil, tt.lockErr
445 }
446 locked = true
447 return func() { locked, unlocked = false, true }, nil
448 }

Callers

nothing calls this directly

Calls 15

SetFunction · 0.92
newTestAuthConfigFunction · 0.85
setRefreshableKeyringFunction · 0.85
saveFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
keyringServiceNameFunction · 0.70
RunMethod · 0.65
LoginMethod · 0.65
LoginRefreshableMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected