MCPcopy Create free account
hub / github.com/supabase/auth / TestDisabledFeatureReturnsJSON

Function TestDisabledFeatureReturnsJSON

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

Source from the content-addressed store, hash-verified

85}
86
87func TestDisabledFeatureReturnsJSON(t *testing.T) {
88 cases := []struct {
89 name string
90 method string
91 path string
92 errorCode string
93 setup func(*conf.GlobalConfiguration)
94 }{
95 {
96 name: "OAuthServer disabled returns JSON on /oauth/token",
97 method: http.MethodPost,
98 path: "http://localhost/oauth/token",
99 errorCode: apierrors.ErrorCodeFeatureDisabled,
100 setup: func(c *conf.GlobalConfiguration) {
101 c.OAuthServer.Enabled = false
102 },
103 },
104 {
105 name: "OAuthServer disabled returns JSON on /oauth/clients/register",
106 method: http.MethodPost,
107 path: "http://localhost/oauth/clients/register",
108 errorCode: apierrors.ErrorCodeFeatureDisabled,
109 setup: func(c *conf.GlobalConfiguration) {
110 c.OAuthServer.Enabled = false
111 },
112 },
113 {
114 name: "OAuthServer disabled returns JSON on /.well-known/oauth-authorization-server",
115 method: http.MethodGet,
116 path: "http://localhost/.well-known/oauth-authorization-server",
117 errorCode: apierrors.ErrorCodeFeatureDisabled,
118 setup: func(c *conf.GlobalConfiguration) {
119 c.OAuthServer.Enabled = false
120 },
121 },
122 }
123
124 for _, tc := range cases {
125 t.Run(tc.name, func(t *testing.T) {
126 api, _, err := setupAPIForTestWithCallback(func(config *conf.GlobalConfiguration, conn *storage.Connection) {
127 if config != nil {
128 tc.setup(config)
129 }
130 })
131 require.NoError(t, err)
132
133 req := httptest.NewRequest(tc.method, tc.path, nil)
134 w := httptest.NewRecorder()
135 api.handler.ServeHTTP(w, req)
136
137 require.Equal(t, http.StatusNotFound, w.Code)
138 require.Contains(t, w.Header().Get("Content-Type"), "application/json")
139
140 var body map[string]interface{}
141 require.NoError(t, json.NewDecoder(w.Body).Decode(&body))
142 require.Equal(t, tc.errorCode, body["error_code"])
143 })
144 }

Callers

nothing calls this directly

Calls 9

setupMethod · 0.80
EqualMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
ServeHTTPMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected