summaryrefslogtreecommitdiff
path: root/internal/api/s2s/webfinger/webfingerget.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-06-11 11:01:34 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-11 11:01:34 +0200
commitdfdc473cefa255c5d0fb6c2e90e2b90815305c2f (patch)
treeaf3bbc5398ac24acbb2ca1158edfef8517344f8a /internal/api/s2s/webfinger/webfingerget.go
parent[feature] Add `created_at` and `error_description` to `/oauth/token` endpoint... (diff)
downloadgotosocial-dfdc473cefa255c5d0fb6c2e90e2b90815305c2f.tar.xz
[chore] Webfinger rework (#627)
* move finger to dereferencer * totally break GetRemoteAccount * start reworking finger func a bit * start reworking getRemoteAccount a bit * move mention parts to namestring * rework webfingerget * use util function to extract webfinger parts * use accountDomain * rework finger again, final form * just a real nasty commit, the worst * remove refresh from account * use new ASRepToAccount signature * fix incorrect debug call * fix for new getRemoteAccount * rework GetRemoteAccount * start updating tests to remove repetition * break a lot of tests Move shared test logic into the testrig, rather than having it scattered all over the place. This allows us to just mock the transport controller once, and have all tests use it (unless they need not to for some other reason). * fix up tests to use main mock httpclient * webfinger only if necessary * cheeky linting with the lads * update mentionName regex recognize instance accounts * don't finger instance accounts * test webfinger part extraction * increase default worker count to 4 per cpu * don't repeat regex parsing * final search for discovered accountDomain * be more permissive in namestring lookup * add more extraction tests * simplify GetParseMentionFunc * skip long search if local account * fix broken test
Diffstat (limited to 'internal/api/s2s/webfinger/webfingerget.go')
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go34
1 files changed, 9 insertions, 25 deletions
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index 7e7ca006b..6d4764ce5 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -22,13 +22,13 @@ import (
"context"
"fmt"
"net/http"
- "strings"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// WebfingerGETRequest swagger:operation GET /.well-known/webfinger webfingerGet
@@ -67,35 +67,19 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
return
}
- // remove the acct: prefix if it's present
- trimAcct := strings.TrimPrefix(resourceQuery, "acct:")
- // remove the first @ in @whatever@example.org if it's present
- namestring := strings.TrimPrefix(trimAcct, "@")
-
- // at this point we should have a string like some_user@example.org
- l.Debugf("got finger request for '%s'", namestring)
-
- usernameAndAccountDomain := strings.Split(namestring, "@")
- if len(usernameAndAccountDomain) != 2 {
- l.Debugf("aborting request because username and domain could not be parsed from %s", namestring)
- c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
- return
- }
-
- username := strings.ToLower(usernameAndAccountDomain[0])
- requestedAccountDomain := strings.ToLower(usernameAndAccountDomain[1])
- if username == "" || requestedAccountDomain == "" {
- l.Debug("aborting request because username or domain was empty")
- c.JSON(http.StatusBadRequest, gin.H{"error": "bad request"})
+ requestedUsername, requestedHost, err := util.ExtractWebfingerParts(resourceQuery)
+ if err != nil {
+ l.Debugf("bad webfinger request with resource query %s: %s", resourceQuery, err)
+ c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("bad webfinger request with resource query %s", resourceQuery)})
return
}
accountDomain := config.GetAccountDomain()
host := config.GetHost()
- if requestedAccountDomain != accountDomain && requestedAccountDomain != host {
- l.Debugf("aborting request because accountDomain %s does not belong to this instance", requestedAccountDomain)
- c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("accountDomain %s does not belong to this instance", requestedAccountDomain)})
+ if requestedHost != host && requestedHost != accountDomain {
+ l.Debugf("aborting request because requestedHost %s does not belong to this instance", requestedHost)
+ c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("requested host %s does not belong to this instance", requestedHost)})
return
}
@@ -106,7 +90,7 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
ctx = context.WithValue(ctx, ap.ContextRequestingPublicKeyVerifier, verifier)
}
- resp, errWithCode := m.processor.GetWebfingerAccount(ctx, username)
+ resp, errWithCode := m.processor.GetWebfingerAccount(ctx, requestedUsername)
if errWithCode != nil {
api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
return