mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-05 20:59:31 -06:00
Updates....
This commit is contained in:
parent
d89d3b0c63
commit
68f3ba03b2
14 changed files with 128 additions and 316 deletions
|
|
@ -16,7 +16,6 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package apimodule is basically a wrapper for a lot of modules (in subdirectories) that satisfy the ClientAPIModule interface.
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
|
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/message"
|
"github.com/superseriousbusiness/gotosocial/internal/message"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
type AccountStandardTestSuite struct {
|
type AccountStandardTestSuite struct {
|
||||||
// standard suite interfaces
|
// standard suite interfaces
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
@ -19,6 +22,8 @@ type AccountStandardTestSuite struct {
|
||||||
db db.DB
|
db db.DB
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
tc typeutils.TypeConverter
|
tc typeutils.TypeConverter
|
||||||
|
storage storage.Storage
|
||||||
|
federator federation.Federator
|
||||||
processor message.Processor
|
processor message.Processor
|
||||||
|
|
||||||
// standard suite models
|
// standard suite models
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ package account_test
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (suite *AccountCreateTestSuite) SetupSuite() {
|
// func (suite *AccountCreateTestSuite) SetupSuite() {
|
||||||
// testrig.StandardDBSetup(suite.db)
|
|
||||||
// suite.testTokens = testrig.NewTestTokens()
|
// suite.testTokens = testrig.NewTestTokens()
|
||||||
// suite.testClients = testrig.NewTestClients()
|
// suite.testClients = testrig.NewTestClients()
|
||||||
// suite.testApplications = testrig.NewTestApplications()
|
// suite.testApplications = testrig.NewTestApplications()
|
||||||
|
|
@ -61,13 +60,18 @@ package account_test
|
||||||
// func (suite *AccountCreateTestSuite) SetupTest() {
|
// func (suite *AccountCreateTestSuite) SetupTest() {
|
||||||
// suite.config = testrig.NewTestConfig()
|
// suite.config = testrig.NewTestConfig()
|
||||||
// suite.db = testrig.NewTestDB()
|
// suite.db = testrig.NewTestDB()
|
||||||
|
// suite.storage = testrig.NewTestStorage()
|
||||||
// suite.log = testrig.NewTestLog()
|
// suite.log = testrig.NewTestLog()
|
||||||
// suite.processor = testrig.NewTestProcessor(suite.db)
|
// suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil)))
|
||||||
|
// suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
|
||||||
// suite.accountModule = account.New(suite.config, suite.processor, suite.log).(*account.Module)
|
// suite.accountModule = account.New(suite.config, suite.processor, suite.log).(*account.Module)
|
||||||
|
// testrig.StandardDBSetup(suite.db)
|
||||||
|
// testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (suite *AccountCreateTestSuite) TearDownTest() {
|
// func (suite *AccountCreateTestSuite) TearDownTest() {
|
||||||
// testrig.StandardDBTeardown(suite.db)
|
// testrig.StandardDBTeardown(suite.db)
|
||||||
|
// testrig.StandardStorageTeardown(suite.storage)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// // TestAccountCreatePOSTHandlerSuccessful checks the happy path for an account creation request: all the fields provided are valid,
|
// // TestAccountCreatePOSTHandlerSuccessful checks the happy path for an account creation request: all the fields provided are valid,
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
acctSensitive, err := m.processor.AccountGet(authed, authed.Account.ID)
|
acctSensitive, err := m.processor.AccountUpdate(authed, form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Debugf("could not update account: %s", err)
|
l.Debugf("could not update account: %s", err)
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
|
|
||||||
|
|
@ -1,303 +1,106 @@
|
||||||
// /*
|
/*
|
||||||
// GoToSocial
|
GoToSocial
|
||||||
// Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Affero General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// */
|
*/
|
||||||
|
|
||||||
package account_test
|
package account_test
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "bytes"
|
"bytes"
|
||||||
// "context"
|
"fmt"
|
||||||
// "fmt"
|
"io/ioutil"
|
||||||
// "io"
|
"net/http"
|
||||||
// "mime/multipart"
|
"net/http/httptest"
|
||||||
// "net/http"
|
"testing"
|
||||||
// "net/http/httptest"
|
|
||||||
// "net/url"
|
|
||||||
// "os"
|
|
||||||
// "testing"
|
|
||||||
// "time"
|
|
||||||
|
|
||||||
// "github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
// "github.com/google/uuid"
|
"github.com/stretchr/testify/assert"
|
||||||
// "github.com/sirupsen/logrus"
|
"github.com/stretchr/testify/suite"
|
||||||
// "github.com/stretchr/testify/assert"
|
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
|
||||||
// "github.com/stretchr/testify/mock"
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||||
// "github.com/stretchr/testify/suite"
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/api/client/account"
|
)
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/config"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/db"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/media"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/oauth"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/storage"
|
|
||||||
// "github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
|
||||||
// "github.com/superseriousbusiness/oauth2/v4"
|
|
||||||
// "github.com/superseriousbusiness/oauth2/v4/models"
|
|
||||||
// oauthmodels "github.com/superseriousbusiness/oauth2/v4/models"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// type AccountUpdateTestSuite struct {
|
type AccountUpdateTestSuite struct {
|
||||||
// suite.Suite
|
AccountStandardTestSuite
|
||||||
// config *config.Config
|
}
|
||||||
// log *logrus.Logger
|
|
||||||
// testAccountLocal *gtsmodel.Account
|
|
||||||
// testApplication *gtsmodel.Application
|
|
||||||
// testToken oauth2.TokenInfo
|
|
||||||
// mockOauthServer *oauth.MockServer
|
|
||||||
// mockStorage *storage.MockStorage
|
|
||||||
// mediaHandler media.Handler
|
|
||||||
// mastoConverter typeutils.TypeConverter
|
|
||||||
// db db.DB
|
|
||||||
// accountModule *account.Module
|
|
||||||
// newUserFormHappyPath url.Values
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*
|
func (suite *AccountUpdateTestSuite) SetupSuite() {
|
||||||
// TEST INFRASTRUCTURE
|
suite.testTokens = testrig.NewTestTokens()
|
||||||
// */
|
suite.testClients = testrig.NewTestClients()
|
||||||
|
suite.testApplications = testrig.NewTestApplications()
|
||||||
|
suite.testUsers = testrig.NewTestUsers()
|
||||||
|
suite.testAccounts = testrig.NewTestAccounts()
|
||||||
|
suite.testAttachments = testrig.NewTestAttachments()
|
||||||
|
suite.testStatuses = testrig.NewTestStatuses()
|
||||||
|
}
|
||||||
|
|
||||||
// // SetupSuite sets some variables on the suite that we can use as consts (more or less) throughout
|
func (suite *AccountUpdateTestSuite) SetupTest() {
|
||||||
// func (suite *AccountUpdateTestSuite) SetupSuite() {
|
suite.config = testrig.NewTestConfig()
|
||||||
// // some of our subsequent entities need a log so create this here
|
suite.db = testrig.NewTestDB()
|
||||||
// log := logrus.New()
|
suite.storage = testrig.NewTestStorage()
|
||||||
// log.SetLevel(logrus.TraceLevel)
|
suite.log = testrig.NewTestLog()
|
||||||
// suite.log = log
|
suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil)))
|
||||||
|
suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator)
|
||||||
|
suite.accountModule = account.New(suite.config, suite.processor, suite.log).(*account.Module)
|
||||||
|
testrig.StandardDBSetup(suite.db)
|
||||||
|
testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
|
||||||
|
}
|
||||||
|
|
||||||
// suite.testAccountLocal = >smodel.Account{
|
func (suite *AccountUpdateTestSuite) TearDownTest() {
|
||||||
// ID: uuid.NewString(),
|
testrig.StandardDBTeardown(suite.db)
|
||||||
// Username: "test_user",
|
testrig.StandardStorageTeardown(suite.storage)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // can use this test application throughout
|
func (suite *AccountUpdateTestSuite) TestAccountUpdateCredentialsPATCHHandler() {
|
||||||
// suite.testApplication = >smodel.Application{
|
|
||||||
// ID: "weeweeeeeeeeeeeeee",
|
|
||||||
// Name: "a test application",
|
|
||||||
// Website: "https://some-application-website.com",
|
|
||||||
// RedirectURI: "http://localhost:8080",
|
|
||||||
// ClientID: "a-known-client-id",
|
|
||||||
// ClientSecret: "some-secret",
|
|
||||||
// Scopes: "read",
|
|
||||||
// VapidKey: "aaaaaa-aaaaaaaa-aaaaaaaaaaa",
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // can use this test token throughout
|
requestBody, w, err := testrig.CreateMultipartFormData("header", "../../../../testrig/media/test-jpeg.jpg", map[string]string{
|
||||||
// suite.testToken = &oauthmodels.Token{
|
"display_name": "updated zork display name!!!",
|
||||||
// ClientID: "a-known-client-id",
|
"locked": "true",
|
||||||
// RedirectURI: "http://localhost:8080",
|
})
|
||||||
// Scope: "read",
|
if err != nil {
|
||||||
// Code: "123456789",
|
panic(err)
|
||||||
// CodeCreateAt: time.Now(),
|
}
|
||||||
// CodeExpiresIn: time.Duration(10 * time.Minute),
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Direct config to local postgres instance
|
// setup
|
||||||
// c := config.Empty()
|
recorder := httptest.NewRecorder()
|
||||||
// c.Protocol = "http"
|
ctx, _ := gin.CreateTestContext(recorder)
|
||||||
// c.Host = "localhost"
|
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
|
||||||
// c.DBConfig = &config.DBConfig{
|
ctx.Set(oauth.SessionAuthorizedToken, oauth.TokenToOauthToken(suite.testTokens["local_account_1"]))
|
||||||
// Type: "postgres",
|
ctx.Request = httptest.NewRequest(http.MethodPatch, fmt.Sprintf("http://localhost:8080/%s", account.UpdateCredentialsPath), bytes.NewReader(requestBody.Bytes())) // the endpoint we're hitting
|
||||||
// Address: "localhost",
|
ctx.Request.Header.Set("Content-Type", w.FormDataContentType())
|
||||||
// Port: 5432,
|
suite.accountModule.AccountUpdateCredentialsPATCHHandler(ctx)
|
||||||
// User: "postgres",
|
|
||||||
// Password: "postgres",
|
|
||||||
// Database: "postgres",
|
|
||||||
// ApplicationName: "gotosocial",
|
|
||||||
// }
|
|
||||||
// c.MediaConfig = &config.MediaConfig{
|
|
||||||
// MaxImageSize: 2 << 20,
|
|
||||||
// }
|
|
||||||
// c.StorageConfig = &config.StorageConfig{
|
|
||||||
// Backend: "local",
|
|
||||||
// BasePath: "/tmp",
|
|
||||||
// ServeProtocol: "http",
|
|
||||||
// ServeHost: "localhost",
|
|
||||||
// ServeBasePath: "/fileserver/media",
|
|
||||||
// }
|
|
||||||
// suite.config = c
|
|
||||||
|
|
||||||
// // use an actual database for this, because it's just easier than mocking one out
|
// check response
|
||||||
// database, err := db.NewPostgresService(context.Background(), c, log)
|
|
||||||
// if err != nil {
|
|
||||||
// suite.FailNow(err.Error())
|
|
||||||
// }
|
|
||||||
// suite.db = database
|
|
||||||
|
|
||||||
// // we need to mock the oauth server because account creation needs it to create a new token
|
// 1. we should have OK because our request was valid
|
||||||
// suite.mockOauthServer = &oauth.MockServer{}
|
suite.EqualValues(http.StatusOK, recorder.Code)
|
||||||
// suite.mockOauthServer.On("GenerateUserAccessToken", suite.testToken, suite.testApplication.ClientSecret, mock.AnythingOfType("string")).Run(func(args mock.Arguments) {
|
|
||||||
// l := suite.log.WithField("func", "GenerateUserAccessToken")
|
|
||||||
// token := args.Get(0).(oauth2.TokenInfo)
|
|
||||||
// l.Infof("received token %+v", token)
|
|
||||||
// clientSecret := args.Get(1).(string)
|
|
||||||
// l.Infof("received clientSecret %+v", clientSecret)
|
|
||||||
// userID := args.Get(2).(string)
|
|
||||||
// l.Infof("received userID %+v", userID)
|
|
||||||
// }).Return(&models.Token{
|
|
||||||
// Code: "we're authorized now!",
|
|
||||||
// }, nil)
|
|
||||||
|
|
||||||
// suite.mockStorage = &storage.MockStorage{}
|
// 2. we should have no error message in the result body
|
||||||
// // We don't need storage to do anything for these tests, so just simulate a success and do nothing -- we won't need to return anything from storage
|
result := recorder.Result()
|
||||||
// suite.mockStorage.On("StoreFileAt", mock.AnythingOfType("string"), mock.AnythingOfType("[]uint8")).Return(nil)
|
defer result.Body.Close()
|
||||||
|
|
||||||
// // set a media handler because some handlers (eg update credentials) need to upload media (new header/avatar)
|
b, err := ioutil.ReadAll(result.Body)
|
||||||
// suite.mediaHandler = media.New(suite.config, suite.db, suite.mockStorage, log)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
// suite.mastoConverter = typeutils.NewConverter(suite.config, suite.db)
|
fmt.Println(string(b))
|
||||||
|
|
||||||
// // and finally here's the thing we're actually testing!
|
// TODO write more assertions allee
|
||||||
// suite.accountModule = account.New(suite.config, suite.db, suite.mockOauthServer, suite.mediaHandler, suite.mastoConverter, suite.log).(*account.Module)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// func (suite *AccountUpdateTestSuite) TearDownSuite() {
|
func TestAccountUpdateTestSuite(t *testing.T) {
|
||||||
// if err := suite.db.Stop(context.Background()); err != nil {
|
suite.Run(t, new(AccountUpdateTestSuite))
|
||||||
// logrus.Panicf("error closing db connection: %s", err)
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // SetupTest creates a db connection and creates necessary tables before each test
|
|
||||||
// func (suite *AccountUpdateTestSuite) SetupTest() {
|
|
||||||
// // create all the tables we might need in thie suite
|
|
||||||
// models := []interface{}{
|
|
||||||
// >smodel.User{},
|
|
||||||
// >smodel.Account{},
|
|
||||||
// >smodel.Follow{},
|
|
||||||
// >smodel.FollowRequest{},
|
|
||||||
// >smodel.Status{},
|
|
||||||
// >smodel.Application{},
|
|
||||||
// >smodel.EmailDomainBlock{},
|
|
||||||
// >smodel.MediaAttachment{},
|
|
||||||
// }
|
|
||||||
// for _, m := range models {
|
|
||||||
// if err := suite.db.CreateTable(m); err != nil {
|
|
||||||
// logrus.Panicf("db connection error: %s", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // form to submit for happy path account create requests -- this will be changed inside tests so it's better to set it before each test
|
|
||||||
// suite.newUserFormHappyPath = url.Values{
|
|
||||||
// "reason": []string{"a very good reason that's at least 40 characters i swear"},
|
|
||||||
// "username": []string{"test_user"},
|
|
||||||
// "email": []string{"user@example.org"},
|
|
||||||
// "password": []string{"very-strong-password"},
|
|
||||||
// "agreement": []string{"true"},
|
|
||||||
// "locale": []string{"en"},
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // same with accounts config
|
|
||||||
// suite.config.AccountsConfig = &config.AccountsConfig{
|
|
||||||
// OpenRegistration: true,
|
|
||||||
// RequireApproval: true,
|
|
||||||
// ReasonRequired: true,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // TearDownTest drops tables to make sure there's no data in the db
|
|
||||||
// func (suite *AccountUpdateTestSuite) TearDownTest() {
|
|
||||||
|
|
||||||
// // remove all the tables we might have used so it's clear for the next test
|
|
||||||
// models := []interface{}{
|
|
||||||
// >smodel.User{},
|
|
||||||
// >smodel.Account{},
|
|
||||||
// >smodel.Follow{},
|
|
||||||
// >smodel.FollowRequest{},
|
|
||||||
// >smodel.Status{},
|
|
||||||
// >smodel.Application{},
|
|
||||||
// >smodel.EmailDomainBlock{},
|
|
||||||
// >smodel.MediaAttachment{},
|
|
||||||
// }
|
|
||||||
// for _, m := range models {
|
|
||||||
// if err := suite.db.DropTable(m); err != nil {
|
|
||||||
// logrus.Panicf("error dropping table: %s", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*
|
|
||||||
// ACTUAL TESTS
|
|
||||||
// */
|
|
||||||
|
|
||||||
// /*
|
|
||||||
// TESTING: AccountUpdateCredentialsPATCHHandler
|
|
||||||
// */
|
|
||||||
|
|
||||||
// func (suite *AccountUpdateTestSuite) TestAccountUpdateCredentialsPATCHHandler() {
|
|
||||||
|
|
||||||
// // put test local account in db
|
|
||||||
// err := suite.db.Put(suite.testAccountLocal)
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// // attach avatar to request form
|
|
||||||
// avatarFile, err := os.Open("../../media/test/test-jpeg.jpg")
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
// body := &bytes.Buffer{}
|
|
||||||
// writer := multipart.NewWriter(body)
|
|
||||||
|
|
||||||
// avatarPart, err := writer.CreateFormFile("avatar", "test-jpeg.jpg")
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// _, err = io.Copy(avatarPart, avatarFile)
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// err = avatarFile.Close()
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// // set display name to a new value
|
|
||||||
// displayNamePart, err := writer.CreateFormField("display_name")
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// _, err = io.Copy(displayNamePart, bytes.NewBufferString("test_user_wohoah"))
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// // set locked to true
|
|
||||||
// lockedPart, err := writer.CreateFormField("locked")
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// _, err = io.Copy(lockedPart, bytes.NewBufferString("true"))
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// // close the request writer, the form is now prepared
|
|
||||||
// err = writer.Close()
|
|
||||||
// assert.NoError(suite.T(), err)
|
|
||||||
|
|
||||||
// // setup
|
|
||||||
// recorder := httptest.NewRecorder()
|
|
||||||
// ctx, _ := gin.CreateTestContext(recorder)
|
|
||||||
// ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccountLocal)
|
|
||||||
// ctx.Set(oauth.SessionAuthorizedToken, suite.testToken)
|
|
||||||
// ctx.Request = httptest.NewRequest(http.MethodPatch, fmt.Sprintf("http://localhost:8080/%s", account.UpdateCredentialsPath), body) // the endpoint we're hitting
|
|
||||||
// ctx.Request.Header.Set("Content-Type", writer.FormDataContentType())
|
|
||||||
// suite.accountModule.AccountUpdateCredentialsPATCHHandler(ctx)
|
|
||||||
|
|
||||||
// // check response
|
|
||||||
|
|
||||||
// // 1. we should have OK because our request was valid
|
|
||||||
// suite.EqualValues(http.StatusOK, recorder.Code)
|
|
||||||
|
|
||||||
// // 2. we should have an error message in the result body
|
|
||||||
// result := recorder.Result()
|
|
||||||
// defer result.Body.Close()
|
|
||||||
// // TODO: implement proper checks here
|
|
||||||
// //
|
|
||||||
// // b, err := ioutil.ReadAll(result.Body)
|
|
||||||
// // assert.NoError(suite.T(), err)
|
|
||||||
// // assert.Equal(suite.T(), `{"error":"not authorized"}`, string(b))
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestAccountUpdateTestSuite(t *testing.T) {
|
|
||||||
// suite.Run(t, new(AccountUpdateTestSuite))
|
|
||||||
// }
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
type StatusStandardTestSuite struct {
|
type StatusStandardTestSuite struct {
|
||||||
// standard suite interfaces
|
// standard suite interfaces
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
type UserStandardTestSuite struct {
|
type UserStandardTestSuite struct {
|
||||||
// standard suite interfaces
|
// standard suite interfaces
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
|
||||||
|
|
@ -32,28 +32,28 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MediaSize describes the *size* of a piece of media
|
// Size describes the *size* of a piece of media
|
||||||
type MediaSize string
|
type Size string
|
||||||
|
|
||||||
// MediaType describes the *type* of a piece of media
|
// Type describes the *type* of a piece of media
|
||||||
type MediaType string
|
type Type string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Small is the key for small/thumbnail versions of media
|
// Small is the key for small/thumbnail versions of media
|
||||||
Small MediaSize = "small"
|
Small Size = "small"
|
||||||
// Original is the key for original/fullsize versions of media and emoji
|
// Original is the key for original/fullsize versions of media and emoji
|
||||||
Original MediaSize = "original"
|
Original Size = "original"
|
||||||
// Static is the key for static (non-animated) versions of emoji
|
// Static is the key for static (non-animated) versions of emoji
|
||||||
Static MediaSize = "static"
|
Static Size = "static"
|
||||||
|
|
||||||
// Attachment is the key for media attachments
|
// Attachment is the key for media attachments
|
||||||
Attachment MediaType = "attachment"
|
Attachment Type = "attachment"
|
||||||
// Header is the key for profile header requests
|
// Header is the key for profile header requests
|
||||||
Header MediaType = "header"
|
Header Type = "header"
|
||||||
// Avatar is the key for profile avatar requests
|
// Avatar is the key for profile avatar requests
|
||||||
Avatar MediaType = "avatar"
|
Avatar Type = "avatar"
|
||||||
// Emoji is the key for emoji type requests
|
// Emoji is the key for emoji type requests
|
||||||
Emoji MediaType = "emoji"
|
Emoji Type = "emoji"
|
||||||
|
|
||||||
// EmojiMaxBytes is the maximum permitted bytes of an emoji upload (50kb)
|
// EmojiMaxBytes is the maximum permitted bytes of an emoji upload (50kb)
|
||||||
EmojiMaxBytes = 51200
|
EmojiMaxBytes = 51200
|
||||||
|
|
@ -64,7 +64,7 @@ type Handler interface {
|
||||||
// ProcessHeaderOrAvatar takes a new header image for an account, checks it out, removes exif data from it,
|
// ProcessHeaderOrAvatar takes a new header image for an account, checks it out, removes exif data from it,
|
||||||
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new image,
|
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new image,
|
||||||
// and then returns information to the caller about the new header.
|
// and then returns information to the caller about the new header.
|
||||||
ProcessHeaderOrAvatar(img []byte, accountID string, mediaType MediaType) (*gtsmodel.MediaAttachment, error)
|
ProcessHeaderOrAvatar(img []byte, accountID string, mediaType Type) (*gtsmodel.MediaAttachment, error)
|
||||||
|
|
||||||
// ProcessLocalAttachment takes a new attachment and the requesting account, checks it out, removes exif data from it,
|
// ProcessLocalAttachment takes a new attachment and the requesting account, checks it out, removes exif data from it,
|
||||||
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new media,
|
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new media,
|
||||||
|
|
@ -101,7 +101,7 @@ func New(config *config.Config, database db.DB, storage storage.Storage, log *lo
|
||||||
// ProcessHeaderOrAvatar takes a new header image for an account, checks it out, removes exif data from it,
|
// ProcessHeaderOrAvatar takes a new header image for an account, checks it out, removes exif data from it,
|
||||||
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new image,
|
// puts it in whatever storage backend we're using, sets the relevant fields in the database for the new image,
|
||||||
// and then returns information to the caller about the new header.
|
// and then returns information to the caller about the new header.
|
||||||
func (mh *mediaHandler) ProcessHeaderOrAvatar(attachment []byte, accountID string, mediaType MediaType) (*gtsmodel.MediaAttachment, error) {
|
func (mh *mediaHandler) ProcessHeaderOrAvatar(attachment []byte, accountID string, mediaType Type) (*gtsmodel.MediaAttachment, error) {
|
||||||
l := mh.log.WithField("func", "SetHeaderForAccountID")
|
l := mh.log.WithField("func", "SetHeaderForAccountID")
|
||||||
|
|
||||||
if mediaType != Header && mediaType != Avatar {
|
if mediaType != Header && mediaType != Avatar {
|
||||||
|
|
@ -394,7 +394,7 @@ func (mh *mediaHandler) processImageAttachment(data []byte, accountID string, co
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string, mediaType MediaType, accountID string) (*gtsmodel.MediaAttachment, error) {
|
func (mh *mediaHandler) processHeaderOrAvi(imageBytes []byte, contentType string, mediaType Type, accountID string) (*gtsmodel.MediaAttachment, error) {
|
||||||
var isHeader bool
|
var isHeader bool
|
||||||
var isAvatar bool
|
var isAvatar bool
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ const (
|
||||||
|
|
||||||
// MIMEVideo is the mime type for video
|
// MIMEVideo is the mime type for video
|
||||||
MIMEVideo = "video"
|
MIMEVideo = "video"
|
||||||
// MIMEmp4 is the mp4 video mime type
|
// MIMEMp4 is the mp4 video mime type
|
||||||
MIMEMp4 = "video/mp4"
|
MIMEMp4 = "video/mp4"
|
||||||
// MIMEMpeg is the mpeg video mime type
|
// MIMEMpeg is the mpeg video mime type
|
||||||
MIMEMpeg = "video/mpeg"
|
MIMEMpeg = "video/mpeg"
|
||||||
|
|
@ -307,8 +307,8 @@ type imageAndMeta struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMediaType converts s to a recognized MediaType, or returns an error if unrecognized
|
// ParseMediaType converts s to a recognized MediaType, or returns an error if unrecognized
|
||||||
func ParseMediaType(s string) (MediaType, error) {
|
func ParseMediaType(s string) (Type, error) {
|
||||||
switch MediaType(s) {
|
switch Type(s) {
|
||||||
case Attachment:
|
case Attachment:
|
||||||
return Attachment, nil
|
return Attachment, nil
|
||||||
case Header:
|
case Header:
|
||||||
|
|
@ -322,8 +322,8 @@ func ParseMediaType(s string) (MediaType, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMediaSize converts s to a recognized MediaSize, or returns an error if unrecognized
|
// ParseMediaSize converts s to a recognized MediaSize, or returns an error if unrecognized
|
||||||
func ParseMediaSize(s string) (MediaSize, error) {
|
func ParseMediaSize(s string) (Size, error) {
|
||||||
switch MediaSize(s) {
|
switch Size(s) {
|
||||||
case Small:
|
case Small:
|
||||||
return Small, nil
|
return Small, nil
|
||||||
case Original:
|
case Original:
|
||||||
|
|
|
||||||
|
|
@ -154,10 +154,6 @@ func (p *processor) AccountUpdate(authed *oauth.Auth, form *apimodel.UpdateCrede
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if form.FieldsAttributes != nil {
|
|
||||||
// // TODO: parse fields attributes nicely and update
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fetch the account with all updated values set
|
// fetch the account with all updated values set
|
||||||
updatedAccount := >smodel.Account{}
|
updatedAccount := >smodel.Account{}
|
||||||
if err := p.db.GetByID(authed.Account.ID, updatedAccount); err != nil {
|
if err := p.db.GetByID(authed.Account.ID, updatedAccount); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ type Processor interface {
|
||||||
AccountCreate(authed *oauth.Auth, form *apimodel.AccountCreateRequest) (*apimodel.Token, error)
|
AccountCreate(authed *oauth.Auth, form *apimodel.AccountCreateRequest) (*apimodel.Token, error)
|
||||||
// AccountGet processes the given request for account information.
|
// AccountGet processes the given request for account information.
|
||||||
AccountGet(authed *oauth.Auth, targetAccountID string) (*apimodel.Account, error)
|
AccountGet(authed *oauth.Auth, targetAccountID string) (*apimodel.Account, error)
|
||||||
|
// AccountUpdate processes the update of an account with the given form
|
||||||
|
AccountUpdate(authed *oauth.Auth, form *apimodel.UpdateCredentialsRequest) (*apimodel.Account, error)
|
||||||
|
|
||||||
// AppCreate processes the creation of a new API application
|
// AppCreate processes the creation of a new API application
|
||||||
AppCreate(authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, error)
|
AppCreate(authed *oauth.Auth, form *apimodel.ApplicationCreateRequest) (*apimodel.Application, error)
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ func (c *converter) ASRepresentationToAccount(accountable Accountable) (*gtsmode
|
||||||
uri := uriProp.GetIRI()
|
uri := uriProp.GetIRI()
|
||||||
|
|
||||||
acct := >smodel.Account{}
|
acct := >smodel.Account{}
|
||||||
if err := c.db.GetWhere("uri", uri.String(), acct); err == nil {
|
err := c.db.GetWhere("uri", uri.String(), acct)
|
||||||
|
if err == nil {
|
||||||
// we already know this account so we can skip generating it
|
// we already know this account so we can skip generating it
|
||||||
return acct, nil
|
return acct, nil
|
||||||
} else {
|
}
|
||||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||||
// we don't know the account and there's been a real error
|
// we don't know the account and there's been a real error
|
||||||
return nil, fmt.Errorf("error getting account with uri %s from the database: %s", uri.String(), err)
|
return nil, fmt.Errorf("error getting account with uri %s from the database: %s", uri.String(), err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we don't know the account so we need to generate it from the person -- at least we already have the URI!
|
// we don't know the account so we need to generate it from the person -- at least we already have the URI!
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint
|
||||||
type ConverterStandardTestSuite struct {
|
type ConverterStandardTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
||||||
aviURLStatic := avi.Thumbnail.URL
|
aviURLStatic := avi.Thumbnail.URL
|
||||||
|
|
||||||
header := >smodel.MediaAttachment{}
|
header := >smodel.MediaAttachment{}
|
||||||
if err := c.db.GetHeaderForAccountID(avi, a.ID); err != nil {
|
if err := c.db.GetHeaderForAccountID(header, a.ID); err != nil {
|
||||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||||
return nil, fmt.Errorf("error getting header: %s", err)
|
return nil, fmt.Errorf("error getting header: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue