diff options
| author | 2021-09-03 10:27:40 +0100 | |
|---|---|---|
| committer | 2021-09-03 10:27:40 +0100 | |
| commit | 25edd57eaf3eecf0b449a4dabb5b5fc5d6ae7687 (patch) | |
| tree | b6cffb65d46a07f59d5393a257973910d4116227 /internal/api/client | |
| parent | session name fix (#185) (diff) | |
| parent | review changes (diff) | |
| download | gotosocial-25edd57eaf3eecf0b449a4dabb5b5fc5d6ae7687.tar.xz | |
Merge pull request #186 from superseriousbusiness/struct_validation
Struct validation
Diffstat (limited to 'internal/api/client')
| -rw-r--r-- | internal/api/client/account/account_test.go | 5 | ||||
| -rw-r--r-- | internal/api/client/account/accountcreate.go | 12 | ||||
| -rw-r--r-- | internal/api/client/admin/emojicreate.go | 4 | ||||
| -rw-r--r-- | internal/api/client/auth/auth_test.go | 13 | ||||
| -rw-r--r-- | internal/api/client/auth/callback.go | 6 | ||||
| -rw-r--r-- | internal/api/client/fileserver/servefile_test.go | 4 | ||||
| -rw-r--r-- | internal/api/client/media/mediacreate_test.go | 4 | ||||
| -rw-r--r-- | internal/api/client/status/status_test.go | 5 | ||||
| -rw-r--r-- | internal/api/client/status/statuscreate.go | 4 | ||||
| -rw-r--r-- | internal/api/client/streaming/stream.go | 8 | 
10 files changed, 31 insertions, 34 deletions
| diff --git a/internal/api/client/account/account_test.go b/internal/api/client/account/account_test.go index 5e1959cc2..02817984b 100644 --- a/internal/api/client/account/account_test.go +++ b/internal/api/client/account/account_test.go @@ -9,7 +9,6 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/federation"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" -	"github.com/superseriousbusiness/gotosocial/internal/oauth"  	"github.com/superseriousbusiness/gotosocial/internal/processing"  	"github.com/superseriousbusiness/gotosocial/internal/typeutils"  ) @@ -27,8 +26,8 @@ type AccountStandardTestSuite struct {  	processor processing.Processor  	// standard suite models -	testTokens       map[string]*oauth.Token -	testClients      map[string]*oauth.Client +	testTokens       map[string]*gtsmodel.Token +	testClients      map[string]*gtsmodel.Client  	testApplications map[string]*gtsmodel.Application  	testUsers        map[string]*gtsmodel.User  	testAccounts     map[string]*gtsmodel.Account diff --git a/internal/api/client/account/accountcreate.go b/internal/api/client/account/accountcreate.go index a9d672f80..3fab1488f 100644 --- a/internal/api/client/account/accountcreate.go +++ b/internal/api/client/account/accountcreate.go @@ -27,7 +27,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/api/model"  	"github.com/superseriousbusiness/gotosocial/internal/config"  	"github.com/superseriousbusiness/gotosocial/internal/oauth" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/validate"  )  // AccountCreatePOSTHandler swagger:operation POST /api/v1/accounts accountCreate @@ -118,15 +118,15 @@ func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsC  		return errors.New("registration is not open for this server")  	} -	if err := util.ValidateUsername(form.Username); err != nil { +	if err := validate.Username(form.Username); err != nil {  		return err  	} -	if err := util.ValidateEmail(form.Email); err != nil { +	if err := validate.Email(form.Email); err != nil {  		return err  	} -	if err := util.ValidateNewPassword(form.Password); err != nil { +	if err := validate.NewPassword(form.Password); err != nil {  		return err  	} @@ -134,11 +134,11 @@ func validateCreateAccount(form *model.AccountCreateRequest, c *config.AccountsC  		return errors.New("agreement to terms and conditions not given")  	} -	if err := util.ValidateLanguage(form.Locale); err != nil { +	if err := validate.Language(form.Locale); err != nil {  		return err  	} -	if err := util.ValidateSignUpReason(form.Reason, c.ReasonRequired); err != nil { +	if err := validate.SignUpReason(form.Reason, c.ReasonRequired); err != nil {  		return err  	} diff --git a/internal/api/client/admin/emojicreate.go b/internal/api/client/admin/emojicreate.go index 859933b16..019298976 100644 --- a/internal/api/client/admin/emojicreate.go +++ b/internal/api/client/admin/emojicreate.go @@ -28,7 +28,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/api/model"  	"github.com/superseriousbusiness/gotosocial/internal/media"  	"github.com/superseriousbusiness/gotosocial/internal/oauth" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/validate"  )  // emojiCreateRequest swagger:operation POST /api/v1/admin/custom_emojis emojiCreate @@ -132,5 +132,5 @@ func validateCreateEmoji(form *model.EmojiCreateRequest) error {  		return fmt.Errorf("file size limit exceeded: limit is %d bytes but emoji was %d bytes", media.EmojiMaxBytes, form.Image.Size)  	} -	return util.ValidateEmojiShortcode(form.Shortcode) +	return validate.EmojiShortcode(form.Shortcode)  } diff --git a/internal/api/client/auth/auth_test.go b/internal/api/client/auth/auth_test.go index 3d5170f31..295c0e964 100644 --- a/internal/api/client/auth/auth_test.go +++ b/internal/api/client/auth/auth_test.go @@ -41,7 +41,7 @@ type AuthTestSuite struct {  	testAccount     *gtsmodel.Account  	testApplication *gtsmodel.Application  	testUser        *gtsmodel.User -	testClient      *oauth.Client +	testClient      *gtsmodel.Client  	config          *config.Config  } @@ -83,7 +83,7 @@ func (suite *AuthTestSuite) SetupSuite() {  		Email:             "user@example.org",  		AccountID:         acctID,  	} -	suite.testClient = &oauth.Client{ +	suite.testClient = >smodel.Client{  		ID:     "a-known-client-id",  		Secret: "some-secret",  		Domain: fmt.Sprintf("%s://%s", c.Protocol, c.Host), @@ -95,7 +95,6 @@ func (suite *AuthTestSuite) SetupSuite() {  		ClientID:     "a-known-client-id",  		ClientSecret: "some-secret",  		Scopes:       "read", -		VapidKey:     uuid.NewString(),  	}  } @@ -112,8 +111,8 @@ func (suite *AuthTestSuite) SetupTest() {  	suite.db = db  	models := []interface{}{ -		&oauth.Client{}, -		&oauth.Token{}, +		>smodel.Client{}, +		>smodel.Token{},  		>smodel.User{},  		>smodel.Account{},  		>smodel.Application{}, @@ -145,8 +144,8 @@ func (suite *AuthTestSuite) SetupTest() {  // TearDownTest drops the oauth_clients table and closes the pg connection after each test  func (suite *AuthTestSuite) TearDownTest() {  	models := []interface{}{ -		&oauth.Client{}, -		&oauth.Token{}, +		>smodel.Client{}, +		>smodel.Token{},  		>smodel.User{},  		>smodel.Account{},  		>smodel.Application{}, diff --git a/internal/api/client/auth/callback.go b/internal/api/client/auth/callback.go index c2fbfb486..322ba5fc9 100644 --- a/internal/api/client/auth/callback.go +++ b/internal/api/client/auth/callback.go @@ -33,7 +33,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"  	"github.com/superseriousbusiness/gotosocial/internal/oidc" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/validate"  )  // CallbackGETHandler parses a token from an external auth provider. @@ -153,7 +153,7 @@ func (m *Module) parseUserFromClaims(ctx context.Context, claims *oidc.Claims, i  	}  	// check if we can just use claims.Name as-is -	err = util.ValidateUsername(claims.Name) +	err = validate.Username(claims.Name)  	if err == nil {  		// the name we have on the claims is already a valid username  		username = claims.Name @@ -166,7 +166,7 @@ func (m *Module) parseUserFromClaims(ctx context.Context, claims *oidc.Claims, i  		// lowercase the whole thing  		lower := strings.ToLower(underscored)  		// see if this is valid.... -		if err := util.ValidateUsername(lower); err == nil { +		if err := validate.Username(lower); err == nil {  			// we managed to get a valid username  			username = lower  		} else { diff --git a/internal/api/client/fileserver/servefile_test.go b/internal/api/client/fileserver/servefile_test.go index 4eec3bae5..579bb9606 100644 --- a/internal/api/client/fileserver/servefile_test.go +++ b/internal/api/client/fileserver/servefile_test.go @@ -57,8 +57,8 @@ type ServeFileTestSuite struct {  	oauthServer  oauth.Server  	// standard suite models -	testTokens       map[string]*oauth.Token -	testClients      map[string]*oauth.Client +	testTokens       map[string]*gtsmodel.Token +	testClients      map[string]*gtsmodel.Client  	testApplications map[string]*gtsmodel.Application  	testUsers        map[string]*gtsmodel.User  	testAccounts     map[string]*gtsmodel.Account diff --git a/internal/api/client/media/mediacreate_test.go b/internal/api/client/media/mediacreate_test.go index 8433786e4..1b2c84cf9 100644 --- a/internal/api/client/media/mediacreate_test.go +++ b/internal/api/client/media/mediacreate_test.go @@ -60,8 +60,8 @@ type MediaCreateTestSuite struct {  	processor    processing.Processor  	// standard suite models -	testTokens       map[string]*oauth.Token -	testClients      map[string]*oauth.Client +	testTokens       map[string]*gtsmodel.Token +	testClients      map[string]*gtsmodel.Client  	testApplications map[string]*gtsmodel.Application  	testUsers        map[string]*gtsmodel.User  	testAccounts     map[string]*gtsmodel.Account diff --git a/internal/api/client/status/status_test.go b/internal/api/client/status/status_test.go index 563a23ce2..f9b4e3671 100644 --- a/internal/api/client/status/status_test.go +++ b/internal/api/client/status/status_test.go @@ -27,7 +27,6 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/db"  	"github.com/superseriousbusiness/gotosocial/internal/federation"  	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" -	"github.com/superseriousbusiness/gotosocial/internal/oauth"  	"github.com/superseriousbusiness/gotosocial/internal/processing"  	"github.com/superseriousbusiness/gotosocial/internal/typeutils"  ) @@ -45,8 +44,8 @@ type StatusStandardTestSuite struct {  	storage   blob.Storage  	// standard suite models -	testTokens       map[string]*oauth.Token -	testClients      map[string]*oauth.Client +	testTokens       map[string]*gtsmodel.Token +	testClients      map[string]*gtsmodel.Client  	testApplications map[string]*gtsmodel.Application  	testUsers        map[string]*gtsmodel.User  	testAccounts     map[string]*gtsmodel.Account diff --git a/internal/api/client/status/statuscreate.go b/internal/api/client/status/statuscreate.go index 09fc47b5b..c8ea019d2 100644 --- a/internal/api/client/status/statuscreate.go +++ b/internal/api/client/status/statuscreate.go @@ -27,7 +27,7 @@ import (  	"github.com/superseriousbusiness/gotosocial/internal/api/model"  	"github.com/superseriousbusiness/gotosocial/internal/config"  	"github.com/superseriousbusiness/gotosocial/internal/oauth" -	"github.com/superseriousbusiness/gotosocial/internal/util" +	"github.com/superseriousbusiness/gotosocial/internal/validate"  )  // StatusCreatePOSTHandler swagger:operation POST /api/v1/statuses statusCreate @@ -157,7 +157,7 @@ func validateCreateStatus(form *model.AdvancedStatusCreateForm, config *config.S  	// validate post language  	if form.Language != "" { -		if err := util.ValidateLanguage(form.Language); err != nil { +		if err := validate.Language(form.Language); err != nil {  			return err  		}  	} diff --git a/internal/api/client/streaming/stream.go b/internal/api/client/streaming/stream.go index fa210e8d8..4a9dcfe52 100644 --- a/internal/api/client/streaming/stream.go +++ b/internal/api/client/streaming/stream.go @@ -146,13 +146,13 @@ func (m *Module) StreamGETHandler(c *gin.Context) {  	}  	defer conn.Close() // whatever happens, when we leave this function we want to close the websocket connection -	// inform the processor that we have a new connection and want a stream for it -	stream, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType) +	// inform the processor that we have a new connection and want a s for it +	s, errWithCode := m.processor.OpenStreamForAccount(c.Request.Context(), account, streamType)  	if errWithCode != nil {  		c.JSON(errWithCode.Code(), errWithCode.Safe())  		return  	} -	defer close(stream.Hangup) // closing stream.Hangup indicates that we've finished with the connection (the client has gone), so we want to do this on exiting this handler +	defer close(s.Hangup) // closing stream.Hangup indicates that we've finished with the connection (the client has gone), so we want to do this on exiting this handler  	// spawn a new ticker for pinging the connection periodically  	t := time.NewTicker(30 * time.Second) @@ -161,7 +161,7 @@ func (m *Module) StreamGETHandler(c *gin.Context) {  sendLoop:  	for {  		select { -		case m := <-stream.Messages: +		case m := <-s.Messages:  			// we've got a streaming message!!  			l.Trace("received message from stream")  			if err := conn.WriteJSON(m); err != nil { | 
