1package admin
2
3import (
4 "encoding/json"
5 "net/http"
6 "net/http/httptest"
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 "github.com/stretchr/testify/require"
11
12 "github.com/bnema/gordon/internal/adapters/dto"
13 inmocks "github.com/bnema/gordon/internal/boundaries/in/mocks"
14)
15
16func retiredTestHandler(t *testing.T) *Handler {
17 t.Helper()
18 return NewHandler(HandlerDeps{
19 ConfigSvc: inmocks.NewMockConfigService(t),
20 AuthSvc: inmocks.NewMockAuthService(t),
21 ContainerSvc: inmocks.NewMockContainerService(t),
22 HealthSvc: inmocks.NewMockHealthService(t),
23 Log: testLogger(),
24 ReloadTrigger: noopReloadTrigger{},
25 })
26}
27
28func TestHandler_RetiredMutations_Return410(t *testing.T) {
29 handler := retiredTestHandler(t)
30 targets := []struct {
31 method string
32 path string
33 }{
34 {http.MethodPost, "/admin/deploy/example.com"},
35 {http.MethodPost, "/admin/restart/example.com"},
36 {http.MethodPost, "/admin/deploy-intent"},
37 {http.MethodPost, "/admin/routes"},
38 {http.MethodGet, "/admin/routes"},
39 {http.MethodDelete, "/admin/routes/example.com"},
40 {http.MethodPost, "/admin/attachments"},
41 {http.MethodGet, "/admin/attachments/by-image/x"},
42 {http.MethodPost, "/admin/attachments/prune"},
43 {http.MethodGet, "/admin/attachments/orphans"},
44 {http.MethodPost, "/admin/bootstrap"},
45 {http.MethodPost, "/admin/preview/blog"},
46 {http.MethodGet, "/admin/previews"},
47 {http.MethodPost, "/admin/autoroute/allowed-domains"},
48 {http.MethodGet, "/admin/secrets/example.com"},
49 {http.MethodPost, "/admin/secrets/example.com"},
50 {http.MethodDelete, "/admin/secrets/example.com/KEY"},
51 }
52 for _, target := range targets {
53 req := httptest.NewRequest(target.method, target.path, nil)
54 req = req.WithContext(ctxWithScopes("admin:*:*"))
55 rec := httptest.NewRecorder()
56 handler.ServeHTTP(rec, req)
57 require.Equal(t, http.StatusGone, rec.Code, "%s %s", target.method, target.path)
58 var envelope dto.AppError
59 require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &envelope), target.path)
60 assert.Equal(t, "endpoint-retired", envelope.Error, target.path)
61 }
62}