From 113186ce4e5bff2141b826d5da7eb2807eda4b45 Mon Sep 17 00:00:00 2001 From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 21 Jul 2021 17:46:59 +0200 Subject: [PATCH] lil webfingy fix (#106) * lil webfingy fix * return requested content type from fede requests --- internal/api/s2s/user/followers.go | 14 ++++++++++++-- internal/api/s2s/user/following.go | 14 ++++++++++++-- internal/api/s2s/user/publickeyget.go | 12 +++++++++++- internal/api/s2s/user/statusget.go | 12 +++++++++++- internal/api/s2s/user/userget.go | 12 +++++++++++- internal/api/s2s/webfinger/webfingerget.go | 2 +- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/internal/api/s2s/user/followers.go b/internal/api/s2s/user/followers.go index 6e33407d0..f9aec7ffb 100644 --- a/internal/api/s2s/user/followers.go +++ b/internal/api/s2s/user/followers.go @@ -20,6 +20,8 @@ package user import ( "context" + "encoding/json" + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -55,12 +57,20 @@ func (m *Module) FollowersGETHandler(c *gin.Context) { ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier) } - user, err := m.processor.GetFediFollowers(ctx, requestedUsername, c.Request.URL) // GetFediUser handles auth as well + followers, err := m.processor.GetFediFollowers(ctx, requestedUsername, c.Request.URL) // GetFediUser handles auth as well if err != nil { l.Info(err.Error()) c.JSON(err.Code(), gin.H{"error": err.Safe()}) return } - c.JSON(http.StatusOK, user) + b, mErr := json.Marshal(followers) + if mErr != nil { + err := fmt.Errorf("could not marshal json: %s", mErr) + l.Error(err) + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + c.Data(http.StatusOK, format, b) } diff --git a/internal/api/s2s/user/following.go b/internal/api/s2s/user/following.go index bdf815b05..4c010dbe0 100644 --- a/internal/api/s2s/user/following.go +++ b/internal/api/s2s/user/following.go @@ -20,6 +20,8 @@ package user import ( "context" + "encoding/json" + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -55,12 +57,20 @@ func (m *Module) FollowingGETHandler(c *gin.Context) { ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier) } - user, err := m.processor.GetFediFollowing(ctx, requestedUsername, c.Request.URL) // handles auth as well + following, err := m.processor.GetFediFollowing(ctx, requestedUsername, c.Request.URL) // handles auth as well if err != nil { l.Info(err.Error()) c.JSON(err.Code(), gin.H{"error": err.Safe()}) return } - c.JSON(http.StatusOK, user) + b, mErr := json.Marshal(following) + if mErr != nil { + err := fmt.Errorf("could not marshal json: %s", mErr) + l.Error(err) + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + c.Data(http.StatusOK, format, b) } diff --git a/internal/api/s2s/user/publickeyget.go b/internal/api/s2s/user/publickeyget.go index bb1844e0e..2cbe564df 100644 --- a/internal/api/s2s/user/publickeyget.go +++ b/internal/api/s2s/user/publickeyget.go @@ -2,6 +2,8 @@ package user import ( "context" + "encoding/json" + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -48,5 +50,13 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) { return } - c.JSON(http.StatusOK, user) + b, mErr := json.Marshal(user) + if mErr != nil { + err := fmt.Errorf("could not marshal json: %s", mErr) + l.Error(err) + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + c.Data(http.StatusOK, format, b) } diff --git a/internal/api/s2s/user/statusget.go b/internal/api/s2s/user/statusget.go index 37621d1de..04241d075 100644 --- a/internal/api/s2s/user/statusget.go +++ b/internal/api/s2s/user/statusget.go @@ -2,6 +2,8 @@ package user import ( "context" + "encoding/json" + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -50,5 +52,13 @@ func (m *Module) StatusGETHandler(c *gin.Context) { return } - c.JSON(http.StatusOK, status) + b, mErr := json.Marshal(status) + if mErr != nil { + err := fmt.Errorf("could not marshal json: %s", mErr) + l.Error(err) + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + c.Data(http.StatusOK, format, b) } diff --git a/internal/api/s2s/user/userget.go b/internal/api/s2s/user/userget.go index ac49b1529..f2f846f97 100644 --- a/internal/api/s2s/user/userget.go +++ b/internal/api/s2s/user/userget.go @@ -20,6 +20,8 @@ package user import ( "context" + "encoding/json" + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -70,5 +72,13 @@ func (m *Module) UsersGETHandler(c *gin.Context) { return } - c.JSON(http.StatusOK, user) + b, mErr := json.Marshal(user) + if mErr != nil { + err := fmt.Errorf("could not marshal json: %s", mErr) + l.Error(err) + c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return + } + + c.Data(http.StatusOK, format, b) } diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go index 1d723e67c..ee3176413 100644 --- a/internal/api/s2s/webfinger/webfingerget.go +++ b/internal/api/s2s/webfinger/webfingerget.go @@ -64,7 +64,7 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) { return } - if accountDomain != m.config.AccountDomain { + if accountDomain != m.config.AccountDomain && accountDomain != m.config.Host { l.Debugf("aborting request because accountDomain %s does not belong to this instance", accountDomain) c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("accountDomain %s does not belong to this instance", accountDomain)}) return