diff options
author | 2021-11-22 14:40:23 +0100 | |
---|---|---|
committer | 2021-11-22 14:40:23 +0100 | |
commit | 79ccd8fd8acd09f78385cda799e9049cbc59de0f (patch) | |
tree | 6f2645b00f65fe4c4f807d1ccc0994738d4719cc /internal/visibility | |
parent | Fix incorrect target being used in CC prop for mentioning statuses (#322) (diff) | |
download | gotosocial-79ccd8fd8acd09f78385cda799e9049cbc59de0f.tar.xz |
Fix mentioned accounts visibility bug (#323)
* update other tests
* set test status to followers_only
* add test dm
* fix mentioned accounts not being added to relevantAccounts
* add some visibility tests for statuses
Diffstat (limited to 'internal/visibility')
-rw-r--r-- | internal/visibility/filter_test.go | 74 | ||||
-rw-r--r-- | internal/visibility/relevantaccounts.go | 1 | ||||
-rw-r--r-- | internal/visibility/statusvisible_test.go | 115 |
3 files changed, 190 insertions, 0 deletions
diff --git a/internal/visibility/filter_test.go b/internal/visibility/filter_test.go new file mode 100644 index 000000000..a140d48e2 --- /dev/null +++ b/internal/visibility/filter_test.go @@ -0,0 +1,74 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package visibility_test + +import ( + "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/visibility" + "github.com/superseriousbusiness/gotosocial/testrig" +) + +type FilterStandardTestSuite struct { + // standard suite interfaces + suite.Suite + config *config.Config + db db.DB + + // standard suite models + testTokens map[string]*gtsmodel.Token + testClients map[string]*gtsmodel.Client + testApplications map[string]*gtsmodel.Application + testUsers map[string]*gtsmodel.User + testAccounts map[string]*gtsmodel.Account + testAttachments map[string]*gtsmodel.MediaAttachment + testStatuses map[string]*gtsmodel.Status + testTags map[string]*gtsmodel.Tag + testMentions map[string]*gtsmodel.Mention + + filter visibility.Filter +} + +func (suite *FilterStandardTestSuite) SetupSuite() { + suite.testTokens = testrig.NewTestTokens() + suite.testClients = testrig.NewTestClients() + suite.testApplications = testrig.NewTestApplications() + suite.testUsers = testrig.NewTestUsers() + suite.testAccounts = testrig.NewTestAccounts() + suite.testAttachments = testrig.NewTestAttachments() + suite.testStatuses = testrig.NewTestStatuses() + suite.testTags = testrig.NewTestTags() + suite.testMentions = testrig.NewTestMentions() +} + +func (suite *FilterStandardTestSuite) SetupTest() { + testrig.InitTestLog() + + suite.config = testrig.NewTestConfig() + suite.db = testrig.NewTestDB() + suite.filter = visibility.NewFilter(suite.db) + + testrig.StandardDBSetup(suite.db, nil) +} + +func (suite *FilterStandardTestSuite) TearDownTest() { + testrig.StandardDBTeardown(suite.db) +} diff --git a/internal/visibility/relevantaccounts.go b/internal/visibility/relevantaccounts.go index d19d26ff4..1be5efea9 100644 --- a/internal/visibility/relevantaccounts.go +++ b/internal/visibility/relevantaccounts.go @@ -134,6 +134,7 @@ func (f *filter) relevantAccounts(ctx context.Context, status *gtsmodel.Status, } if mentionIn(m, status.MentionIDs) { nm = append(nm, m) + relAccts.MentionedAccounts = append(relAccts.MentionedAccounts, m.TargetAccount) } } status.Mentions = nm diff --git a/internal/visibility/statusvisible_test.go b/internal/visibility/statusvisible_test.go new file mode 100644 index 000000000..f92bcd62f --- /dev/null +++ b/internal/visibility/statusvisible_test.go @@ -0,0 +1,115 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package visibility_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/suite" +) + +type StatusVisibleTestSuite struct { + FilterStandardTestSuite +} + +func (suite *StatusVisibleTestSuite) TestOwnStatusVisible() { + testStatus := suite.testStatuses["local_account_1_status_1"] + testAccount := suite.testAccounts["local_account_1"] + ctx := context.Background() + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.True(visible) +} + +func (suite *StatusVisibleTestSuite) TestOwnDMVisible() { + ctx := context.Background() + + testStatusID := suite.testStatuses["local_account_2_status_6"].ID + testStatus, err := suite.db.GetStatusByID(ctx, testStatusID) + suite.NoError(err) + testAccount := suite.testAccounts["local_account_2"] + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.True(visible) +} + +func (suite *StatusVisibleTestSuite) TestDMVisibleToTarget() { + ctx := context.Background() + + testStatusID := suite.testStatuses["local_account_2_status_6"].ID + testStatus, err := suite.db.GetStatusByID(ctx, testStatusID) + suite.NoError(err) + testAccount := suite.testAccounts["local_account_1"] + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.True(visible) +} + +func (suite *StatusVisibleTestSuite) TestDMNotVisibleIfNotMentioned() { + ctx := context.Background() + + testStatusID := suite.testStatuses["local_account_2_status_6"].ID + testStatus, err := suite.db.GetStatusByID(ctx, testStatusID) + suite.NoError(err) + testAccount := suite.testAccounts["admin_account"] + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.False(visible) +} + +func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotMutuals() { + ctx := context.Background() + + testStatusID := suite.testStatuses["local_account_1_status_4"].ID + testStatus, err := suite.db.GetStatusByID(ctx, testStatusID) + suite.NoError(err) + testAccount := suite.testAccounts["local_account_2"] + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.False(visible) +} + +func (suite *StatusVisibleTestSuite) TestStatusNotVisibleIfNotFollowing() { + ctx := context.Background() + + testStatusID := suite.testStatuses["local_account_1_status_5"].ID + testStatus, err := suite.db.GetStatusByID(ctx, testStatusID) + suite.NoError(err) + testAccount := suite.testAccounts["admin_account"] + + visible, err := suite.filter.StatusVisible(ctx, testStatus, testAccount) + suite.NoError(err) + + suite.False(visible) +} + +func TestStatusVisibleTestSuite(t *testing.T) { + suite.Run(t, new(StatusVisibleTestSuite)) +} |