MCPcopy Create free account
hub / github.com/docker/cli / TestRevoke

Function TestRevoke

internal/oauth/api/api_test.go:244–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

242}
243
244func TestRevoke(t *testing.T) {
245 t.Parallel()
246
247 t.Run("success", func(t *testing.T) {
248 t.Parallel()
249 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
250 assert.Equal(t, "POST", r.Method)
251 assert.Equal(t, "/oauth/revoke", r.URL.Path)
252 assert.Equal(t, r.FormValue("client_id"), "aClientID")
253 assert.Equal(t, r.FormValue("token"), "v1.a-refresh-token")
254
255 w.WriteHeader(http.StatusOK)
256 }))
257 defer ts.Close()
258 api := API{
259 TenantURL: ts.URL,
260 ClientID: "aClientID",
261 Scopes: []string{"bork", "meow"},
262 }
263
264 err := api.RevokeToken(context.Background(), "v1.a-refresh-token")
265 assert.NilError(t, err)
266 })
267
268 t.Run("unexpected response", func(t *testing.T) {
269 t.Parallel()
270 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
271 assert.Equal(t, "POST", r.Method)
272 assert.Equal(t, "/oauth/revoke", r.URL.Path)
273 assert.Equal(t, r.FormValue("client_id"), "aClientID")
274 assert.Equal(t, r.FormValue("token"), "v1.a-refresh-token")
275
276 w.WriteHeader(http.StatusNotFound)
277 }))
278 defer ts.Close()
279 api := API{
280 TenantURL: ts.URL,
281 ClientID: "aClientID",
282 Scopes: []string{"bork", "meow"},
283 }
284
285 err := api.RevokeToken(context.Background(), "v1.a-refresh-token")
286 assert.ErrorContains(t, err, "unexpected response from tenant: 404 Not Found")
287 })
288
289 t.Run("error w/ description", func(t *testing.T) {
290 t.Parallel()
291 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
292 jsonState, err := json.Marshal(TokenResponse{
293 ErrorDescription: "invalid client id",
294 })
295 assert.NilError(t, err)
296
297 w.WriteHeader(http.StatusBadRequest)
298 _, _ = w.Write(jsonState)
299 }))
300 defer ts.Close()
301 api := API{

Callers

nothing calls this directly

Calls 3

RevokeTokenMethod · 0.95
CloseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…