From 3a11861ac67655aa87dea219067277ab30c553ad Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 30 Nov 2022 17:44:02 +0100 Subject: [PATCH] [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 --- internal/api/client/followrequest/get_test.go | 2 +- internal/api/client/search/searchget_test.go | 17 ++++++++ internal/db/bundb/account.go | 2 - .../federation/federatingdb/create_test.go | 2 +- internal/processing/followrequest_test.go | 4 +- internal/processing/fromfederator_test.go | 4 +- internal/typeutils/internaltofrontend_test.go | 2 +- testrig/testmodels.go | 40 +++++++++---------- testrig/transportcontroller.go | 6 +-- 9 files changed, 47 insertions(+), 32 deletions(-) diff --git a/internal/api/client/followrequest/get_test.go b/internal/api/client/followrequest/get_test.go index 01c9cc300..c9b72a35b 100644 --- a/internal/api/client/followrequest/get_test.go +++ b/internal/api/client/followrequest/get_test.go @@ -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) { diff --git a/internal/api/client/search/searchget_test.go b/internal/api/client/search/searchget_test.go index bcbe83baf..952b5fd5f 100644 --- a/internal/api/client/search/searchget_test.go +++ b/internal/api/client/search/searchget_test.go @@ -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 diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 3b36fe16b..712e0c1c7 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -22,7 +22,6 @@ "context" "errors" "fmt" - "strings" "time" "codeberg.org/gruf/go-cache/v3/result" @@ -102,7 +101,6 @@ func(account *gtsmodel.Account) error { } 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", diff --git a/internal/federation/federatingdb/create_test.go b/internal/federation/federatingdb/create_test.go index d4f277c37..399809e42 100644 --- a/internal/federation/federatingdb/create_test.go +++ b/internal/federation/federatingdb/create_test.go @@ -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) { diff --git a/internal/processing/followrequest_test.go b/internal/processing/followrequest_test.go index 5be615ab5..399afb566 100644 --- a/internal/processing/followrequest_test.go +++ b/internal/processing/followrequest_test.go @@ -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) diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go index 22d0ba9f4..75cef43f5 100644 --- a/internal/processing/fromfederator_test.go +++ b/internal/processing/fromfederator_test.go @@ -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) } diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go index 7c7f922fa..a3f134312 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -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() { diff --git a/testrig/testmodels.go b/testrig/testmodels.go index 11d64b2a9..b34c1a1d9 100644 --- a/testrig/testmodels.go +++ b/testrig/testmodels.go @@ -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"), diff --git a/testrig/transportcontroller.go b/testrig/transportcontroller.go index 18c3094d5..6296d4420 100644 --- a/testrig/transportcontroller.go +++ b/testrig/transportcontroller.go @@ -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", }, }, }