gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

routersession_test.go (3010B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package validate_test
     19 
     20 import (
     21 	"testing"
     22 
     23 	"github.com/stretchr/testify/suite"
     24 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     25 	"github.com/superseriousbusiness/gotosocial/internal/validate"
     26 )
     27 
     28 func happyRouterSession() *gtsmodel.RouterSession {
     29 	return &gtsmodel.RouterSession{
     30 		ID:    "01FE91RJR88PSEEE30EV35QR8N",
     31 		Auth:  []byte("12345678901234567890123456789012"),
     32 		Crypt: []byte("12345678901234567890123456789012"),
     33 	}
     34 }
     35 
     36 type RouterSessionValidateTestSuite struct {
     37 	suite.Suite
     38 }
     39 
     40 func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionHappyPath() {
     41 	// no problem here
     42 	r := happyRouterSession()
     43 	err := validate.Struct(r)
     44 	suite.NoError(err)
     45 }
     46 
     47 func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionAuth() {
     48 	r := happyRouterSession()
     49 
     50 	// remove auth struct
     51 	r.Auth = nil
     52 	err := validate.Struct(r)
     53 	suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'required' tag")
     54 
     55 	// auth bytes too long
     56 	r.Auth = []byte("1234567890123456789012345678901234567890")
     57 	err = validate.Struct(r)
     58 	suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'len' tag")
     59 
     60 	// auth bytes too short
     61 	r.Auth = []byte("12345678901")
     62 	err = validate.Struct(r)
     63 	suite.EqualError(err, "Key: 'RouterSession.Auth' Error:Field validation for 'Auth' failed on the 'len' tag")
     64 }
     65 
     66 func (suite *RouterSessionValidateTestSuite) TestValidateRouterSessionCrypt() {
     67 	r := happyRouterSession()
     68 
     69 	// remove crypt struct
     70 	r.Crypt = nil
     71 	err := validate.Struct(r)
     72 	suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'required' tag")
     73 
     74 	// crypt bytes too long
     75 	r.Crypt = []byte("1234567890123456789012345678901234567890")
     76 	err = validate.Struct(r)
     77 	suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'len' tag")
     78 
     79 	// crypt bytes too short
     80 	r.Crypt = []byte("12345678901")
     81 	err = validate.Struct(r)
     82 	suite.EqualError(err, "Key: 'RouterSession.Crypt' Error:Field validation for 'Crypt' failed on the 'len' tag")
     83 }
     84 
     85 func TestRouterSessionValidateTestSuite(t *testing.T) {
     86 	suite.Run(t, new(RouterSessionValidateTestSuite))
     87 }