(t *testing.T)
| 242 | } |
| 243 | |
| 244 | func 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{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…