summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltoas_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-02-06 10:45:46 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-06 09:45:46 +0000
commitaa396c78d30c129bb2145765d3990571dbc025bb (patch)
treec2046f00c80b029d4f44a1eaf97ca2e960a492cf /internal/typeutils/internaltoas_test.go
parent[chore]: Bump github.com/miekg/dns from 1.1.57 to 1.1.58 (#2606) (diff)
downloadgotosocial-aa396c78d30c129bb2145765d3990571dbc025bb.tar.xz
[feature] serdes for moved/also_known_as (#2600)
* [feature] serdes for moved/also_known_as * document `alsoKnownAs` and `movedTo` properties * only implicitly populate AKA uris from DB for local accounts * don't let remotes store more than 20 AKA uris to avoid shenanigans
Diffstat (limited to 'internal/typeutils/internaltoas_test.go')
-rw-r--r--internal/typeutils/internaltoas_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index cbeaf3c8c..740938220 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -138,6 +138,72 @@ func (suite *InternalToASTestSuite) TestAccountToASWithFields() {
}`, trimmed)
}
+func (suite *InternalToASTestSuite) TestAccountToASAliasedAndMoved() {
+ testAccount := &gtsmodel.Account{}
+ *testAccount = *suite.testAccounts["local_account_1"] // take zork for this test
+
+ ctx := context.Background()
+
+ // Suppose zork has moved account to turtle.
+ testAccount.AlsoKnownAsURIs = []string{"http://localhost:8080/users/1happyturtle"}
+ testAccount.MovedToURI = "http://localhost:8080/users/1happyturtle"
+ if err := suite.state.DB.UpdateAccount(ctx,
+ testAccount,
+ "also_known_as_uris",
+ "moved_to_uri",
+ ); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ asPerson, err := suite.typeconverter.AccountToAS(context.Background(), testAccount)
+ suite.NoError(err)
+
+ ser, err := ap.Serialize(asPerson)
+ suite.NoError(err)
+
+ bytes, err := json.MarshalIndent(ser, "", " ")
+ suite.NoError(err)
+
+ // trim off everything up to 'alsoKnownAs';
+ // this is necessary because the order of multiple 'context' entries is not determinate
+ trimmed := strings.Split(string(bytes), "\"alsoKnownAs\"")[1]
+
+ suite.Equal(`: [
+ "http://localhost:8080/users/1happyturtle"
+ ],
+ "discoverable": true,
+ "featured": "http://localhost:8080/users/the_mighty_zork/collections/featured",
+ "followers": "http://localhost:8080/users/the_mighty_zork/followers",
+ "following": "http://localhost:8080/users/the_mighty_zork/following",
+ "icon": {
+ "mediaType": "image/jpeg",
+ "type": "Image",
+ "url": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg"
+ },
+ "id": "http://localhost:8080/users/the_mighty_zork",
+ "image": {
+ "mediaType": "image/jpeg",
+ "type": "Image",
+ "url": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg"
+ },
+ "inbox": "http://localhost:8080/users/the_mighty_zork/inbox",
+ "manuallyApprovesFollowers": false,
+ "movedTo": "http://localhost:8080/users/1happyturtle",
+ "name": "original zork (he/they)",
+ "outbox": "http://localhost:8080/users/the_mighty_zork/outbox",
+ "preferredUsername": "the_mighty_zork",
+ "publicKey": {
+ "id": "http://localhost:8080/users/the_mighty_zork/main-key",
+ "owner": "http://localhost:8080/users/the_mighty_zork",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwXTcOAvM1Jiw5Ffpk0qn\nr0cwbNvFe/5zQ+Tp7tumK/ZnT37o7X0FUEXrxNi+dkhmeJ0gsaiN+JQGNUewvpSk\nPIAXKvi908aSfCGjs7bGlJCJCuDuL5d6m7hZnP9rt9fJc70GElPpG0jc9fXwlz7T\nlsPb2ecatmG05Y4jPwdC+oN4MNCv9yQzEvCVMzl76EJaM602kIHC1CISn0rDFmYd\n9rSN7XPlNJw1F6PbpJ/BWQ+pXHKw3OEwNTETAUNYiVGnZU+B7a7bZC9f6/aPbJuV\nt8Qmg+UnDvW1Y8gmfHnxaWG2f5TDBvCHmcYtucIZPLQD4trAozC4ryqlmCWQNKbt\n0wIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "summary": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
+ "tag": [],
+ "type": "Person",
+ "url": "http://localhost:8080/@the_mighty_zork"
+}`, trimmed)
+}
+
func (suite *InternalToASTestSuite) TestAccountToASWithOneField() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_2"]