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

Function TestRevokeToken

internal/authflow/revoke_test.go:29–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestRevokeToken(t *testing.T) {
30 tests := []struct {
31 name string
32 host string
33 apiHost string
34 wantURL string
35 status int
36 transportErr error
37 wantErr string
38 }{
39 {
40 name: "GitHub.com", host: "github.com", status: 204,
41 wantURL: "https://api.github.com/applications/" + oauthClientID + "/token",
42 },
43 {
44 name: "GHES", host: "enterprise.example.com", status: 204,
45 wantURL: "https://enterprise.example.com/api/v3/applications/" + oauthClientID + "/token",
46 },
47 {
48 name: "configured API gateway", host: "github.com", apiHost: "gateway.example.com", status: 204,
49 wantURL: "https://gateway.example.com/applications/" + oauthClientID + "/token",
50 },
51 {
52 name: "not found is not success", host: "github.com", status: 404,
53 wantErr: "HTTP 404 (Not Found)",
54 },
55 {
56 name: "server error omits response message", host: "github.com", status: 500,
57 wantErr: "HTTP 500 (Internal Server Error)",
58 },
59 {
60 name: "unexpected successful status", host: "github.com", status: 200,
61 wantErr: "unexpected HTTP 200 for DELETE https://api.github.com/applications/" + oauthClientID + "/token",
62 },
63 {
64 name: "does not follow redirects", host: "github.com", status: 302,
65 wantErr: "HTTP 302 (Found)",
66 },
67 {
68 name: "request timeout", host: "github.com", transportErr: context.DeadlineExceeded,
69 wantErr: "request timed out",
70 },
71 {
72 name: "request cancellation", host: "github.com", transportErr: context.Canceled,
73 wantErr: "context canceled",
74 },
75 {
76 name: "transport error redacts credentials", host: "github.com",
77 transportErr: errors.New("connection failed with gho_test_secret and " + oauthClientSecret),
78 wantErr: "Delete \"https://api.github.com/applications/" + oauthClientID + "/token\": connection failed with [REDACTED] and [REDACTED]",
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 cfg, _ := config.NewIsolatedTestConfig(t, "")
84 if tt.apiHost != "" {
85 cfg.Set(tt.host, "api_host", tt.apiHost)
86 }

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
RegisterMethod · 0.95
NewIsolatedTestConfigFunction · 0.92
RESTFunction · 0.92
RevokeTokenFunction · 0.85
EqualMethod · 0.80
EmptyMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65
StringMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected