summaryrefslogtreecommitdiff
path: root/internal/api/s2s
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-07-05 13:23:03 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-05 13:23:03 +0200
commitd389e7b150df6ecd215c7b661b294ea153ad0103 (patch)
tree8739e3103cb5130875d903cc7fc72fd9db3b8434 /internal/api/s2s
parentFix 404 contact (#74) (diff)
downloadgotosocial-d389e7b150df6ecd215c7b661b294ea153ad0103.tar.xz
Domain block (#76)
* start work on admin domain blocking * move stuff around + further work on domain blocks * move + restructure processor * prep work for deleting account * tidy * go fmt * formatting * domain blocking more work * check domain blocks way earlier on * progress on delete account * delete more stuff when an account is gone * and more... * domain blocky block block * get individual domain block, delete a block
Diffstat (limited to 'internal/api/s2s')
-rw-r--r--internal/api/s2s/user/followers.go13
-rw-r--r--internal/api/s2s/user/following.go13
-rw-r--r--internal/api/s2s/user/inboxpost.go11
-rw-r--r--internal/api/s2s/user/publickeyget.go13
-rw-r--r--internal/api/s2s/user/statusget.go13
-rw-r--r--internal/api/s2s/user/userget.go13
-rw-r--r--internal/api/s2s/user/userget_test.go4
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go11
8 files changed, 72 insertions, 19 deletions
diff --git a/internal/api/s2s/user/followers.go b/internal/api/s2s/user/followers.go
index 9ccf9c4d5..6e33407d0 100644
--- a/internal/api/s2s/user/followers.go
+++ b/internal/api/s2s/user/followers.go
@@ -19,10 +19,12 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// FollowersGETHandler returns a collection of URIs for followers of the target user, formatted so that other AP servers can understand it.
@@ -46,9 +48,14 @@ func (m *Module) FollowersGETHandler(c *gin.Context) {
}
l.Tracef("negotiated format: %s", format)
- // make a copy of the context to pass along so we don't break anything
- cp := c.Copy()
- user, err := m.processor.GetFediFollowers(requestedUsername, cp.Request) // GetFediUser handles auth as well
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ user, 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()})
diff --git a/internal/api/s2s/user/following.go b/internal/api/s2s/user/following.go
index f19965c26..bdf815b05 100644
--- a/internal/api/s2s/user/following.go
+++ b/internal/api/s2s/user/following.go
@@ -19,10 +19,12 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// FollowingGETHandler returns a collection of URIs for accounts that the target user follows, formatted so that other AP servers can understand it.
@@ -46,9 +48,14 @@ func (m *Module) FollowingGETHandler(c *gin.Context) {
}
l.Tracef("negotiated format: %s", format)
- // make a copy of the context to pass along so we don't break anything
- cp := c.Copy()
- user, err := m.processor.GetFediFollowing(requestedUsername, cp.Request) // handles auth as well
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ user, 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()})
diff --git a/internal/api/s2s/user/inboxpost.go b/internal/api/s2s/user/inboxpost.go
index a51cd8add..98442af13 100644
--- a/internal/api/s2s/user/inboxpost.go
+++ b/internal/api/s2s/user/inboxpost.go
@@ -19,11 +19,13 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
@@ -40,7 +42,14 @@ func (m *Module) InboxPOSTHandler(c *gin.Context) {
return
}
- posted, err := m.processor.InboxPost(c.Request.Context(), c.Writer, c.Request)
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ posted, err := m.processor.InboxPost(ctx, c.Writer, c.Request)
if err != nil {
if withCode, ok := err.(gtserror.WithCode); ok {
l.Debug(withCode.Error())
diff --git a/internal/api/s2s/user/publickeyget.go b/internal/api/s2s/user/publickeyget.go
index b6aadedb2..bb1844e0e 100644
--- a/internal/api/s2s/user/publickeyget.go
+++ b/internal/api/s2s/user/publickeyget.go
@@ -1,10 +1,12 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// PublicKeyGETHandler should be served at eg https://example.org/users/:username/main-key.
@@ -32,9 +34,14 @@ func (m *Module) PublicKeyGETHandler(c *gin.Context) {
}
l.Tracef("negotiated format: %s", format)
- // make a copy of the context to pass along so we don't break anything
- cp := c.Copy()
- user, err := m.processor.GetFediUser(requestedUsername, cp.Request) // GetFediUser handles auth as well
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ user, err := m.processor.GetFediUser(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()})
diff --git a/internal/api/s2s/user/statusget.go b/internal/api/s2s/user/statusget.go
index 22774ae2c..37621d1de 100644
--- a/internal/api/s2s/user/statusget.go
+++ b/internal/api/s2s/user/statusget.go
@@ -1,10 +1,12 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// StatusGETHandler serves the target status as an activitystreams NOTE so that other AP servers can parse it.
@@ -34,9 +36,14 @@ func (m *Module) StatusGETHandler(c *gin.Context) {
}
l.Tracef("negotiated format: %s", format)
- // make a copy of the context to pass along so we don't break anything
- cp := c.Copy()
- status, err := m.processor.GetFediStatus(requestedUsername, requestedStatusID, cp.Request) // handles auth as well
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ status, err := m.processor.GetFediStatus(ctx, requestedUsername, requestedStatusID, c.Request.URL) // handles auth as well
if err != nil {
l.Info(err.Error())
c.JSON(err.Code(), gin.H{"error": err.Safe()})
diff --git a/internal/api/s2s/user/userget.go b/internal/api/s2s/user/userget.go
index 9d268e121..ac49b1529 100644
--- a/internal/api/s2s/user/userget.go
+++ b/internal/api/s2s/user/userget.go
@@ -19,10 +19,12 @@
package user
import (
+ "context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// UsersGETHandler should be served at https://example.org/users/:username.
@@ -54,9 +56,14 @@ func (m *Module) UsersGETHandler(c *gin.Context) {
}
l.Tracef("negotiated format: %s", format)
- // make a copy of the context to pass along so we don't break anything
- cp := c.Copy()
- user, err := m.processor.GetFediUser(requestedUsername, cp.Request) // GetFediUser handles auth as well
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ user, err := m.processor.GetFediUser(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()})
diff --git a/internal/api/s2s/user/userget_test.go b/internal/api/s2s/user/userget_test.go
index fab490767..d20148802 100644
--- a/internal/api/s2s/user/userget_test.go
+++ b/internal/api/s2s/user/userget_test.go
@@ -42,7 +42,7 @@ func (suite *UserGetTestSuite) SetupTest() {
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
suite.log = testrig.NewTestLog()
- suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil)))
+ suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil)), suite.storage)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
suite.userModule = user.New(suite.config, suite.processor, suite.log).(*user.Module)
testrig.StandardDBSetup(suite.db)
@@ -98,7 +98,7 @@ func (suite *UserGetTestSuite) TestGetUser() {
}, nil
}))
// get this transport controller embedded right in the user module we're testing
- federator := testrig.NewTestFederator(suite.db, tc)
+ federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator)
userModule := user.New(suite.config, processor, suite.log).(*user.Module)
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index 30e089162..416a75f3b 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -19,12 +19,14 @@
package webfinger
import (
+ "context"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/util"
)
// WebfingerGETRequest handles requests to, for example, https://example.org/.well-known/webfinger?resource=acct:some_user@example.org
@@ -68,7 +70,14 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
return
}
- resp, err := m.processor.GetWebfingerAccount(username, c.Request)
+ // transfer the signature verifier from the gin context to the request context
+ ctx := c.Request.Context()
+ verifier, signed := c.Get(string(util.APRequestingPublicKeyVerifier))
+ if signed {
+ ctx = context.WithValue(ctx, util.APRequestingPublicKeyVerifier, verifier)
+ }
+
+ resp, err := m.processor.GetWebfingerAccount(ctx, username, c.Request.URL)
if err != nil {
l.Debugf("aborting request with an error: %s", err.Error())
c.JSON(err.Code(), gin.H{"error": err.Safe()})