From a409e9e33de9276cef13bef8bd21b06954f14382 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 28 May 2018 18:44:51 -0500 Subject: [PATCH] test failed update attempts --- app/rest/api/rest_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/rest/api/rest_test.go b/app/rest/api/rest_test.go index 499e0425..224f1c16 100644 --- a/app/rest/api/rest_test.go +++ b/app/rest/api/rest_test.go @@ -350,6 +350,38 @@ func TestRest_Update(t *testing.T) { assert.Equal(t, c2, c3, "same as response from update") } +func TestRest_UpdateNotOwner(t *testing.T) { + srv, ts := prep(t) + assert.NotNil(t, srv) + defer cleanup(ts) + + c1 := store.Comment{Text: "test test #1", ParentID: "p1", + Locator: store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah1"}, User: store.User{ID: "xyz"}} + id1, err := srv.DataService.Create(c1) + assert.Nil(t, err) + + client := http.Client{} + req, err := http.NewRequest(http.MethodPut, ts.URL+"/api/v1/comment/"+id1+ + "?site=radio-t&url=https://radio-t.com/blah1", strings.NewReader(`{"text":"updated text", "summary":"my edit"}`)) + assert.Nil(t, err) + req = withBasicAuth(req, "dev", "password") + b, err := client.Do(req) + assert.Nil(t, err) + body, err := ioutil.ReadAll(b.Body) + assert.Nil(t, err) + assert.Equal(t, 403, b.StatusCode, string(body), "update from non-owner") + assert.Equal(t, `{"details":"can not edit comments for other users","error":"rejected"}`+"\n", string(body)) + + client = http.Client{} + req, err = http.NewRequest(http.MethodPut, ts.URL+"/api/v1/comment/"+id1+ + "?site=radio-t&url=https://radio-t.com/blah1", strings.NewReader(`ERRR "text":"updated text", "summary":"my"}`)) + assert.Nil(t, err) + req = withBasicAuth(req, "dev", "password") + b, err = client.Do(req) + assert.Nil(t, err) + assert.Equal(t, 400, b.StatusCode, string(body), "update is not json") +} + func TestRest_Last(t *testing.T) { srv, ts := prep(t) assert.NotNil(t, srv)