mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 09:46:15 -06:00
more big changes
This commit is contained in:
parent
b9746a30f3
commit
4e054233da
71 changed files with 640 additions and 405 deletions
|
|
@ -79,7 +79,7 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateCredentialsPATCHHandler()
|
|||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedToken, oauth.TokenToOauthToken(suite.testTokens["local_account_1"]))
|
||||
ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(suite.testTokens["local_account_1"]))
|
||||
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
|
||||
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
|
||||
ctx.Request = httptest.NewRequest(http.MethodPatch, fmt.Sprintf("http://localhost:8080/%s", account.UpdateCredentialsPath), bytes.NewReader(requestBody.Bytes())) // the endpoint we're hitting
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import (
|
|||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/pg"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
|
@ -104,7 +104,7 @@ func (suite *AuthTestSuite) SetupTest() {
|
|||
|
||||
log := logrus.New()
|
||||
log.SetLevel(logrus.TraceLevel)
|
||||
db, err := pg.NewPostgresService(context.Background(), suite.config, log)
|
||||
db, err := bundb.NewBunDBService(context.Background(), suite.config, log)
|
||||
if err != nil {
|
||||
logrus.Panicf("error creating database connection: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,20 +80,15 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
// we can also use the userid of the user to fetch their username from the db to greet them nicely <3
|
||||
user := >smodel.User{
|
||||
ID: userID,
|
||||
}
|
||||
user := >smodel.User{}
|
||||
if err := m.db.GetByID(c.Request.Context(), user.ID, user); err != nil {
|
||||
m.clearSession(s)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
acct := >smodel.Account{
|
||||
ID: user.AccountID,
|
||||
}
|
||||
|
||||
if err := m.db.GetByID(c.Request.Context(), acct.ID, acct); err != nil {
|
||||
acct, err := m.db.GetAccountByID(c.Request.Context(), user.AccountID)
|
||||
if err != nil {
|
||||
m.clearSession(s)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ func (m *Module) OauthTokenMiddleware(c *gin.Context) {
|
|||
c.Set(oauth.SessionAuthorizedUser, user)
|
||||
l.Tracef("set gin context %s to %+v", oauth.SessionAuthorizedUser, user)
|
||||
|
||||
acct := >smodel.Account{}
|
||||
if err := m.db.GetByID(c.Request.Context(), user.AccountID, acct); err != nil || acct == nil {
|
||||
acct, err := m.db.GetAccountByID(c.Request.Context(), user.AccountID)
|
||||
if err != nil || acct == nil {
|
||||
l.Warnf("no account found for validated user %s", uid)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func (suite *MediaCreateTestSuite) TestStatusCreatePOSTImageHandlerSuccessful()
|
|||
|
||||
// set up the context for the request
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (suite *StatusBoostTestSuite) TearDownTest() {
|
|||
func (suite *StatusBoostTestSuite) TestPostBoost() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["admin_account_status_1"]
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ func (suite *StatusBoostTestSuite) TestPostBoost() {
|
|||
func (suite *StatusBoostTestSuite) TestPostUnboostable() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["local_account_2_status_4"]
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ func (suite *StatusBoostTestSuite) TestPostUnboostable() {
|
|||
func (suite *StatusBoostTestSuite) TestPostNotVisible() {
|
||||
|
||||
t := suite.testTokens["local_account_2"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["local_account_1_status_3"] // this is a mutual only status and these accounts aren't mutuals
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ https://docs.gotosocial.org/en/latest/user_guide/posts/#links
|
|||
func (suite *StatusCreateTestSuite) TestPostNewStatus() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
@ -137,7 +137,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatus() {
|
|||
func (suite *StatusCreateTestSuite) TestPostAnotherNewStatus() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
@ -172,7 +172,7 @@ func (suite *StatusCreateTestSuite) TestPostAnotherNewStatus() {
|
|||
func (suite *StatusCreateTestSuite) TestPostNewStatusWithEmoji() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
@ -213,7 +213,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithEmoji() {
|
|||
// Try to reply to a status that doesn't exist
|
||||
func (suite *StatusCreateTestSuite) TestReplyToNonexistentStatus() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
@ -244,7 +244,7 @@ func (suite *StatusCreateTestSuite) TestReplyToNonexistentStatus() {
|
|||
// Post a reply to the status of a local user that allows replies.
|
||||
func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// setup
|
||||
recorder := httptest.NewRecorder()
|
||||
|
|
@ -284,7 +284,7 @@ func (suite *StatusCreateTestSuite) TestReplyToLocalStatus() {
|
|||
// Take a media file which is currently not associated with a status, and attach it to a new status.
|
||||
func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() {
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
attachment := suite.testAttachments["local_account_1_unattached_1"]
|
||||
|
||||
|
|
@ -323,8 +323,7 @@ func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() {
|
|||
assert.Len(suite.T(), statusResponse.MediaAttachments, 1)
|
||||
|
||||
// get the updated media attachment from the database
|
||||
gtsAttachment := >smodel.MediaAttachment{}
|
||||
err = suite.db.GetByID(context.Background(), statusResponse.MediaAttachments[0].ID, gtsAttachment)
|
||||
gtsAttachment, err := suite.db.GetAttachmentByID(context.Background(), statusResponse.MediaAttachments[0].ID)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
// convert it to a masto attachment
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func (suite *StatusFaveTestSuite) TearDownTest() {
|
|||
func (suite *StatusFaveTestSuite) TestPostFave() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["admin_account_status_2"]
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ func (suite *StatusFaveTestSuite) TestPostFave() {
|
|||
func (suite *StatusFaveTestSuite) TestPostUnfaveable() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["local_account_2_status_3"] // this one is unlikeable and unreplyable
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func (suite *StatusFavedByTestSuite) TearDownTest() {
|
|||
|
||||
func (suite *StatusFavedByTestSuite) TestGetFavedBy() {
|
||||
t := suite.testTokens["local_account_2"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
targetStatus := suite.testStatuses["admin_account_status_1"] // this status is faved by local_account_1
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func (suite *StatusUnfaveTestSuite) TearDownTest() {
|
|||
func (suite *StatusUnfaveTestSuite) TestPostUnfave() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// this is the status we wanna unfave: in the testrig it's already faved by this account
|
||||
targetStatus := suite.testStatuses["admin_account_status_1"]
|
||||
|
|
@ -120,7 +120,7 @@ func (suite *StatusUnfaveTestSuite) TestPostUnfave() {
|
|||
func (suite *StatusUnfaveTestSuite) TestPostAlreadyNotFaved() {
|
||||
|
||||
t := suite.testTokens["local_account_1"]
|
||||
oauthToken := oauth.TokenToOauthToken(t)
|
||||
oauthToken := oauth.DBTokenToToken(t)
|
||||
|
||||
// this is the status we wanna unfave: in the testrig it's not faved by this account
|
||||
targetStatus := suite.testStatuses["admin_account_status_2"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue