mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Dereference remote mentions when the account is not already known (#442)
* remove mention util function from db * add ParseMentionFunc to gtsmodel * add parseMentionFunc to processor * refactor search to simplify it a bit * add parseMentionFunc to account * add parseMentionFunc to status * some renaming for clarity * test dereference of unknown mentioned account
This commit is contained in:
@@ -19,8 +19,18 @@
|
||||
package status_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/gruf/go-store/kv"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/activity/pub"
|
||||
"github.com/superseriousbusiness/activity/streams"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/email"
|
||||
@@ -73,7 +83,7 @@ func (suite *StatusStandardTestSuite) SetupTest() {
|
||||
suite.tc = testrig.NewTestTypeConverter(suite.db)
|
||||
suite.storage = testrig.NewTestStorage()
|
||||
suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage)
|
||||
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage, suite.mediaManager)
|
||||
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(suite.testHttpClient(), suite.db), suite.storage, suite.mediaManager)
|
||||
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
|
||||
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender, suite.mediaManager)
|
||||
suite.statusModule = status.New(suite.processor).(*status.Module)
|
||||
@@ -85,3 +95,89 @@ func (suite *StatusStandardTestSuite) TearDownTest() {
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
testrig.StandardStorageTeardown(suite.storage)
|
||||
}
|
||||
|
||||
func (suite *StatusStandardTestSuite) testHttpClient() pub.HttpClient {
|
||||
remoteAccount := suite.testAccounts["remote_account_1"]
|
||||
remoteAccountNamestring := fmt.Sprintf("acct:%s@%s", remoteAccount.Username, remoteAccount.Domain)
|
||||
remoteAccountWebfingerURI := fmt.Sprintf("https://%s/.well-known/webfinger?resource=%s", remoteAccount.Domain, remoteAccountNamestring)
|
||||
|
||||
fmt.Println(remoteAccountWebfingerURI)
|
||||
|
||||
httpClient := testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
|
||||
// respond correctly to a webfinger lookup
|
||||
if req.URL.String() == remoteAccountWebfingerURI {
|
||||
responseJson := fmt.Sprintf(`
|
||||
{
|
||||
"subject": "%s",
|
||||
"aliases": [
|
||||
"%s",
|
||||
"%s"
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"rel": "http://webfinger.net/rel/profile-page",
|
||||
"type": "text/html",
|
||||
"href": "%s"
|
||||
},
|
||||
{
|
||||
"rel": "self",
|
||||
"type": "application/activity+json",
|
||||
"href": "%s"
|
||||
}
|
||||
]
|
||||
}`, remoteAccountNamestring, remoteAccount.URI, remoteAccount.URL, remoteAccount.URL, remoteAccount.URI)
|
||||
responseType := "application/json"
|
||||
|
||||
reader := bytes.NewReader([]byte(responseJson))
|
||||
readCloser := io.NopCloser(reader)
|
||||
response := &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: readCloser,
|
||||
ContentLength: int64(len(responseJson)),
|
||||
Header: http.Header{
|
||||
"content-type": {responseType},
|
||||
},
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// respond correctly to an account dereference
|
||||
if req.URL.String() == remoteAccount.URI {
|
||||
satanAS, err := suite.tc.AccountToAS(context.Background(), remoteAccount)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
satanI, err := streams.Serialize(satanAS)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
satanJson, err := json.Marshal(satanI)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
responseType := "application/activity+json"
|
||||
|
||||
reader := bytes.NewReader(satanJson)
|
||||
readCloser := io.NopCloser(reader)
|
||||
response := &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: readCloser,
|
||||
ContentLength: int64(len(satanJson)),
|
||||
Header: http.Header{
|
||||
"content-type": {responseType},
|
||||
},
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
r := ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: r,
|
||||
}, nil
|
||||
})
|
||||
|
||||
return httpClient
|
||||
}
|
||||
|
Reference in New Issue
Block a user