diff options
author | 2022-06-24 10:43:21 +0200 | |
---|---|---|
committer | 2022-06-24 10:43:21 +0200 | |
commit | 7eacbd064b15d2a9ed2f6006c943e0ee65a31317 (patch) | |
tree | f0416303cf509c0c2891e1fbec120c766d4ea024 /internal/api/client/instance | |
parent | [feature] Implement `/api/v1/instance/peers` endpoint (#660) (diff) | |
download | gotosocial-7eacbd064b15d2a9ed2f6006c943e0ee65a31317.tar.xz |
[bugfix] allow setting empty email via instance patch (#665)
Diffstat (limited to 'internal/api/client/instance')
-rw-r--r-- | internal/api/client/instance/instancepatch_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/api/client/instance/instancepatch_test.go b/internal/api/client/instance/instancepatch_test.go index 683fec5a6..90464d009 100644 --- a/internal/api/client/instance/instancepatch_test.go +++ b/internal/api/client/instance/instancepatch_test.go @@ -187,6 +187,65 @@ func (suite *InstancePatchTestSuite) TestInstancePatch5() { suite.Equal(`{"error":"Forbidden: user is not an admin so cannot update instance settings"}`, string(b)) } +func (suite *InstancePatchTestSuite) TestInstancePatch6() { + requestBody, w, err := testrig.CreateMultipartFormData( + "", "", + map[string]string{ + "contact_email": "", + }) + if err != nil { + panic(err) + } + bodyBytes := requestBody.Bytes() + + // set up the request + recorder := httptest.NewRecorder() + ctx := suite.newContext(recorder, http.MethodPatch, bodyBytes, instance.InstanceInformationPath, w.FormDataContentType()) + + // call the handler + suite.instanceModule.InstanceUpdatePATCHHandler(ctx) + + // we should have OK because our request was valid + suite.Equal(http.StatusOK, recorder.Code) + + result := recorder.Result() + defer result.Body.Close() + + b, err := io.ReadAll(result.Body) + suite.NoError(err) + + suite.Equal(`{"uri":"http://localhost:8080","title":"localhost:8080","description":"","short_description":"","email":"","version":"","registrations":true,"approval_required":true,"invites_enabled":false,"urls":{"streaming_api":"wss://localhost:8080"},"stats":{"domain_count":2,"status_count":16,"user_count":4},"thumbnail":"","max_toot_chars":5000}`, string(b)) +} + +func (suite *InstancePatchTestSuite) TestInstancePatch7() { + requestBody, w, err := testrig.CreateMultipartFormData( + "", "", + map[string]string{ + "contact_email": "not.an.email.address", + }) + if err != nil { + panic(err) + } + bodyBytes := requestBody.Bytes() + + // set up the request + recorder := httptest.NewRecorder() + ctx := suite.newContext(recorder, http.MethodPatch, bodyBytes, instance.InstanceInformationPath, w.FormDataContentType()) + + // call the handler + suite.instanceModule.InstanceUpdatePATCHHandler(ctx) + + suite.Equal(http.StatusBadRequest, recorder.Code) + + result := recorder.Result() + defer result.Body.Close() + + b, err := io.ReadAll(result.Body) + suite.NoError(err) + + suite.Equal(`{"error":"Bad Request: mail: missing '@' or angle-addr"}`, string(b)) +} + func TestInstancePatchTestSuite(t *testing.T) { suite.Run(t, &InstancePatchTestSuite{}) } |