[bugfix] Don't call `strings.ToLower()` on usernames when selecting account by domain+username (#1190)

* don't lowercase account username when doing a select

* test getting remote user with uppercase username
This commit is contained in:
tobi 2022-11-30 17:44:02 +01:00 committed by GitHub
parent 8d581deb28
commit 3a11861ac6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 32 deletions

View File

@ -70,7 +70,7 @@ func (suite *GetTestSuite) TestGet() {
b, err := ioutil.ReadAll(result.Body)
assert.NoError(suite.T(), err)
suite.Equal(`[{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"some_user","acct":"some_user@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@some_user","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]}]`, string(b))
suite.Equal(`[{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"Some_User","acct":"Some_User@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@Some_User","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]}]`, string(b))
}
func TestGetTestSuite(t *testing.T) {

View File

@ -97,6 +97,23 @@ func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestring() {
suite.NotNil(gotAccount)
}
func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringUppercase() {
query := "@Some_User@example.org"
resolve := true
searchResult, err := suite.testSearch(query, resolve, http.StatusOK)
if err != nil {
suite.FailNow(err.Error())
}
if !suite.Len(searchResult.Accounts, 1) {
suite.FailNow("expected 1 account in search results but got 0")
}
gotAccount := searchResult.Accounts[0]
suite.NotNil(gotAccount)
}
func (suite *SearchGetTestSuite) TestSearchRemoteAccountByNamestringNoLeadingAt() {
query := "brand_new_person@unknown-instance.com"
resolve := true

View File

@ -22,7 +22,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"
"codeberg.org/gruf/go-cache/v3/result"
@ -102,7 +101,6 @@ func (a *accountDB) GetAccountByURL(ctx context.Context, url string) (*gtsmodel.
}
func (a *accountDB) GetAccountByUsernameDomain(ctx context.Context, username string, domain string) (*gtsmodel.Account, db.Error) {
username = strings.ToLower(username)
return a.getAccount(
ctx,
"Username.Domain",

View File

@ -80,7 +80,7 @@ func (suite *CreateTestSuite) TestCreateNoteForward() {
suite.Nil(msg.GTSModel)
// but we should have a uri set
suite.Equal("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1", msg.APIri.String())
suite.Equal("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1", msg.APIri.String())
}
func TestCreateTestSuite(t *testing.T) {

View File

@ -56,7 +56,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestAccept() {
suite.NoError(errWithCode)
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: true, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
// accept should be sent to some_user
// accept should be sent to Some_User
var sent [][]byte
if !testrig.WaitFor(func() bool {
sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)
@ -119,7 +119,7 @@ func (suite *FollowRequestTestSuite) TestFollowRequestReject() {
suite.NoError(errWithCode)
suite.EqualValues(&apimodel.Relationship{ID: "01FHMQX3GAABWSM0S2VZEC2SWC", Following: false, ShowingReblogs: false, Notifying: false, FollowedBy: false, Blocking: false, BlockedBy: false, Muting: false, MutingNotifications: false, Requested: false, DomainBlocking: false, Endorsed: false, Note: ""}, relationship)
// reject should be sent to some_user
// reject should be sent to Some_User
var sent [][]byte
if !testrig.WaitFor(func() bool {
sentI, ok := suite.httpClient.SentMessages.Load(requestingAccount.InboxURI)

View File

@ -556,12 +556,12 @@ func (suite *FromFederatorTestSuite) TestCreateStatusFromIRI() {
APActivityType: ap.ActivityCreate,
GTSModel: nil, // gtsmodel is nil because this is a forwarded status -- we want to dereference it using the iri
ReceivingAccount: receivingAccount,
APIri: testrig.URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
APIri: testrig.URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
})
suite.NoError(err)
// status should now be in the database, attributed to remote_account_2
s, err := suite.db.GetStatusByURI(context.Background(), "http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
s, err := suite.db.GetStatusByURI(context.Background(), "http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1")
suite.NoError(err)
suite.Equal(statusCreator.URI, s.AccountURI)
}

View File

@ -138,7 +138,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceToFrontendWithAdminAccount
b, err := json.Marshal(apiInstance)
suite.NoError(err)
suite.Equal(`{"uri":"https://example.org","title":"example instance","description":"a much longer description","short_description":"a little description","email":"someone@example.org","version":"software-from-hell 0.666","registrations":false,"approval_required":false,"invites_enabled":false,"thumbnail":"","contact_account":{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"some_user","acct":"some_user@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@some_user","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]},"max_toot_chars":0}`, string(b))
suite.Equal(`{"uri":"https://example.org","title":"example instance","description":"a much longer description","short_description":"a little description","email":"someone@example.org","version":"software-from-hell 0.666","registrations":false,"approval_required":false,"invites_enabled":false,"thumbnail":"","contact_account":{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"Some_User","acct":"Some_User@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@Some_User","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]},"max_toot_chars":0}`, string(b))
}
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontend() {

View File

@ -539,7 +539,7 @@ func NewTestAccounts() map[string]*gtsmodel.Account {
},
"remote_account_2": {
ID: "01FHMQX3GAABWSM0S2VZEC2SWC",
Username: "some_user",
Username: "Some_User",
Domain: "example.org",
DisplayName: "some user",
Fields: []gtsmodel.Field{},
@ -553,20 +553,20 @@ func NewTestAccounts() map[string]*gtsmodel.Account {
Discoverable: TrueBool(),
Sensitive: FalseBool(),
Language: "en",
URI: "http://example.org/users/some_user",
URL: "http://example.org/@some_user",
URI: "http://example.org/users/Some_User",
URL: "http://example.org/@Some_User",
LastWebfingeredAt: time.Time{},
InboxURI: "http://example.org/users/some_user/inbox",
InboxURI: "http://example.org/users/Some_User/inbox",
SharedInboxURI: StringPtr(""),
OutboxURI: "http://example.org/users/some_user/outbox",
FollowersURI: "http://example.org/users/some_user/followers",
FollowingURI: "http://example.org/users/some_user/following",
FeaturedCollectionURI: "http://example.org/users/some_user/collections/featured",
OutboxURI: "http://example.org/users/Some_User/outbox",
FollowersURI: "http://example.org/users/Some_User/followers",
FollowingURI: "http://example.org/users/Some_User/following",
FeaturedCollectionURI: "http://example.org/users/Some_User/collections/featured",
ActorType: ap.ActorPerson,
AlsoKnownAs: "",
PrivateKey: &rsa.PrivateKey{},
PublicKey: &rsa.PublicKey{},
PublicKeyURI: "http://example.org/users/some_user#main-key",
PublicKeyURI: "http://example.org/users/Some_User#main-key",
SensitizedAt: time.Time{},
SilencedAt: time.Time{},
SuspendedAt: time.Time{},
@ -1853,27 +1853,27 @@ func NewTestActivities(accounts map[string]*gtsmodel.Account) map[string]Activit
createReplyToTurtleForTurtleSig, createReplyToTurtleForTurtleDigest, createReplyToTurtleForTurtleDate := GetSignatureForActivity(createReplyToTurtle, accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_2"].InboxURI))
forwardedMessage := NewAPNote(
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
URLMustParse("http://example.org/@some_user/afaba698-5740-4e32-a702-af61aa543bc1"),
URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
URLMustParse("http://example.org/@Some_User/afaba698-5740-4e32-a702-af61aa543bc1"),
TimeMustParse("2022-07-13T12:13:12+02:00"),
"this is a public status, please forward it!",
"",
URLMustParse("http://example.org/users/some_user"),
URLMustParse("http://example.org/users/Some_User"),
[]*url.URL{URLMustParse(pub.PublicActivityPubIRI)},
nil,
false,
[]vocab.ActivityStreamsMention{},
[]vocab.ActivityStreamsImage{
newAPImage(
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1/attachment1.jpeg"),
URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1/attachment1.jpeg"),
"image/jpeg",
"trent reznor looking handsome as balls",
"LEDara58O=t5EMSOENEN9]}?aK%0"),
},
)
createForwardedMessage := WrapAPNoteInCreate(
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1/activity"),
URLMustParse("http://example.org/users/some_user"),
URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1/activity"),
URLMustParse("http://example.org/users/Some_User"),
TimeMustParse("2022-07-13T12:13:12+02:00"),
forwardedMessage)
createForwardedMessageSig, createForwardedMessageDigest, createForwardedMessageDate := GetSignatureForActivity(createForwardedMessage, accounts["remote_account_1"].PublicKeyURI, accounts["remote_account_1"].PrivateKey, URLMustParse(accounts["local_account_1"].InboxURI))
@ -2172,20 +2172,20 @@ func NewTestFediAttachments(relativePath string) map[string]RemoteAttachmentFile
func NewTestFediStatuses() map[string]vocab.ActivityStreamsNote {
return map[string]vocab.ActivityStreamsNote{
"http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1": NewAPNote(
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
URLMustParse("http://example.org/@some_user/afaba698-5740-4e32-a702-af61aa543bc1"),
"http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1": NewAPNote(
URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1"),
URLMustParse("http://example.org/@Some_User/afaba698-5740-4e32-a702-af61aa543bc1"),
TimeMustParse("2022-07-13T12:13:12+02:00"),
"this is a public status, please forward it!",
"",
URLMustParse("http://example.org/users/some_user"),
URLMustParse("http://example.org/users/Some_User"),
[]*url.URL{URLMustParse(pub.PublicActivityPubIRI)},
nil,
false,
[]vocab.ActivityStreamsMention{},
[]vocab.ActivityStreamsImage{
newAPImage(
URLMustParse("http://example.org/users/some_user/statuses/afaba698-5740-4e32-a702-af61aa543bc1/attachment1.jpeg"),
URLMustParse("http://example.org/users/Some_User/statuses/afaba698-5740-4e32-a702-af61aa543bc1/attachment1.jpeg"),
"image/jpeg",
"trent reznor looking handsome as balls",
"LEDara58O=t5EMSOENEN9]}?aK%0"),

View File

@ -282,14 +282,14 @@ func WebfingerResponse(req *http.Request) (responseCode int, responseBytes []byt
},
},
}
case "https://example.org/.well-known/webfinger?resource=acct:some_user@example.org":
case "https://example.org/.well-known/webfinger?resource=acct:Some_User@example.org":
wfr = &apimodel.WellKnownResponse{
Subject: "acct:some_user@example.org",
Subject: "acct:Some_User@example.org",
Links: []apimodel.Link{
{
Rel: "self",
Type: applicationActivityJSON,
Href: "https://example.org/users/some_user",
Href: "https://example.org/users/Some_User",
},
},
}