summaryrefslogtreecommitdiff
path: root/internal/typeutils/astointernal_test.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-08-13 09:01:50 +0000
committerLibravatar GitHub <noreply@github.com>2024-08-13 09:01:50 +0000
commit5212a1057ed05085d4d332976510880c6a692a8e (patch)
tree33ec543f66439328983deb688d3c10ae37e91264 /internal/typeutils/astointernal_test.go
parent[bugfix] incorrect AP serialize function used serializing worker data (#3196) (diff)
downloadgotosocial-5212a1057ed05085d4d332976510880c6a692a8e.tar.xz
[bugfix] relax missing preferred_username, instead using webfingered username (#3189)
* support no preferred_username, instead using webfingered username * add tests for the new preferred_username behaviour
Diffstat (limited to 'internal/typeutils/astointernal_test.go')
-rw-r--r--internal/typeutils/astointernal_test.go66
1 files changed, 61 insertions, 5 deletions
diff --git a/internal/typeutils/astointernal_test.go b/internal/typeutils/astointernal_test.go
index 3efc15999..998a3e974 100644
--- a/internal/typeutils/astointernal_test.go
+++ b/internal/typeutils/astointernal_test.go
@@ -65,7 +65,7 @@ func (suite *ASToInternalTestSuite) jsonToType(in string) vocab.Type {
func (suite *ASToInternalTestSuite) TestParsePerson() {
testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "", "")
suite.NoError(err)
suite.Equal("https://unknown-instance.com/users/brand_new_person", acct.URI)
@@ -87,7 +87,7 @@ func (suite *ASToInternalTestSuite) TestParsePerson() {
func (suite *ASToInternalTestSuite) TestParsePersonWithSharedInbox() {
testPerson := suite.testPeople["https://turnip.farm/users/turniplover6969"]
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), testPerson, "", "")
suite.NoError(err)
suite.Equal("https://turnip.farm/users/turniplover6969", acct.URI)
@@ -145,7 +145,7 @@ func (suite *ASToInternalTestSuite) TestParseGargron() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
suite.NoError(err)
suite.Equal("https://mastodon.social/inbox", *acct.SharedInboxURI)
suite.Equal([]string{"https://tooting.ai/users/Gargron"}, acct.AlsoKnownAsURIs)
@@ -196,7 +196,7 @@ func (suite *ASToInternalTestSuite) TestParseOwncastService() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
suite.NoError(err)
suite.Equal("rgh", acct.Username)
@@ -547,7 +547,7 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
suite.FailNow("type not coercible")
}
- acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "")
+ acct, err := suite.typeconverter.ASRepresentationToAccount(context.Background(), rep, "", "")
suite.NoError(err)
suite.Equal("https://honk.example.org/u/honk_user/followers", acct.FollowersURI)
suite.Equal("https://honk.example.org/u/honk_user/following", acct.FollowingURI)
@@ -651,6 +651,62 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
suite.False(*dbAcct.Discoverable)
}
+func (suite *ASToInternalTestSuite) TestParseAccountableWithoutPreferredUsername() {
+ ctx, cncl := context.WithCancel(context.Background())
+ defer cncl()
+
+ testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
+ // preferredUsername := "newish_person_actually"
+ username := "brand_new_person"
+
+ // Specifically unset the preferred_username field.
+ testPerson.SetActivityStreamsPreferredUsername(nil)
+
+ // Attempt to parse account model from ActivityStreams.
+ // This should fall back to the passed username argument as no preferred_username is set.
+ acc, err := suite.typeconverter.ASRepresentationToAccount(ctx, testPerson, "", username)
+ suite.NoError(err)
+ suite.Equal(acc.Username, username)
+}
+
+func (suite *ASToInternalTestSuite) TestParseAccountableWithoutAnyUsername() {
+ ctx, cncl := context.WithCancel(context.Background())
+ defer cncl()
+
+ testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
+ // preferredUsername := "newish_person_actually"
+ // username := "brand_new_person"
+
+ // Specifically unset the preferred_username field.
+ testPerson.SetActivityStreamsPreferredUsername(nil)
+
+ // Attempt to parse account model from ActivityStreams.
+ // This should return error as we provide no username and no preferred_username is set.
+ acc, err := suite.typeconverter.ASRepresentationToAccount(ctx, testPerson, "", "")
+ suite.Equal(err.Error(), "ASRepresentationToAccount: missing username for https://unknown-instance.com/users/brand_new_person")
+ suite.Nil(acc)
+}
+
+func (suite *ASToInternalTestSuite) TestParseAccountableWithPreferredUsername() {
+ ctx, cncl := context.WithCancel(context.Background())
+ defer cncl()
+
+ testPerson := suite.testPeople["https://unknown-instance.com/users/brand_new_person"]
+ preferredUsername := "newish_person_actually"
+ username := "brand_new_person"
+
+ // Specifically set a known preferred_username field.
+ prop := streams.NewActivityStreamsPreferredUsernameProperty()
+ prop.SetXMLSchemaString(preferredUsername)
+ testPerson.SetActivityStreamsPreferredUsername(prop)
+
+ // Attempt to parse account model from ActivityStreams.
+ // This should use the ActivityStreams preferred_username, instead of the passed argument.
+ acc, err := suite.typeconverter.ASRepresentationToAccount(ctx, testPerson, "", username)
+ suite.NoError(err)
+ suite.Equal(acc.Username, preferredUsername)
+}
+
func TestASToInternalTestSuite(t *testing.T) {
suite.Run(t, new(ASToInternalTestSuite))
}