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

Method TestVerifyCaptchaInvalid

internal/api/middleware_test.go:137–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135}
136
137func (ts *MiddlewareTestSuite) TestVerifyCaptchaInvalid() {
138 cases := []struct {
139 desc string
140 errorCodes []string
141 expectedCode int
142 expectedMsg string
143 }{
144 {
145 "Captcha validation failed",
146 []string{"not-using-dummy-secret"},
147 http.StatusBadRequest,
148 "captcha protection: request disallowed (not-using-dummy-secret)",
149 },
150 {
151 "Captcha validation failed",
152 []string{"invalid-input-secret"},
153 http.StatusBadRequest,
154 "captcha protection: request disallowed (invalid-input-secret)",
155 },
156 }
157 for _, c := range cases {
158 ts.Run(c.desc, func() {
159 ts.Config.Security.Captcha.Enabled = true
160 ts.Config.Security.Captcha.Provider = "hcaptcha"
161 ts.Config.Security.Captcha.Secret = "test-secret"
162
163 ts.CaptchaVerifier.Result = &security.VerificationResponse{
164 Success: false,
165 ErrorCodes: c.errorCodes,
166 }
167 ts.CaptchaVerifier.Err = nil
168
169 var buffer bytes.Buffer
170 require.NoError(ts.T(), json.NewEncoder(&buffer).Encode(map[string]interface{}{
171 "email": "test@example.com",
172 "password": "secret",
173 "gotrue_meta_security": map[string]interface{}{
174 "captcha_token": captchaResponse,
175 },
176 }))
177 req := httptest.NewRequest(http.MethodPost, "http://localhost", &buffer)
178 req.Header.Set("Content-Type", "application/json")
179
180 req = req.WithContext(context.Background())
181
182 w := httptest.NewRecorder()
183
184 _, err := ts.API.verifyCaptcha(w, req)
185 require.Equal(ts.T(), c.expectedCode, err.(*HTTPError).HTTPStatus)
186 require.Equal(ts.T(), c.expectedMsg, err.(*HTTPError).Message)
187 })
188 }
189}
190
191func (ts *MiddlewareTestSuite) TestIsValidExternalHost() {
192 cases := []struct {

Callers

nothing calls this directly

Calls 6

EncodeMethod · 0.80
SetMethod · 0.80
WithContextMethod · 0.80
verifyCaptchaMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected