summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/account/account.go5
-rw-r--r--internal/api/client/account/account_test.go11
-rw-r--r--internal/api/client/account/accountcreate.go14
-rw-r--r--internal/api/client/admin/admin.go5
-rw-r--r--internal/api/client/app/app.go5
-rw-r--r--internal/api/client/auth/auth.go5
-rw-r--r--internal/api/client/auth/auth_test.go132
-rw-r--r--internal/api/client/auth/callback.go5
-rw-r--r--internal/api/client/blocks/blocks.go5
-rw-r--r--internal/api/client/emoji/emoji.go5
-rw-r--r--internal/api/client/favourites/favourites.go5
-rw-r--r--internal/api/client/fileserver/fileserver.go15
-rw-r--r--internal/api/client/fileserver/servefile_test.go8
-rw-r--r--internal/api/client/filter/filter.go5
-rw-r--r--internal/api/client/followrequest/followrequest.go5
-rw-r--r--internal/api/client/followrequest/followrequest_test.go11
-rw-r--r--internal/api/client/instance/instance.go5
-rw-r--r--internal/api/client/instance/instanceget.go9
-rw-r--r--internal/api/client/list/list.go5
-rw-r--r--internal/api/client/media/media.go5
-rw-r--r--internal/api/client/media/mediacreate.go24
-rw-r--r--internal/api/client/media/mediacreate_test.go8
-rw-r--r--internal/api/client/media/mediaupdate.go15
-rw-r--r--internal/api/client/notification/notification.go5
-rw-r--r--internal/api/client/search/search.go5
-rw-r--r--internal/api/client/status/status.go5
-rw-r--r--internal/api/client/status/status_test.go8
-rw-r--r--internal/api/client/status/statuscreate.go35
-rw-r--r--internal/api/client/streaming/streaming.go5
-rw-r--r--internal/api/client/timeline/timeline.go5
-rw-r--r--internal/api/client/user/user.go5
-rw-r--r--internal/api/client/user/user_test.go8
-rw-r--r--internal/api/s2s/nodeinfo/nodeinfo.go5
-rw-r--r--internal/api/s2s/user/inboxpost_test.go8
-rw-r--r--internal/api/s2s/user/outboxget_test.go6
-rw-r--r--internal/api/s2s/user/repliesget_test.go6
-rw-r--r--internal/api/s2s/user/user.go5
-rw-r--r--internal/api/s2s/user/user_test.go11
-rw-r--r--internal/api/s2s/user/userget_test.go2
-rw-r--r--internal/api/s2s/webfinger/webfinger.go5
-rw-r--r--internal/api/s2s/webfinger/webfinger_test.go11
-rw-r--r--internal/api/s2s/webfinger/webfingerget.go15
-rw-r--r--internal/api/s2s/webfinger/webfingerget_test.go30
-rw-r--r--internal/api/security/security.go5
44 files changed, 173 insertions, 329 deletions
diff --git a/internal/api/client/account/account.go b/internal/api/client/account/account.go
index 6e8b1e242..d75fb8e9c 100644
--- a/internal/api/client/account/account.go
+++ b/internal/api/client/account/account.go
@@ -24,7 +24,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
@@ -76,14 +75,12 @@ const (
// Module implements the ClientAPIModule interface for account-related actions
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new account module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/account/account_test.go b/internal/api/client/account/account_test.go
index 315ddfce3..f7dfa4520 100644
--- a/internal/api/client/account/account_test.go
+++ b/internal/api/client/account/account_test.go
@@ -8,6 +8,7 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/gin-gonic/gin"
+ "github.com/spf13/viper"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -24,7 +25,6 @@ import (
type AccountStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
storage *kv.KVStore
@@ -57,7 +57,7 @@ func (suite *AccountStandardTestSuite) SetupSuite() {
}
func (suite *AccountStandardTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
testrig.InitTestLog()
@@ -65,7 +65,7 @@ func (suite *AccountStandardTestSuite) SetupTest() {
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.accountModule = account.New(suite.config, suite.processor).(*account.Module)
+ suite.accountModule = account.New(suite.processor).(*account.Module)
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
@@ -83,7 +83,10 @@ func (suite *AccountStandardTestSuite) newContext(recorder *httptest.ResponseRec
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
- baseURI := fmt.Sprintf("%s://%s", suite.config.Protocol, suite.config.Host)
+ protocol := viper.GetString(config.Keys.Protocol)
+ host := viper.GetString(config.Keys.Host)
+
+ baseURI := fmt.Sprintf("%s://%s", protocol, host)
requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath)
ctx.Request = httptest.NewRequest(http.MethodPatch, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting
diff --git a/internal/api/client/account/accountcreate.go b/internal/api/client/account/accountcreate.go
index 6497d4d01..ae9d7b0d7 100644
--- a/internal/api/client/account/accountcreate.go
+++ b/internal/api/client/account/accountcreate.go
@@ -20,10 +20,12 @@ package account
import (
"errors"
- "github.com/sirupsen/logrus"
"net"
"net/http"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -85,7 +87,7 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
}
l.Tracef("validating form %+v", form)
- if err := validateCreateAccount(form, m.config.AccountsConfig); err != nil {
+ if err := validateCreateAccount(form); err != nil {
l.Debugf("error validating form: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
@@ -114,8 +116,10 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
// validateCreateAccount checks through all the necessary prerequisites for creating a new account,
// according to the provided account create request. If the account isn't eligible, an error will be returned.
-func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsConfig) error {
- if !c.OpenRegistration {
+func validateCreateAccount(form *model.AccountCreateRequest) error {
+ keys := config.Keys
+
+ if !viper.GetBool(keys.AccountsRegistrationOpen) {
return errors.New("registration is not open for this server")
}
@@ -139,7 +143,7 @@ func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsC
return err
}
- if err := validate.SignUpReason(form.Reason, c.ReasonRequired); err != nil {
+ if err := validate.SignUpReason(form.Reason, viper.GetBool(keys.AccountsReasonRequired)); err != nil {
return err
}
diff --git a/internal/api/client/admin/admin.go b/internal/api/client/admin/admin.go
index 35d162139..f611807a6 100644
--- a/internal/api/client/admin/admin.go
+++ b/internal/api/client/admin/admin.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -47,14 +46,12 @@ const (
// Module implements the ClientAPIModule interface for admin-related actions (reports, emojis, etc)
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new admin module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/app/app.go b/internal/api/client/app/app.go
index b3df7c388..a5f4c9bcd 100644
--- a/internal/api/client/app/app.go
+++ b/internal/api/client/app/app.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -32,14 +31,12 @@ const BasePath = "/api/v1/apps"
// Module implements the ClientAPIModule interface for requests relating to registering/removing applications
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new auth module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/auth/auth.go b/internal/api/client/auth/auth.go
index 7d9a0caf5..2552331a6 100644
--- a/internal/api/client/auth/auth.go
+++ b/internal/api/client/auth/auth.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/oidc"
@@ -54,16 +53,14 @@ const (
// Module implements the ClientAPIModule interface for
type Module struct {
- config *config.Config
db db.DB
server oauth.Server
idp oidc.IDP
}
// New returns a new auth module
-func New(config *config.Config, db db.DB, server oauth.Server, idp oidc.IDP) api.ClientModule {
+func New(db db.DB, server oauth.Server, idp oidc.IDP) api.ClientModule {
return &Module{
- config: config,
db: db,
server: server,
idp: idp,
diff --git a/internal/api/client/auth/auth_test.go b/internal/api/client/auth/auth_test.go
index ae58ffbbb..7f2a78ada 100644
--- a/internal/api/client/auth/auth_test.go
+++ b/internal/api/client/auth/auth_test.go
@@ -18,134 +18,4 @@
package auth_test
-import (
- "context"
- "fmt"
- "testing"
-
- "github.com/google/uuid"
- "github.com/sirupsen/logrus"
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/db/bundb"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
- "golang.org/x/crypto/bcrypt"
-)
-
-type AuthTestSuite struct {
- suite.Suite
- oauthServer oauth.Server
- db db.DB
- testAccount *gtsmodel.Account
- testApplication *gtsmodel.Application
- testUser *gtsmodel.User
- testClient *gtsmodel.Client
- config *config.Config
-}
-
-// SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
-func (suite *AuthTestSuite) SetupSuite() {
- c := config.Default()
- // we're running on localhost without https so set the protocol to http
- c.Protocol = "http"
- // just for testing
- c.Host = "localhost:8080"
- // because go tests are run within the test package directory, we need to fiddle with the templateconfig
- // basedir in a way that we wouldn't normally have to do when running the binary, in order to make
- // the templates actually load
- c.TemplateConfig.BaseDir = "../../../web/template/"
- c.DBConfig = &config.DBConfig{
- Type: "postgres",
- Address: "localhost",
- Port: 5432,
- User: "postgres",
- Password: "postgres",
- Database: "postgres",
- ApplicationName: "gotosocial",
- }
- suite.config = c
-
- encryptedPassword, err := bcrypt.GenerateFromPassword([]byte("password"), bcrypt.DefaultCost)
- if err != nil {
- logrus.Panicf("error encrypting user pass: %s", err)
- }
-
- acctID := uuid.NewString()
-
- suite.testAccount = &gtsmodel.Account{
- ID: acctID,
- Username: "test_user",
- }
- suite.testUser = &gtsmodel.User{
- EncryptedPassword: string(encryptedPassword),
- Email: "user@example.org",
- AccountID: acctID,
- }
- suite.testClient = &gtsmodel.Client{
- ID: "a-known-client-id",
- Secret: "some-secret",
- Domain: fmt.Sprintf("%s://%s", c.Protocol, c.Host),
- }
- suite.testApplication = &gtsmodel.Application{
- Name: "a test application",
- Website: "https://some-application-website.com",
- RedirectURI: "http://localhost:8080",
- ClientID: "a-known-client-id",
- ClientSecret: "some-secret",
- Scopes: "read",
- }
-}
-
-// SetupTest creates a postgres connection and creates the oauth_clients table before each test
-func (suite *AuthTestSuite) SetupTest() {
-
- log := logrus.New()
- log.SetLevel(logrus.TraceLevel)
- db, err := bundb.NewBunDBService(context.Background(), suite.config)
- if err != nil {
- logrus.Panicf("error creating database connection: %s", err)
- }
-
- suite.db = db
- suite.oauthServer = oauth.New(context.Background(), suite.db)
-
- if err := suite.db.Put(context.Background(), suite.testAccount); err != nil {
- logrus.Panicf("could not insert test account into db: %s", err)
- }
- if err := suite.db.Put(context.Background(), suite.testUser); err != nil {
- logrus.Panicf("could not insert test user into db: %s", err)
- }
- if err := suite.db.Put(context.Background(), suite.testClient); err != nil {
- logrus.Panicf("could not insert test client into db: %s", err)
- }
- if err := suite.db.Put(context.Background(), suite.testApplication); err != nil {
- logrus.Panicf("could not insert test application into db: %s", err)
- }
-
-}
-
-// TearDownTest drops the oauth_clients table and closes the pg connection after each test
-func (suite *AuthTestSuite) TearDownTest() {
- models := []interface{}{
- &gtsmodel.Client{},
- &gtsmodel.Token{},
- &gtsmodel.User{},
- &gtsmodel.Account{},
- &gtsmodel.Application{},
- }
- for _, m := range models {
- if err := suite.db.DropTable(context.Background(), m); err != nil {
- logrus.Panicf("error dropping table: %s", err)
- }
- }
- if err := suite.db.Stop(context.Background()); err != nil {
- logrus.Panicf("error closing db connection: %s", err)
- }
- suite.db = nil
-}
-
-func TestAuthTestSuite(t *testing.T) {
- suite.Run(t, new(AuthTestSuite))
-}
+// TODO
diff --git a/internal/api/client/auth/callback.go b/internal/api/client/auth/callback.go
index 286bcd935..d50fea3db 100644
--- a/internal/api/client/auth/callback.go
+++ b/internal/api/client/auth/callback.go
@@ -30,6 +30,8 @@ import (
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oidc"
@@ -211,7 +213,8 @@ func (m *Module) parseUserFromClaims(ctx context.Context, claims *oidc.Claims, i
password := uuid.NewString() + uuid.NewString()
// create the user! this will also create an account and store it in the database so we don't need to do that here
- user, err = m.db.NewSignup(ctx, username, "", m.config.AccountsConfig.RequireApproval, claims.Email, password, ip, "", appID, claims.EmailVerified, admin)
+ requireApproval := viper.GetBool(config.Keys.AccountsApprovalRequired)
+ user, err = m.db.NewSignup(ctx, username, "", requireApproval, claims.Email, password, ip, "", appID, claims.EmailVerified, admin)
if err != nil {
return nil, fmt.Errorf("error creating user: %s", err)
}
diff --git a/internal/api/client/blocks/blocks.go b/internal/api/client/blocks/blocks.go
index 531dfa8d8..552a6c599 100644
--- a/internal/api/client/blocks/blocks.go
+++ b/internal/api/client/blocks/blocks.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -41,14 +40,12 @@ const (
// Module implements the ClientAPIModule interface for everything relating to viewing blocks
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new blocks module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/emoji/emoji.go b/internal/api/client/emoji/emoji.go
index 4c69fbcc2..4ce021d8f 100644
--- a/internal/api/client/emoji/emoji.go
+++ b/internal/api/client/emoji/emoji.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -34,14 +33,12 @@ const (
// Module implements the ClientAPIModule interface for everything related to emoji
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new emoji module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/favourites/favourites.go b/internal/api/client/favourites/favourites.go
index daaab82f8..f03372ccd 100644
--- a/internal/api/client/favourites/favourites.go
+++ b/internal/api/client/favourites/favourites.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -45,14 +44,12 @@ const (
// Module implements the ClientAPIModule interface for everything relating to viewing favourites
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new favourites module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/fileserver/fileserver.go b/internal/api/client/fileserver/fileserver.go
index e60105686..092a15256 100644
--- a/internal/api/client/fileserver/fileserver.go
+++ b/internal/api/client/fileserver/fileserver.go
@@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
+ "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
@@ -42,22 +43,20 @@ const (
// FileServer implements the RESTAPIModule interface.
// The goal here is to serve requested media files if the gotosocial server is configured to use local storage.
type FileServer struct {
- config *config.Config
- processor processing.Processor
- storageBase string
+ processor processing.Processor
+ storageServeBasePath string
}
// New returns a new fileServer module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &FileServer{
- config: config,
- processor: processor,
- storageBase: config.StorageConfig.ServeBasePath,
+ processor: processor,
+ storageServeBasePath: viper.GetString(config.Keys.StorageServeBasePath),
}
}
// Route satisfies the RESTAPIModule interface
func (m *FileServer) Route(s router.Router) error {
- s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageBase, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey), m.ServeFile)
+ s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageServeBasePath, AccountIDKey, MediaTypeKey, MediaSizeKey, FileNameKey), m.ServeFile)
return nil
}
diff --git a/internal/api/client/fileserver/servefile_test.go b/internal/api/client/fileserver/servefile_test.go
index 692122a7b..b93f97606 100644
--- a/internal/api/client/fileserver/servefile_test.go
+++ b/internal/api/client/fileserver/servefile_test.go
@@ -32,7 +32,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/fileserver"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -47,7 +46,6 @@ import (
type ServeFileTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
storage *kv.KVStore
federator federation.Federator
@@ -75,9 +73,9 @@ type ServeFileTestSuite struct {
func (suite *ServeFileTestSuite) SetupSuite() {
// setup standard items
- suite.config = testrig.NewTestConfig()
- suite.db = testrig.NewTestDB()
+ testrig.InitTestConfig()
testrig.InitTestLog()
+ suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
@@ -88,7 +86,7 @@ func (suite *ServeFileTestSuite) SetupSuite() {
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
// setup module being tested
- suite.fileServer = fileserver.New(suite.config, suite.processor).(*fileserver.FileServer)
+ suite.fileServer = fileserver.New(suite.processor).(*fileserver.FileServer)
}
func (suite *ServeFileTestSuite) TearDownSuite() {
diff --git a/internal/api/client/filter/filter.go b/internal/api/client/filter/filter.go
index 2ec53bd0a..e8dea8170 100644
--- a/internal/api/client/filter/filter.go
+++ b/internal/api/client/filter/filter.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -34,14 +33,12 @@ const (
// Module implements the ClientAPIModule interface for every related to filters
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new filter module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/followrequest/followrequest.go b/internal/api/client/followrequest/followrequest.go
index 4f46e1654..75fbbea10 100644
--- a/internal/api/client/followrequest/followrequest.go
+++ b/internal/api/client/followrequest/followrequest.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -43,14 +42,12 @@ const (
// Module implements the ClientAPIModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new follow request module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/followrequest/followrequest_test.go b/internal/api/client/followrequest/followrequest_test.go
index 3c2cc32d0..e7dccc210 100644
--- a/internal/api/client/followrequest/followrequest_test.go
+++ b/internal/api/client/followrequest/followrequest_test.go
@@ -25,6 +25,7 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/gin-gonic/gin"
+ "github.com/spf13/viper"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -39,7 +40,6 @@ import (
type FollowRequestStandardTestSuite struct {
suite.Suite
- config *config.Config
db db.DB
storage *kv.KVStore
federator federation.Federator
@@ -70,14 +70,14 @@ func (suite *FollowRequestStandardTestSuite) SetupSuite() {
}
func (suite *FollowRequestStandardTestSuite) SetupTest() {
+ testrig.InitTestConfig()
testrig.InitTestLog()
- suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.followRequestModule = followrequest.New(suite.config, suite.processor).(*followrequest.Module)
+ suite.followRequestModule = followrequest.New(suite.processor).(*followrequest.Module)
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
@@ -95,7 +95,10 @@ func (suite *FollowRequestStandardTestSuite) newContext(recorder *httptest.Respo
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
- baseURI := fmt.Sprintf("%s://%s", suite.config.Protocol, suite.config.Host)
+ protocol := viper.GetString(config.Keys.Protocol)
+ host := viper.GetString(config.Keys.Host)
+
+ baseURI := fmt.Sprintf("%s://%s", protocol, host)
requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath)
ctx.Request = httptest.NewRequest(requestMethod, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting
diff --git a/internal/api/client/instance/instance.go b/internal/api/client/instance/instance.go
index 33e0054c3..758cce376 100644
--- a/internal/api/client/instance/instance.go
+++ b/internal/api/client/instance/instance.go
@@ -4,7 +4,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -16,14 +15,12 @@ const (
// Module implements the ClientModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new instance information module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/instance/instanceget.go b/internal/api/client/instance/instanceget.go
index fac917b25..f2f496cb5 100644
--- a/internal/api/client/instance/instanceget.go
+++ b/internal/api/client/instance/instanceget.go
@@ -1,9 +1,12 @@
package instance
import (
- "github.com/sirupsen/logrus"
"net/http"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
+
"github.com/gin-gonic/gin"
)
@@ -32,7 +35,9 @@ import (
func (m *Module) InstanceInformationGETHandler(c *gin.Context) {
l := logrus.WithField("func", "InstanceInformationGETHandler")
- instance, err := m.processor.InstanceGet(c.Request.Context(), m.config.Host)
+ host := viper.GetString(config.Keys.Host)
+
+ instance, err := m.processor.InstanceGet(c.Request.Context(), host)
if err != nil {
l.Debugf("error getting instance from processor: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
diff --git a/internal/api/client/list/list.go b/internal/api/client/list/list.go
index 106682ca9..347525d54 100644
--- a/internal/api/client/list/list.go
+++ b/internal/api/client/list/list.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -34,14 +33,12 @@ const (
// Module implements the ClientAPIModule interface for everything related to lists
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new list module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/media/media.go b/internal/api/client/media/media.go
index a051dea48..669ce9ce9 100644
--- a/internal/api/client/media/media.go
+++ b/internal/api/client/media/media.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -38,14 +37,12 @@ const BasePathWithID = BasePath + "/:" + IDKey
// Module implements the ClientAPIModule interface for media
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new auth module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/media/mediacreate.go b/internal/api/client/media/mediacreate.go
index 5b7a2dea7..f808b554c 100644
--- a/internal/api/client/media/mediacreate.go
+++ b/internal/api/client/media/mediacreate.go
@@ -21,9 +21,11 @@ package media
import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
"net/http"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -102,7 +104,7 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
// Give the fields on the request form a first pass to make sure the request is superficially valid.
l.Tracef("validating form %+v", form)
- if err := validateCreateMedia(form, m.config.MediaConfig); err != nil {
+ if err := validateCreateMedia(form); err != nil {
l.Debugf("error validating form: %s", err)
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": err.Error()})
return
@@ -119,24 +121,30 @@ func (m *Module) MediaCreatePOSTHandler(c *gin.Context) {
c.JSON(http.StatusOK, apiAttachment)
}
-func validateCreateMedia(form *model.AttachmentRequest, config *config.MediaConfig) error {
+func validateCreateMedia(form *model.AttachmentRequest) error {
// check there actually is a file attached and it's not size 0
if form.File == nil {
return errors.New("no attachment given")
}
+ keys := config.Keys
+ maxVideoSize := viper.GetInt(keys.MediaVideoMaxSize)
+ maxImageSize := viper.GetInt(keys.MediaImageMaxSize)
+ minDescriptionChars := viper.GetInt(keys.MediaDescriptionMinChars)
+ maxDescriptionChars := viper.GetInt(keys.MediaDescriptionMaxChars)
+
// a very superficial check to see if no size limits are exceeded
// we still don't actually know which media types we're dealing with but the other handlers will go into more detail there
- maxSize := config.MaxVideoSize
- if config.MaxImageSize > maxSize {
- maxSize = config.MaxImageSize
+ maxSize := maxVideoSize
+ if maxImageSize > maxSize {
+ maxSize = maxImageSize
}
if form.File.Size > int64(maxSize) {
return fmt.Errorf("file size limit exceeded: limit is %d bytes but attachment was %d bytes", maxSize, form.File.Size)
}
- if len(form.Description) < config.MinDescriptionChars || len(form.Description) > config.MaxDescriptionChars {
- return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", config.MinDescriptionChars, config.MaxDescriptionChars, len(form.Description))
+ if len(form.Description) < minDescriptionChars || len(form.Description) > maxDescriptionChars {
+ return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, len(form.Description))
}
// TODO: validate focus here
diff --git a/internal/api/client/media/mediacreate_test.go b/internal/api/client/media/mediacreate_test.go
index 9ad1b9001..f8a17c9de 100644
--- a/internal/api/client/media/mediacreate_test.go
+++ b/internal/api/client/media/mediacreate_test.go
@@ -35,7 +35,6 @@ import (
"github.com/stretchr/testify/suite"
mediamodule "github.com/superseriousbusiness/gotosocial/internal/api/client/media"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -50,7 +49,6 @@ import (
type MediaCreateTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
storage *kv.KVStore
federator federation.Federator
@@ -78,9 +76,9 @@ type MediaCreateTestSuite struct {
func (suite *MediaCreateTestSuite) SetupSuite() {
// setup standard items
- suite.config = testrig.NewTestConfig()
- suite.db = testrig.NewTestDB()
+ testrig.InitTestConfig()
testrig.InitTestLog()
+ suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.mediaHandler = testrig.NewTestMediaHandler(suite.db, suite.storage)
@@ -90,7 +88,7 @@ func (suite *MediaCreateTestSuite) SetupSuite() {
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
// setup module being tested
- suite.mediaModule = mediamodule.New(suite.config, suite.processor).(*mediamodule.Module)
+ suite.mediaModule = mediamodule.New(suite.processor).(*mediamodule.Module)
}
func (suite *MediaCreateTestSuite) TearDownSuite() {
diff --git a/internal/api/client/media/mediaupdate.go b/internal/api/client/media/mediaupdate.go
index 2a6d056bb..c22e4e919 100644
--- a/internal/api/client/media/mediaupdate.go
+++ b/internal/api/client/media/mediaupdate.go
@@ -21,9 +21,11 @@ package media
import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
"net/http"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -117,7 +119,7 @@ func (m *Module) MediaPUTHandler(c *gin.Context) {
// Give the fields on the request form a first pass to make sure the request is superficially valid.
l.Tracef("validating form %+v", form)
- if err := validateUpdateMedia(&form, m.config.MediaConfig); err != nil {
+ if err := validateUpdateMedia(&form); err != nil {
l.Debugf("error validating form: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
@@ -132,11 +134,14 @@ func (m *Module) MediaPUTHandler(c *gin.Context) {
c.JSON(http.StatusOK, attachment)
}
-func validateUpdateMedia(form *model.AttachmentUpdateRequest, config *config.MediaConfig) error {
+func validateUpdateMedia(form *model.AttachmentUpdateRequest) error {
+ keys := config.Keys
+ minDescriptionChars := viper.GetInt(keys.MediaDescriptionMinChars)
+ maxDescriptionChars := viper.GetInt(keys.MediaDescriptionMaxChars)
if form.Description != nil {
- if len(*form.Description) < config.MinDescriptionChars || len(*form.Description) > config.MaxDescriptionChars {
- return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", config.MinDescriptionChars, config.MaxDescriptionChars, len(*form.Description))
+ if len(*form.Description) < minDescriptionChars || len(*form.Description) > maxDescriptionChars {
+ return fmt.Errorf("image description length must be between %d and %d characters (inclusive), but provided image description was %d chars", minDescriptionChars, maxDescriptionChars, len(*form.Description))
}
}
diff --git a/internal/api/client/notification/notification.go b/internal/api/client/notification/notification.go
index 04a1c2909..bc2d1e4bb 100644
--- a/internal/api/client/notification/notification.go
+++ b/internal/api/client/notification/notification.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -46,14 +45,12 @@ const (
// Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with notifications
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new notification module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/search/search.go b/internal/api/client/search/search.go
index 474cccb27..b0b9c8613 100644
--- a/internal/api/client/search/search.go
+++ b/internal/api/client/search/search.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -65,14 +64,12 @@ const (
// Module implements the ClientAPIModule interface for everything related to searching
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new search module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/status/status.go b/internal/api/client/status/status.go
index 6c7f077e1..2c6fc614a 100644
--- a/internal/api/client/status/status.go
+++ b/internal/api/client/status/status.go
@@ -26,7 +26,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -75,14 +74,12 @@ const (
// Module implements the ClientAPIModule interface for every related to posting/deleting/interacting with statuses
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new account module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/status/status_test.go b/internal/api/client/status/status_test.go
index 399873fcc..0af5b78c2 100644
--- a/internal/api/client/status/status_test.go
+++ b/internal/api/client/status/status_test.go
@@ -22,7 +22,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/status"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -35,7 +34,6 @@ import (
type StatusStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
federator federation.Federator
@@ -67,15 +65,15 @@ func (suite *StatusStandardTestSuite) SetupSuite() {
}
func (suite *StatusStandardTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestConfig()
+ testrig.InitTestLog()
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
- testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.statusModule = status.New(suite.config, suite.processor).(*status.Module)
+ suite.statusModule = status.New(suite.processor).(*status.Module)
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
diff --git a/internal/api/client/status/statuscreate.go b/internal/api/client/status/statuscreate.go
index e9d92890e..629a325c5 100644
--- a/internal/api/client/status/statuscreate.go
+++ b/internal/api/client/status/statuscreate.go
@@ -21,9 +21,11 @@ package status
import (
"errors"
"fmt"
- "github.com/sirupsen/logrus"
"net/http"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/config"
@@ -96,7 +98,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
// Give the fields on the request form a first pass to make sure the request is superficially valid.
l.Tracef("validating form %+v", form)
- if err := validateCreateStatus(form, m.config.StatusesConfig); err != nil {
+ if err := validateCreateStatus(form); err != nil {
l.Debugf("error validating form: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
@@ -112,7 +114,7 @@ func (m *Module) StatusCreatePOSTHandler(c *gin.Context) {
c.JSON(http.StatusOK, apiStatus)
}
-func validateCreateStatus(form *model.AdvancedStatusCreateForm, config *config.StatusesConfig) error {
+func validateCreateStatus(form *model.AdvancedStatusCreateForm) error {
// validate that, structurally, we have a valid status/post
if form.Status == "" && form.MediaIDs == nil && form.Poll == nil {
return errors.New("no status, media, or poll provided")
@@ -122,16 +124,23 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm, config *config.S
return errors.New("can't post media + poll in same status")
}
+ keys := config.Keys
+ maxChars := viper.GetInt(keys.StatusesMaxChars)
+ maxMediaFiles := viper.GetInt(keys.StatusesMediaMaxFiles)
+ maxPollOptions := viper.GetInt(keys.StatusesPollMaxOptions)
+ maxPollChars := viper.GetInt(keys.StatusesPollOptionMaxChars)
+ maxCwChars := viper.GetInt(keys.StatusesCWMaxChars)
+
// validate status
if form.Status != "" {
- if len(form.Status) > config.MaxChars {
- return fmt.Errorf("status too long, %d characters provided but limit is %d", len(form.Status), config.MaxChars)
+ if len(form.Status) > maxChars {
+ return fmt.Errorf("status too long, %d characters provided but limit is %d", len(form.Status), maxChars)
}
}
// validate media attachments
- if len(form.MediaIDs) > config.MaxMediaFiles {
- return fmt.Errorf("too many media files attached to status, %d attached but limit is %d", len(form.MediaIDs), config.MaxMediaFiles)
+ if len(form.MediaIDs) > maxMediaFiles {
+ return fmt.Errorf("too many media files attached to status, %d attached but limit is %d", len(form.MediaIDs), maxMediaFiles)
}
// validate poll
@@ -139,20 +148,20 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm, config *config.S
if form.Poll.Options == nil {
return errors.New("poll with no options")
}
- if len(form.Poll.Options) > config.PollMaxOptions {
- return fmt.Errorf("too many poll options provided, %d provided but limit is %d", len(form.Poll.Options), config.PollMaxOptions)
+ if len(form.Poll.Options) > maxPollOptions {
+ return fmt.Errorf("too many poll options provided, %d provided but limit is %d", len(form.Poll.Options), maxPollOptions)
}
for _, p := range form.Poll.Options {
- if len(p) > config.PollOptionMaxChars {
- return fmt.Errorf("poll option too long, %d characters provided but limit is %d", len(p), config.PollOptionMaxChars)
+ if len(p) > maxPollChars {
+ return fmt.Errorf("poll option too long, %d characters provided but limit is %d", len(p), maxPollChars)
}
}
}
// validate spoiler text/cw
if form.SpoilerText != "" {
- if len(form.SpoilerText) > config.CWMaxChars {
- return fmt.Errorf("content-warning/spoilertext too long, %d characters provided but limit is %d", len(form.SpoilerText), config.CWMaxChars)
+ if len(form.SpoilerText) > maxCwChars {
+ return fmt.Errorf("content-warning/spoilertext too long, %d characters provided but limit is %d", len(form.SpoilerText), maxCwChars)
}
}
diff --git a/internal/api/client/streaming/streaming.go b/internal/api/client/streaming/streaming.go
index fd52419e0..cd499455f 100644
--- a/internal/api/client/streaming/streaming.go
+++ b/internal/api/client/streaming/streaming.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -40,14 +39,12 @@ const (
// Module implements the api.ClientModule interface for everything related to streaming
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new streaming module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/timeline/timeline.go b/internal/api/client/timeline/timeline.go
index 2aa939f61..3e9b37e07 100644
--- a/internal/api/client/timeline/timeline.go
+++ b/internal/api/client/timeline/timeline.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -48,14 +47,12 @@ const (
// Module implements the ClientAPIModule interface for everything relating to viewing timelines
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new timeline module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/user/user.go b/internal/api/client/user/user.go
index ff28a197f..89f71344b 100644
--- a/internal/api/client/user/user.go
+++ b/internal/api/client/user/user.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -36,14 +35,12 @@ const (
// Module implements the ClientAPIModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new user module
-func New(config *config.Config, processor processing.Processor) api.ClientModule {
+func New(processor processing.Processor) api.ClientModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/client/user/user_test.go b/internal/api/client/user/user_test.go
index 76d95b2d9..4a9a1a9d7 100644
--- a/internal/api/client/user/user_test.go
+++ b/internal/api/client/user/user_test.go
@@ -22,7 +22,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/client/user"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -34,7 +33,6 @@ import (
type UserStandardTestSuite struct {
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
federator federation.Federator
@@ -54,21 +52,21 @@ type UserStandardTestSuite struct {
}
func (suite *UserStandardTestSuite) SetupTest() {
+ testrig.InitTestLog()
+ testrig.InitTestConfig()
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
- suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.storage = testrig.NewTestStorage()
- testrig.InitTestLog()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", suite.sentEmails)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.userModule = user.New(suite.config, suite.processor).(*user.Module)
+ suite.userModule = user.New(suite.processor).(*user.Module)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
diff --git a/internal/api/s2s/nodeinfo/nodeinfo.go b/internal/api/s2s/nodeinfo/nodeinfo.go
index 5d1d03b24..1cbf32760 100644
--- a/internal/api/s2s/nodeinfo/nodeinfo.go
+++ b/internal/api/s2s/nodeinfo/nodeinfo.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -36,14 +35,12 @@ const (
// Module implements the FederationModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new nodeinfo module
-func New(config *config.Config, processor processing.Processor) api.FederationModule {
+func New(processor processing.Processor) api.FederationModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/s2s/user/inboxpost_test.go b/internal/api/s2s/user/inboxpost_test.go
index 4d1c05757..716dcfc25 100644
--- a/internal/api/s2s/user/inboxpost_test.go
+++ b/internal/api/s2s/user/inboxpost_test.go
@@ -87,7 +87,7 @@ func (suite *InboxPostTestSuite) TestPostBlock() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -187,7 +187,7 @@ func (suite *InboxPostTestSuite) TestPostUnblock() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -277,7 +277,7 @@ func (suite *InboxPostTestSuite) TestPostUpdate() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -398,7 +398,7 @@ func (suite *InboxPostTestSuite) TestPostDelete() {
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
err = processor.Start(context.Background())
suite.NoError(err)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
diff --git a/internal/api/s2s/user/outboxget_test.go b/internal/api/s2s/user/outboxget_test.go
index 251051cbd..4cd556bbe 100644
--- a/internal/api/s2s/user/outboxget_test.go
+++ b/internal/api/s2s/user/outboxget_test.go
@@ -48,7 +48,7 @@ func (suite *OutboxGetTestSuite) TestGetOutbox() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -102,7 +102,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxFirstPage() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -156,7 +156,7 @@ func (suite *OutboxGetTestSuite) TestGetOutboxNextPage() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
diff --git a/internal/api/s2s/user/repliesget_test.go b/internal/api/s2s/user/repliesget_test.go
index cd1094b53..a4229bb21 100644
--- a/internal/api/s2s/user/repliesget_test.go
+++ b/internal/api/s2s/user/repliesget_test.go
@@ -51,7 +51,7 @@ func (suite *RepliesGetTestSuite) TestGetReplies() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -111,7 +111,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesNext() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
@@ -174,7 +174,7 @@ func (suite *RepliesGetTestSuite) TestGetRepliesLast() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
diff --git a/internal/api/s2s/user/user.go b/internal/api/s2s/user/user.go
index 56b940f1d..891f2c1b1 100644
--- a/internal/api/s2s/user/user.go
+++ b/internal/api/s2s/user/user.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
"github.com/superseriousbusiness/gotosocial/internal/util"
@@ -66,14 +65,12 @@ const (
// Module implements the FederationAPIModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new auth module
-func New(config *config.Config, processor processing.Processor) api.FederationModule {
+func New(processor processing.Processor) api.FederationModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/s2s/user/user_test.go b/internal/api/s2s/user/user_test.go
index da305488f..ed6a83312 100644
--- a/internal/api/s2s/user/user_test.go
+++ b/internal/api/s2s/user/user_test.go
@@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/user"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -37,7 +36,6 @@ import (
type UserStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
federator federation.Federator
@@ -73,17 +71,18 @@ func (suite *UserStandardTestSuite) SetupSuite() {
}
func (suite *UserStandardTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestLog()
+ testrig.InitTestConfig()
+
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
- testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.userModule = user.New(suite.config, suite.processor).(*user.Module)
+ suite.userModule = user.New(suite.processor).(*user.Module)
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
- suite.securityModule = security.New(suite.config, suite.db, suite.oauthServer).(*security.Module)
+ suite.securityModule = security.New(suite.db, suite.oauthServer).(*security.Module)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
diff --git a/internal/api/s2s/user/userget_test.go b/internal/api/s2s/user/userget_test.go
index 303295cfe..8ad4a8151 100644
--- a/internal/api/s2s/user/userget_test.go
+++ b/internal/api/s2s/user/userget_test.go
@@ -49,7 +49,7 @@ func (suite *UserGetTestSuite) TestGetUser() {
federator := testrig.NewTestFederator(suite.db, tc, suite.storage)
emailSender := testrig.NewEmailSender("../../../../web/template/", nil)
processor := testrig.NewTestProcessor(suite.db, suite.storage, federator, emailSender)
- userModule := user.New(suite.config, processor).(*user.Module)
+ userModule := user.New(processor).(*user.Module)
// setup request
recorder := httptest.NewRecorder()
diff --git a/internal/api/s2s/webfinger/webfinger.go b/internal/api/s2s/webfinger/webfinger.go
index c447d730e..2ad77d56f 100644
--- a/internal/api/s2s/webfinger/webfinger.go
+++ b/internal/api/s2s/webfinger/webfinger.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -34,14 +33,12 @@ const (
// Module implements the FederationModule interface
type Module struct {
- config *config.Config
processor processing.Processor
}
// New returns a new webfinger module
-func New(config *config.Config, processor processing.Processor) api.FederationModule {
+func New(processor processing.Processor) api.FederationModule {
return &Module{
- config: config,
processor: processor,
}
}
diff --git a/internal/api/s2s/webfinger/webfinger_test.go b/internal/api/s2s/webfinger/webfinger_test.go
index 679dbcd5d..f2e6d0659 100644
--- a/internal/api/s2s/webfinger/webfinger_test.go
+++ b/internal/api/s2s/webfinger/webfinger_test.go
@@ -28,7 +28,6 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
"github.com/superseriousbusiness/gotosocial/internal/api/security"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
"github.com/superseriousbusiness/gotosocial/internal/federation"
@@ -42,7 +41,6 @@ import (
type WebfingerStandardTestSuite struct {
// standard suite interfaces
suite.Suite
- config *config.Config
db db.DB
tc typeutils.TypeConverter
federator federation.Federator
@@ -76,17 +74,18 @@ func (suite *WebfingerStandardTestSuite) SetupSuite() {
}
func (suite *WebfingerStandardTestSuite) SetupTest() {
- suite.config = testrig.NewTestConfig()
+ testrig.InitTestLog()
+ testrig.InitTestConfig()
+
suite.db = testrig.NewTestDB()
suite.tc = testrig.NewTestTypeConverter(suite.db)
suite.storage = testrig.NewTestStorage()
- testrig.InitTestLog()
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil), suite.db), suite.storage)
suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender)
- suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module)
+ suite.webfingerModule = webfinger.New(suite.processor).(*webfinger.Module)
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
- suite.securityModule = security.New(suite.config, suite.db, suite.oauthServer).(*security.Module)
+ suite.securityModule = security.New(suite.db, suite.oauthServer).(*security.Module)
testrig.StandardDBSetup(suite.db, suite.testAccounts)
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
}
diff --git a/internal/api/s2s/webfinger/webfingerget.go b/internal/api/s2s/webfinger/webfingerget.go
index 3552394f2..b7f3c714d 100644
--- a/internal/api/s2s/webfinger/webfingerget.go
+++ b/internal/api/s2s/webfinger/webfingerget.go
@@ -26,6 +26,8 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -59,16 +61,19 @@ func (m *Module) WebfingerGETRequest(c *gin.Context) {
}
username := strings.ToLower(usernameAndAccountDomain[0])
- accountDomain := strings.ToLower(usernameAndAccountDomain[1])
- if username == "" || accountDomain == "" {
+ 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"})
return
}
- 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)})
+ accountDomain := viper.GetString(config.Keys.AccountDomain)
+ host := viper.GetString(config.Keys.Host)
+
+ 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)})
return
}
diff --git a/internal/api/s2s/webfinger/webfingerget_test.go b/internal/api/s2s/webfinger/webfingerget_test.go
index 19c637929..8314972d6 100644
--- a/internal/api/s2s/webfinger/webfingerget_test.go
+++ b/internal/api/s2s/webfinger/webfingerget_test.go
@@ -27,9 +27,11 @@ import (
"testing"
"github.com/gin-gonic/gin"
+ "github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/api/s2s/webfinger"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/testrig"
)
@@ -42,7 +44,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() {
targetAccount := suite.testAccounts["local_account_1"]
// setup request
- requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, suite.config.Host)
+ host := viper.GetString(config.Keys.Host)
+ requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, host)
recorder := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(recorder)
@@ -63,10 +66,10 @@ func (suite *WebfingerGetTestSuite) TestFingerUser() {
}
func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHost() {
- suite.config.Host = "gts.example.org"
- suite.config.AccountDomain = "example.org"
- suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.emailSender)
- suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module)
+ viper.Set(config.Keys.Host, "gts.example.org")
+ viper.Set(config.Keys.AccountDomain, "example.org")
+ suite.processor = processing.NewProcessor(suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.emailSender)
+ suite.webfingerModule = webfinger.New(suite.processor).(*webfinger.Module)
targetAccount := accountDomainAccount()
if err := suite.db.Put(context.Background(), targetAccount); err != nil {
@@ -74,7 +77,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHo
}
// setup request
- requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, suite.config.Host)
+ host := viper.GetString(config.Keys.Host)
+ requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, host)
recorder := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(recorder)
@@ -95,10 +99,10 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByHo
}
func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAccountDomain() {
- suite.config.Host = "gts.example.org"
- suite.config.AccountDomain = "example.org"
- suite.processor = processing.NewProcessor(suite.config, suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.emailSender)
- suite.webfingerModule = webfinger.New(suite.config, suite.processor).(*webfinger.Module)
+ viper.Set(config.Keys.Host, "gts.example.org")
+ viper.Set(config.Keys.AccountDomain, "example.org")
+ suite.processor = processing.NewProcessor(suite.tc, suite.federator, testrig.NewTestOauthServer(suite.db), testrig.NewTestMediaHandler(suite.db, suite.storage), suite.storage, testrig.NewTestTimelineManager(suite.db), suite.db, suite.emailSender)
+ suite.webfingerModule = webfinger.New(suite.processor).(*webfinger.Module)
targetAccount := accountDomainAccount()
if err := suite.db.Put(context.Background(), targetAccount); err != nil {
@@ -106,7 +110,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithDifferentAccountDomainByAc
}
// setup request
- requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, suite.config.AccountDomain)
+ accountDomain := viper.GetString(config.Keys.AccountDomain)
+ requestPath := fmt.Sprintf("/%s?resource=acct:%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, accountDomain)
recorder := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(recorder)
@@ -130,7 +135,8 @@ func (suite *WebfingerGetTestSuite) TestFingerUserWithoutAcct() {
targetAccount := suite.testAccounts["local_account_1"]
// setup request -- leave out the 'acct:' prefix, which is prettymuch what pixelfed currently does
- requestPath := fmt.Sprintf("/%s?resource=%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, suite.config.Host)
+ host := viper.GetString(config.Keys.Host)
+ requestPath := fmt.Sprintf("/%s?resource=%s@%s", webfinger.WebfingerBasePath, targetAccount.Username, host)
recorder := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(recorder)
diff --git a/internal/api/security/security.go b/internal/api/security/security.go
index 0379b2d53..1e55d5bc5 100644
--- a/internal/api/security/security.go
+++ b/internal/api/security/security.go
@@ -22,7 +22,6 @@ import (
"net/http"
"github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/router"
@@ -32,15 +31,13 @@ const robotsPath = "/robots.txt"
// Module implements the ClientAPIModule interface for security middleware
type Module struct {
- config *config.Config
db db.DB
server oauth.Server
}
// New returns a new security module
-func New(config *config.Config, db db.DB, server oauth.Server) api.ClientModule {
+func New(db db.DB, server oauth.Server) api.ClientModule {
return &Module{
- config: config,
db: db,
server: server,
}