From 2cac5a4613ab51a5ac33a16cb54bb1210be9e8ce Mon Sep 17 00:00:00 2001 From: Daenney Date: Mon, 11 Sep 2023 18:38:31 +0200 Subject: [feature] Support Actor URIs for webfinger queries (#2187) * [feature] Support Actor URIs for webfinger queries It's now possible to pass an Actor URI as the resource to query for when doing a webfinger query. The code now extracts the username and domain from the URI. The URI needs to be fully qualified, including having a scheme of http or https to be recognised as such. The acct scheme is handled as we used to, including dealing with an erroneous leading @ on the username. We retain the ability to handle resources without a scheme by parsing them again with the acct scheme if the original parse failed. This can happen due to parsing ambiguities when dealing with a string like user@domain.tld:port. * [bugfix] Remove debugging changes * [chore] Make TestExtractNamestring table-driven * [chore] Unnest Trim and Split for readability --- .../api/wellknown/webfinger/webfingerget_test.go | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'internal/api') diff --git a/internal/api/wellknown/webfinger/webfingerget_test.go b/internal/api/wellknown/webfinger/webfingerget_test.go index 5b1cc47dd..fb450470f 100644 --- a/internal/api/wellknown/webfinger/webfingerget_test.go +++ b/internal/api/wellknown/webfinger/webfingerget_test.go @@ -143,6 +143,45 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() { }`, resp) } +func (suite *WebfingerGetTestSuite) TestFingerUserActorURI() { + targetAccount := suite.testAccounts["local_account_1"] + host := config.GetHost() + + tests := []struct { + resource string + }{ + {resource: fmt.Sprintf("https://%s/@%s", host, targetAccount.Username)}, + {resource: fmt.Sprintf("https://%s/users/%s", host, targetAccount.Username)}, + } + + for _, tt := range tests { + tt := tt + suite.Run(tt.resource, func() { + requestPath := fmt.Sprintf("/%s?resource=%s", webfinger.WebfingerBasePath, tt.resource) + resp := suite.finger(requestPath) + suite.Equal(`{ + "subject": "acct:the_mighty_zork@localhost:8080", + "aliases": [ + "http://localhost:8080/users/the_mighty_zork", + "http://localhost:8080/@the_mighty_zork" + ], + "links": [ + { + "rel": "http://webfinger.net/rel/profile-page", + "type": "text/html", + "href": "http://localhost:8080/@the_mighty_zork" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "http://localhost:8080/users/the_mighty_zork" + } + ] +}`, resp) + }) + } +} + func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHost() { targetAccount := suite.funkifyAccountDomain("gts.example.org", "example.org") requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, config.GetHost()) -- cgit v1.2.3