diff --git a/backend/app/rest/api/rest_private_test.go b/backend/app/rest/api/rest_private_test.go index d0a052f0..029dab01 100644 --- a/backend/app/rest/api/rest_private_test.go +++ b/backend/app/rest/api/rest_private_test.go @@ -425,7 +425,8 @@ func TestRest_Vote(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 1, cr.Score) assert.Equal(t, 1, cr.Vote) - assert.Equal(t, map[string]bool(nil), cr.Votes) + assert.Equal(t, map[string]bool(nil), cr.Votes, "hidden") + assert.Equal(t, map[string]store.VotedIPInfo(nil), cr.VotedIPs, "hidden") assert.Equal(t, 200, vote(-1), "opposite vote allowed") body, code = getWithDevAuth(t, fmt.Sprintf("%s/api/v1/id/%s?site=remark42&url=https://radio-t.com/blah", ts.URL, id1)) @@ -461,7 +462,8 @@ func TestRest_Vote(t *testing.T) { assert.NoError(t, err) assert.Equal(t, -1, cr.Score) assert.Equal(t, 0, cr.Vote, "no vote info for not authed user") - assert.Equal(t, map[string]bool(nil), cr.Votes) + assert.Equal(t, map[string]bool(nil), cr.Votes, "hidden") + assert.Equal(t, map[string]store.VotedIPInfo(nil), cr.VotedIPs, "hidden") req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/id/%s?site=remark42&url=https://radio-t.com/blah", ts.URL, id1), nil) @@ -474,7 +476,8 @@ func TestRest_Vote(t *testing.T) { assert.NoError(t, err) assert.Equal(t, -1, cr.Score) assert.Equal(t, 0, cr.Vote, "no vote info for different user") - assert.Equal(t, map[string]bool(nil), cr.Votes) + assert.Equal(t, map[string]bool(nil), cr.Votes, "hidden") + assert.Equal(t, map[string]store.VotedIPInfo(nil), cr.VotedIPs, "hidden") } func TestRest_AnonVote(t *testing.T) { diff --git a/backend/app/store/comment.go b/backend/app/store/comment.go index b2c902dd..ba4e008f 100644 --- a/backend/app/store/comment.go +++ b/backend/app/store/comment.go @@ -83,6 +83,7 @@ func (c *Comment) PrepareUntrusted() { c.ID = "" // don't allow user to define ID, force auto-gen c.Timestamp = time.Time{} // reset time, force auto-gen c.Votes = make(map[string]bool) + c.VotedIPs = make(map[string]VotedIPInfo) c.Score = 0 c.Edit = nil c.Pin = false @@ -95,6 +96,7 @@ func (c *Comment) SetDeleted(mode DeleteMode) { c.Orig = "" c.Score = 0 c.Votes = map[string]bool{} + c.VotedIPs = make(map[string]VotedIPInfo) c.Edit = nil c.Deleted = true c.Pin = false diff --git a/backend/app/store/service/service.go b/backend/app/store/service/service.go index a16c5201..2c3ed8b5 100644 --- a/backend/app/store/service/service.go +++ b/backend/app/store/service/service.go @@ -940,7 +940,8 @@ func (s *DataStore) prepVotes(c store.Comment, user store.User) store.Comment { } } - c.Votes = nil // hide voters list + c.Votes = nil // hide voters list + c.VotedIPs = nil // hide voted ips (hashes) return c } diff --git a/backend/app/store/service/service_test.go b/backend/app/store/service/service_test.go index 894dc546..982ea017 100644 --- a/backend/app/store/service/service_test.go +++ b/backend/app/store/service/service_test.go @@ -387,7 +387,7 @@ func TestService_VoteAggressive(t *testing.T) { // random +1/-1 result should be [0..2] rand.Seed(time.Now().UnixNano()) - for i := 0; i < 1000; i++ { + for i := 0; i < 100; i++ { wg.Add(1) go func() { defer wg.Done()