mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-28 03:11:01 +00:00
[bugfix] Return empty result rather than 500 error when searching for blocked domains (#1498)
* [bugfix] Return empty result when searching for blocked domains * add tests
This commit is contained in:
parent
561ad71e58
commit
6c6f042290
2 changed files with 46 additions and 0 deletions
|
@ -252,6 +252,34 @@ func (suite *SearchGetTestSuite) TestSearchStatusByURL() {
|
||||||
suite.NotNil(gotStatus)
|
suite.NotNil(gotStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *SearchGetTestSuite) TestSearchBlockedDomainURL() {
|
||||||
|
query := "https://replyguys.com/@someone"
|
||||||
|
resolve := true
|
||||||
|
|
||||||
|
searchResult, err := suite.testSearch(query, resolve, http.StatusOK)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Len(searchResult.Accounts, 0)
|
||||||
|
suite.Len(searchResult.Statuses, 0)
|
||||||
|
suite.Len(searchResult.Hashtags, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *SearchGetTestSuite) TestSearchBlockedDomainNamestring() {
|
||||||
|
query := "@someone@replyguys.com"
|
||||||
|
resolve := true
|
||||||
|
|
||||||
|
searchResult, err := suite.testSearch(query, resolve, http.StatusOK)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Len(searchResult.Accounts, 0)
|
||||||
|
suite.Len(searchResult.Statuses, 0)
|
||||||
|
suite.Len(searchResult.Hashtags, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSearchGetTestSuite(t *testing.T) {
|
func TestSearchGetTestSuite(t *testing.T) {
|
||||||
suite.Run(t, &SearchGetTestSuite{})
|
suite.Run(t, &SearchGetTestSuite{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,15 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, search *a
|
||||||
|
|
||||||
if username, domain, err := util.ExtractNamestringParts(maybeNamestring); err == nil {
|
if username, domain, err := util.ExtractNamestringParts(maybeNamestring); err == nil {
|
||||||
l.Trace("search term is a mention, looking it up...")
|
l.Trace("search term is a mention, looking it up...")
|
||||||
|
blocked, err := p.db.IsDomainBlocked(ctx, domain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking domain block: %w", err))
|
||||||
|
}
|
||||||
|
if blocked {
|
||||||
|
l.Debug("domain is blocked")
|
||||||
|
return searchResult, nil
|
||||||
|
}
|
||||||
|
|
||||||
foundAccount, err := p.searchAccountByUsernameDomain(ctx, authed, username, domain, search.Resolve)
|
foundAccount, err := p.searchAccountByUsernameDomain(ctx, authed, username, domain, search.Resolve)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var errNotRetrievable *dereferencing.ErrNotRetrievable
|
var errNotRetrievable *dereferencing.ErrNotRetrievable
|
||||||
|
@ -110,6 +119,15 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, search *a
|
||||||
if uri, err := url.Parse(query); err == nil {
|
if uri, err := url.Parse(query); err == nil {
|
||||||
if uri.Scheme == "https" || uri.Scheme == "http" {
|
if uri.Scheme == "https" || uri.Scheme == "http" {
|
||||||
l.Trace("search term is a uri, looking it up...")
|
l.Trace("search term is a uri, looking it up...")
|
||||||
|
blocked, err := p.db.IsURIBlocked(ctx, uri)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error checking domain block: %w", err))
|
||||||
|
}
|
||||||
|
if blocked {
|
||||||
|
l.Debug("domain is blocked")
|
||||||
|
return searchResult, nil
|
||||||
|
}
|
||||||
|
|
||||||
// check if it's a status...
|
// check if it's a status...
|
||||||
foundStatus, err := p.searchStatusByURI(ctx, authed, uri)
|
foundStatus, err := p.searchStatusByURI(ctx, authed, uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue