2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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/>.
|
2022-09-06 10:42:55 +00:00
|
|
|
|
|
|
|
package emoji_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-01-02 12:10:50 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/api/activitypub/emoji"
|
2022-09-06 10:42:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/media"
|
2023-01-02 12:10:50 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/middleware"
|
2022-09-06 10:42:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
2023-03-01 18:26:53 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/state"
|
2022-09-06 10:42:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2023-05-25 08:37:38 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
2022-09-06 10:42:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EmojiGetTestSuite struct {
|
|
|
|
suite.Suite
|
2023-01-02 12:10:50 +00:00
|
|
|
db db.DB
|
2023-09-23 16:44:11 +00:00
|
|
|
tc *typeutils.Converter
|
2023-05-28 12:08:35 +00:00
|
|
|
mediaManager *media.Manager
|
2023-10-23 09:58:13 +00:00
|
|
|
federator *federation.Federator
|
2023-01-02 12:10:50 +00:00
|
|
|
emailSender email.Sender
|
2023-02-22 15:05:26 +00:00
|
|
|
processor *processing.Processor
|
2023-01-02 12:10:50 +00:00
|
|
|
storage *storage.Driver
|
2023-03-01 18:26:53 +00:00
|
|
|
state state.State
|
2022-09-06 10:42:55 +00:00
|
|
|
|
|
|
|
testEmojis map[string]*gtsmodel.Emoji
|
|
|
|
testAccounts map[string]*gtsmodel.Account
|
|
|
|
|
|
|
|
emojiModule *emoji.Module
|
2023-01-02 12:10:50 +00:00
|
|
|
|
|
|
|
signatureCheck gin.HandlerFunc
|
2022-09-06 10:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiGetTestSuite) SetupSuite() {
|
|
|
|
suite.testAccounts = testrig.NewTestAccounts()
|
|
|
|
suite.testEmojis = testrig.NewTestEmojis()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiGetTestSuite) SetupTest() {
|
2023-03-01 18:26:53 +00:00
|
|
|
suite.state.Caches.Init()
|
2023-11-14 14:57:25 +00:00
|
|
|
testrig.StartNoopWorkers(&suite.state)
|
2023-03-01 18:26:53 +00:00
|
|
|
|
2022-09-06 10:42:55 +00:00
|
|
|
testrig.InitTestConfig()
|
|
|
|
testrig.InitTestLog()
|
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
suite.db = testrig.NewTestDB(&suite.state)
|
|
|
|
suite.state.DB = suite.db
|
|
|
|
suite.storage = testrig.NewInMemoryStorage()
|
|
|
|
suite.state.Storage = suite.storage
|
2023-09-23 16:44:11 +00:00
|
|
|
suite.tc = typeutils.NewConverter(&suite.state)
|
2023-03-01 18:26:53 +00:00
|
|
|
|
2023-05-25 08:37:38 +00:00
|
|
|
testrig.StartTimelines(
|
|
|
|
&suite.state,
|
|
|
|
visibility.NewFilter(&suite.state),
|
|
|
|
suite.tc,
|
|
|
|
)
|
|
|
|
|
2023-03-01 18:26:53 +00:00
|
|
|
suite.mediaManager = testrig.NewTestMediaManager(&suite.state)
|
|
|
|
suite.federator = testrig.NewTestFederator(&suite.state, testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../../testrig/media")), suite.mediaManager)
|
2022-09-06 10:42:55 +00:00
|
|
|
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
|
2023-03-01 18:26:53 +00:00
|
|
|
suite.processor = testrig.NewTestProcessor(&suite.state, suite.federator, suite.emailSender, suite.mediaManager)
|
2023-01-02 12:10:50 +00:00
|
|
|
suite.emojiModule = emoji.New(suite.processor)
|
2022-09-06 10:42:55 +00:00
|
|
|
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
|
|
|
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
|
2022-09-28 17:30:40 +00:00
|
|
|
|
2023-01-02 12:10:50 +00:00
|
|
|
suite.signatureCheck = middleware.SignatureCheck(suite.db.IsURIBlocked)
|
2022-09-06 10:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiGetTestSuite) TearDownTest() {
|
|
|
|
testrig.StandardDBTeardown(suite.db)
|
|
|
|
testrig.StandardStorageTeardown(suite.storage)
|
2023-03-01 18:26:53 +00:00
|
|
|
testrig.StopWorkers(&suite.state)
|
2022-09-06 10:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *EmojiGetTestSuite) TestGetEmoji() {
|
|
|
|
// the dereference we're gonna use
|
|
|
|
derefRequests := testrig.NewTestDereferenceRequests(suite.testAccounts)
|
|
|
|
signedRequest := derefRequests["foss_satan_dereference_emoji"]
|
|
|
|
targetEmoji := suite.testEmojis["rainbow"]
|
|
|
|
|
|
|
|
// setup request
|
|
|
|
recorder := httptest.NewRecorder()
|
|
|
|
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
|
|
|
|
ctx.Request = httptest.NewRequest(http.MethodGet, targetEmoji.URI, nil) // the endpoint we're hitting
|
|
|
|
ctx.Request.Header.Set("accept", "application/activity+json")
|
|
|
|
ctx.Request.Header.Set("Signature", signedRequest.SignatureHeader)
|
|
|
|
ctx.Request.Header.Set("Date", signedRequest.DateHeader)
|
|
|
|
|
|
|
|
// we need to pass the context through signature check first to set appropriate values on it
|
2023-01-02 12:10:50 +00:00
|
|
|
suite.signatureCheck(ctx)
|
2022-09-06 10:42:55 +00:00
|
|
|
|
|
|
|
// normally the router would populate these params from the path values,
|
|
|
|
// but because we're calling the function directly, we need to set them manually.
|
|
|
|
ctx.Params = gin.Params{
|
|
|
|
gin.Param{
|
|
|
|
Key: emoji.EmojiIDKey,
|
|
|
|
Value: targetEmoji.ID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger the function being tested
|
|
|
|
suite.emojiModule.EmojiGetHandler(ctx)
|
|
|
|
|
|
|
|
// check response
|
|
|
|
suite.EqualValues(http.StatusOK, recorder.Code)
|
|
|
|
|
|
|
|
result := recorder.Result()
|
|
|
|
defer result.Body.Close()
|
|
|
|
b, err := ioutil.ReadAll(result.Body)
|
|
|
|
suite.NoError(err)
|
|
|
|
|
2022-11-30 15:20:57 +00:00
|
|
|
suite.Contains(string(b), `"icon":{"mediaType":"image/png","type":"Image","url":"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png"},"id":"http://localhost:8080/emoji/01F8MH9H8E4VG3KDYJR9EGPXCQ","name":":rainbow:","type":"Emoji"`)
|
2022-09-06 10:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmojiGetTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(EmojiGetTestSuite))
|
|
|
|
}
|