mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 23:12:25 -05:00 
			
		
		
		
	fiddling about
This commit is contained in:
		
					parent
					
						
							
								b713ccac9f
							
						
					
				
			
			
				commit
				
					
						9a57dac5a1
					
				
			
		
					 17 changed files with 359 additions and 123 deletions
				
			
		|  | @ -35,6 +35,7 @@ import ( | |||
| func main() { | ||||
| 	flagNames := config.GetFlagNames() | ||||
| 	envNames := config.GetEnvNames() | ||||
| 	defaults := config.GetDefaults() | ||||
| 	app := &cli.App{ | ||||
| 		Usage: "a fediverse social media server", | ||||
| 		Flags: []cli.Flag{ | ||||
|  | @ -42,32 +43,32 @@ func main() { | |||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.LogLevel, | ||||
| 				Usage:   "Log level to run at: debug, info, warn, fatal", | ||||
| 				Value:   "info", | ||||
| 				EnvVars: []string{"GTS_LOG_LEVEL"}, | ||||
| 				Value:   defaults.LogLevel, | ||||
| 				EnvVars: []string{envNames.LogLevel}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.ApplicationName, | ||||
| 				Usage:   "Name of the application, used in various places internally", | ||||
| 				Value:   "gotosocial", | ||||
| 				Value:   defaults.ApplicationName, | ||||
| 				EnvVars: []string{envNames.ApplicationName}, | ||||
| 				Hidden:  true, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.ConfigPath, | ||||
| 				Usage:   "Path to a yaml file containing gotosocial configuration. Values set in this file will be overwritten by values set as env vars or arguments", | ||||
| 				Value:   "", | ||||
| 				Value:   defaults.ConfigPath, | ||||
| 				EnvVars: []string{envNames.ConfigPath}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.Host, | ||||
| 				Usage:   "Hostname to use for the server (eg., example.org, gotosocial.whatever.com)", | ||||
| 				Value:   "localhost", | ||||
| 				Value:   defaults.Host, | ||||
| 				EnvVars: []string{envNames.Host}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.Protocol, | ||||
| 				Usage:   "Protocol to use for the REST api of the server (only use http for debugging and tests!)", | ||||
| 				Value:   "https", | ||||
| 				Value:   defaults.Protocol, | ||||
| 				EnvVars: []string{envNames.Protocol}, | ||||
| 			}, | ||||
| 
 | ||||
|  | @ -75,36 +76,37 @@ func main() { | |||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.DbType, | ||||
| 				Usage:   "Database type: eg., postgres", | ||||
| 				Value:   "postgres", | ||||
| 				Value:   defaults.DbType, | ||||
| 				EnvVars: []string{envNames.DbType}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.DbAddress, | ||||
| 				Usage:   "Database ipv4 address or hostname", | ||||
| 				Value:   "localhost", | ||||
| 				Value:   defaults.DbAddress, | ||||
| 				EnvVars: []string{envNames.DbAddress}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.DbPort, | ||||
| 				Usage:   "Database port", | ||||
| 				Value:   5432, | ||||
| 				Value:   defaults.DbPort, | ||||
| 				EnvVars: []string{envNames.DbPort}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.DbUser, | ||||
| 				Usage:   "Database username", | ||||
| 				Value:   "postgres", | ||||
| 				Value:   defaults.DbUser, | ||||
| 				EnvVars: []string{envNames.DbUser}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.DbPassword, | ||||
| 				Usage:   "Database password", | ||||
| 				Value: defaults.DbPassword, | ||||
| 				EnvVars: []string{envNames.DbPassword}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.DbDatabase, | ||||
| 				Usage:   "Database name", | ||||
| 				Value:   "postgres", | ||||
| 				Value:   defaults.DbDatabase, | ||||
| 				EnvVars: []string{envNames.DbDatabase}, | ||||
| 			}, | ||||
| 
 | ||||
|  | @ -112,7 +114,7 @@ func main() { | |||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.TemplateBaseDir, | ||||
| 				Usage:   "Basedir for html templating files for rendering pages and composing emails.", | ||||
| 				Value:   "./web/template/", | ||||
| 				Value:   defaults.TemplateBaseDir, | ||||
| 				EnvVars: []string{envNames.TemplateBaseDir}, | ||||
| 			}, | ||||
| 
 | ||||
|  | @ -120,39 +122,45 @@ func main() { | |||
| 			&cli.BoolFlag{ | ||||
| 				Name:    flagNames.AccountsOpenRegistration, | ||||
| 				Usage:   "Allow anyone to submit an account signup request. If false, server will be invite-only.", | ||||
| 				Value:   true, | ||||
| 				Value:   defaults.AccountsOpenRegistration, | ||||
| 				EnvVars: []string{envNames.AccountsOpenRegistration}, | ||||
| 			}, | ||||
| 			&cli.BoolFlag{ | ||||
| 				Name:    flagNames.AccountsRequireApproval, | ||||
| 				Name:    flagNames.AccountsApprovalRequired, | ||||
| 				Usage:   "Do account signups require approval by an admin or moderator before user can log in? If false, new registrations will be automatically approved.", | ||||
| 				Value:   true, | ||||
| 				EnvVars: []string{envNames.AccountsRequireApproval}, | ||||
| 				Value:   defaults.AccountsRequireApproval, | ||||
| 				EnvVars: []string{envNames.AccountsApprovalRequired}, | ||||
| 			}, | ||||
| 			&cli.BoolFlag{ | ||||
| 				Name:    flagNames.AccountsReasonRequired, | ||||
| 				Usage:   "Do new account signups require a reason to be submitted on registration?", | ||||
| 				Value:   defaults.AccountsReasonRequired, | ||||
| 				EnvVars: []string{envNames.AccountsReasonRequired}, | ||||
| 			}, | ||||
| 
 | ||||
| 			// MEDIA FLAGS | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.MediaMaxImageSize, | ||||
| 				Usage:   "Max size of accepted images in bytes", | ||||
| 				Value:   1048576, // 1mb | ||||
| 				Value:   defaults.MediaMaxImageSize, | ||||
| 				EnvVars: []string{envNames.MediaMaxImageSize}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.MediaMaxVideoSize, | ||||
| 				Usage:   "Max size of accepted videos in bytes", | ||||
| 				Value:   5242880, // 5mb | ||||
| 				Value:   defaults.MediaMaxVideoSize, | ||||
| 				EnvVars: []string{envNames.MediaMaxVideoSize}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.MediaMinDescriptionChars, | ||||
| 				Usage:   "Min required chars for an image description", | ||||
| 				Value:   0, | ||||
| 				Value:   defaults.MediaMinDescriptionChars, | ||||
| 				EnvVars: []string{envNames.MediaMinDescriptionChars}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.MediaMaxDescriptionChars, | ||||
| 				Usage:   "Max permitted chars for an image description", | ||||
| 				Value:   500, | ||||
| 				Value:   defaults.MediaMaxDescriptionChars, | ||||
| 				EnvVars: []string{envNames.MediaMaxDescriptionChars}, | ||||
| 			}, | ||||
| 
 | ||||
|  | @ -160,31 +168,31 @@ func main() { | |||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.StorageBackend, | ||||
| 				Usage:   "Storage backend to use for media attachments", | ||||
| 				Value:   "local", | ||||
| 				Value:   defaults.StorageBackend, | ||||
| 				EnvVars: []string{envNames.StorageBackend}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.StorageBasePath, | ||||
| 				Usage:   "Full path to an already-created directory where gts should store/retrieve media files. Subfolders will be created within this dir.", | ||||
| 				Value:   "/gotosocial/storage/media", | ||||
| 				Value:   defaults.StorageBasePath, | ||||
| 				EnvVars: []string{envNames.StorageBasePath}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.StorageServeProtocol, | ||||
| 				Usage:   "Protocol to use for serving media attachments (use https if storage is local)", | ||||
| 				Value:   "https", | ||||
| 				Value:   defaults.StorageServeProtocol, | ||||
| 				EnvVars: []string{envNames.StorageServeProtocol}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.StorageServeHost, | ||||
| 				Usage:   "Hostname to serve media attachments from (use the same value as host if storage is local)", | ||||
| 				Value:   "localhost", | ||||
| 				Value:   defaults.StorageServeHost, | ||||
| 				EnvVars: []string{envNames.StorageServeHost}, | ||||
| 			}, | ||||
| 			&cli.StringFlag{ | ||||
| 				Name:    flagNames.StorageServeBasePath, | ||||
| 				Usage:   "Path to append to protocol and hostname to create the base path from which media files will be served (default will mostly be fine)", | ||||
| 				Value:   "/fileserver/media", | ||||
| 				Value:   defaults.StorageServeBasePath, | ||||
| 				EnvVars: []string{envNames.StorageServeBasePath}, | ||||
| 			}, | ||||
| 
 | ||||
|  | @ -192,31 +200,31 @@ func main() { | |||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.StatusesMaxChars, | ||||
| 				Usage:   "Max permitted characters for posted statuses", | ||||
| 				Value:   5000, | ||||
| 				Value:   defaults.StatusesMaxChars, | ||||
| 				EnvVars: []string{envNames.StatusesMaxChars}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.StatusesCWMaxChars, | ||||
| 				Usage:   "Max permitted characters for content/spoiler warnings on statuses", | ||||
| 				Value:   100, | ||||
| 				Value:   defaults.StatusesCWMaxChars, | ||||
| 				EnvVars: []string{envNames.StatusesCWMaxChars}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.StatusesPollMaxOptions, | ||||
| 				Usage:   "Max amount of options permitted on a poll", | ||||
| 				Value:   6, | ||||
| 				Value:   defaults.StatusesPollMaxOptions, | ||||
| 				EnvVars: []string{envNames.StatusesPollMaxOptions}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.StatusesPollOptionMaxChars, | ||||
| 				Usage:   "Max amount of characters for a poll option", | ||||
| 				Value:   50, | ||||
| 				Value:   defaults.StatusesPollOptionMaxChars, | ||||
| 				EnvVars: []string{envNames.StatusesPollOptionMaxChars}, | ||||
| 			}, | ||||
| 			&cli.IntFlag{ | ||||
| 				Name:    flagNames.StatusesMaxMediaFiles, | ||||
| 				Usage:   "Maximum number of media files/attachments per status", | ||||
| 				Value:   6, | ||||
| 				Value:   defaults.StatusesMaxMediaFiles, | ||||
| 				EnvVars: []string{envNames.StatusesMaxMediaFiles}, | ||||
| 			}, | ||||
| 		}, | ||||
|  |  | |||
|  | @ -55,39 +55,10 @@ func (suite *MediaCreateTestSuite) SetupSuite() { | |||
| 	suite.log = log | ||||
| 
 | ||||
| 	// Direct config to local postgres instance | ||||
| 	c := config.Empty() | ||||
| 	c.Protocol = "http" | ||||
| 	c.Host = "localhost" | ||||
| 	c.DBConfig = &config.DBConfig{ | ||||
| 		Type:            "postgres", | ||||
| 		Address:         "localhost", | ||||
| 		Port:            5432, | ||||
| 		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", | ||||
| 	} | ||||
| 	c.StatusesConfig = &config.StatusesConfig{ | ||||
| 		MaxChars:           500, | ||||
| 		CWMaxChars:         50, | ||||
| 		PollMaxOptions:     4, | ||||
| 		PollOptionMaxChars: 50, | ||||
| 		MaxMediaFiles:      4, | ||||
| 	} | ||||
| 	suite.config = c | ||||
| 	suite.config = testrig.NewTestConfig() | ||||
| 
 | ||||
| 	// use an actual database for this, because it's just easier than mocking one out | ||||
| 	database, err := db.New(context.Background(), c, log) | ||||
| 	database, err := db.New(context.Background(), suite.config, log) | ||||
| 	if err != nil { | ||||
| 		suite.FailNow(err.Error()) | ||||
| 	} | ||||
|  | @ -108,21 +79,17 @@ func (suite *MediaCreateTestSuite) TearDownSuite() { | |||
| } | ||||
| 
 | ||||
| func (suite *MediaCreateTestSuite) SetupTest() { | ||||
| 	if err := testrig.StandardDBSetup(suite.db); err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	suite.testTokens = testrig.TestTokens() | ||||
| 	suite.testClients = testrig.TestClients() | ||||
| 	suite.testApplications = testrig.TestApplications() | ||||
| 	suite.testUsers = testrig.TestUsers() | ||||
| 	suite.testAccounts = testrig.TestAccounts() | ||||
| 	testrig.StandardDBSetup(suite.db) | ||||
| 	suite.testTokens = testrig.NewTestTokens() | ||||
| 	suite.testClients = testrig.NewTestClients() | ||||
| 	suite.testApplications = testrig.NewTestApplications() | ||||
| 	suite.testUsers = testrig.NewTestUsers() | ||||
| 	suite.testAccounts = testrig.NewTestAccounts() | ||||
| } | ||||
| 
 | ||||
| // TearDownTest drops tables to make sure there's no data in the db | ||||
| func (suite *MediaCreateTestSuite) TearDownTest() { | ||||
| 	if err := testrig.StandardDBTeardown(suite.db); err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	testrig.StandardDBTeardown(suite.db) | ||||
| } | ||||
| 
 | ||||
| /* | ||||
|  |  | |||
|  | @ -129,21 +129,17 @@ func (suite *StatusCreateTestSuite) TearDownSuite() { | |||
| } | ||||
| 
 | ||||
| func (suite *StatusCreateTestSuite) SetupTest() { | ||||
| 	if err := testrig.StandardDBSetup(suite.db); err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	suite.testTokens = testrig.TestTokens() | ||||
| 	suite.testClients = testrig.TestClients() | ||||
| 	suite.testApplications = testrig.TestApplications() | ||||
| 	suite.testUsers = testrig.TestUsers() | ||||
| 	suite.testAccounts = testrig.TestAccounts() | ||||
| 	testrig.StandardDBSetup(suite.db) | ||||
| 	suite.testTokens = testrig.NewTestTokens() | ||||
| 	suite.testClients = testrig.NewTestClients() | ||||
| 	suite.testApplications = testrig.NewTestApplications() | ||||
| 	suite.testUsers = testrig.NewTestUsers() | ||||
| 	suite.testAccounts = testrig.NewTestAccounts() | ||||
| } | ||||
| 
 | ||||
| // TearDownTest drops tables to make sure there's no data in the db | ||||
| func (suite *StatusCreateTestSuite) TearDownTest() { | ||||
| 	if err := testrig.StandardDBTeardown(suite.db); err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	testrig.StandardDBTeardown(suite.db) | ||||
| } | ||||
| 
 | ||||
| /* | ||||
|  | @ -241,8 +237,8 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSucce | |||
| 	ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"]) | ||||
| 	ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080/%s", basePath), nil) // the endpoint we're hitting | ||||
| 	ctx.Request.Form = url.Values{ | ||||
| 		"status":         {fmt.Sprintf("hello @%s this reply should work!", testrig.TestAccounts()["local_account_2"].Username)}, | ||||
| 		"in_reply_to_id": {testrig.TestStatuses()["local_account_2_status_1"].ID}, | ||||
| 		"status":         {fmt.Sprintf("hello @%s this reply should work!", testrig.NewTestAccounts()["local_account_2"].Username)}, | ||||
| 		"in_reply_to_id": {testrig.NewTestStatuses()["local_account_2_status_1"].ID}, | ||||
| 	} | ||||
| 	suite.statusModule.statusCreatePOSTHandler(ctx) | ||||
| 
 | ||||
|  | @ -259,11 +255,11 @@ func (suite *StatusCreateTestSuite) TestStatusCreatePOSTHandlerReplyToLocalSucce | |||
| 	assert.NoError(suite.T(), err) | ||||
| 
 | ||||
| 	assert.Equal(suite.T(), "", statusReply.SpoilerText) | ||||
| 	assert.Equal(suite.T(), fmt.Sprintf("hello @%s this reply should work!", testrig.TestAccounts()["local_account_2"].Username), statusReply.Content) | ||||
| 	assert.Equal(suite.T(), fmt.Sprintf("hello @%s this reply should work!", testrig.NewTestAccounts()["local_account_2"].Username), statusReply.Content) | ||||
| 	assert.False(suite.T(), statusReply.Sensitive) | ||||
| 	assert.Equal(suite.T(), mastomodel.VisibilityPublic, statusReply.Visibility) | ||||
| 	assert.Equal(suite.T(), testrig.TestStatuses()["local_account_2_status_1"].ID, statusReply.InReplyToID) | ||||
| 	assert.Equal(suite.T(), testrig.TestAccounts()["local_account_2"].ID, statusReply.InReplyToAccountID) | ||||
| 	assert.Equal(suite.T(), testrig.NewTestStatuses()["local_account_2_status_1"].ID, statusReply.InReplyToID) | ||||
| 	assert.Equal(suite.T(), testrig.NewTestAccounts()["local_account_2"].ID, statusReply.InReplyToAccountID) | ||||
| 	assert.Len(suite.T(), statusReply.Mentions, 1) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -51,7 +51,7 @@ func FromFile(path string) (*Config, error) { | |||
| 	return Empty(), nil | ||||
| } | ||||
| 
 | ||||
| // Empty just returns an empty config | ||||
| // Empty just returns a new empty config | ||||
| func Empty() *Config { | ||||
| 	return &Config{ | ||||
| 		DBConfig:       &DBConfig{}, | ||||
|  | @ -63,6 +63,8 @@ func Empty() *Config { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // loadFromFile takes a path to a yaml file and attempts to load a Config object from it | ||||
| func loadFromFile(path string) (*Config, error) { | ||||
| 	bytes, err := os.ReadFile(path) | ||||
|  | @ -142,8 +144,8 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) { | |||
| 		c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration) | ||||
| 	} | ||||
| 
 | ||||
| 	if f.IsSet(fn.AccountsRequireApproval) { | ||||
| 		c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsRequireApproval) | ||||
| 	if f.IsSet(fn.AccountsApprovalRequired) { | ||||
| 		c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsApprovalRequired) | ||||
| 	} | ||||
| 
 | ||||
| 	// media flags | ||||
|  | @ -230,7 +232,8 @@ type Flags struct { | |||
| 	TemplateBaseDir string | ||||
| 
 | ||||
| 	AccountsOpenRegistration string | ||||
| 	AccountsRequireApproval  string | ||||
| 	AccountsApprovalRequired string | ||||
| 	AccountsReasonRequired   string | ||||
| 
 | ||||
| 	MediaMaxImageSize        string | ||||
| 	MediaMaxVideoSize        string | ||||
|  | @ -250,6 +253,44 @@ type Flags struct { | |||
| 	StatusesMaxMediaFiles      string | ||||
| } | ||||
| 
 | ||||
| type Defaults struct { | ||||
| 	LogLevel        string | ||||
| 	ApplicationName string | ||||
| 	ConfigPath      string | ||||
| 	Host            string | ||||
| 	Protocol        string | ||||
| 
 | ||||
| 	DbType     string | ||||
| 	DbAddress  string | ||||
| 	DbPort     int | ||||
| 	DbUser     string | ||||
| 	DbPassword string | ||||
| 	DbDatabase string | ||||
| 
 | ||||
| 	TemplateBaseDir string | ||||
| 
 | ||||
| 	AccountsOpenRegistration bool | ||||
| 	AccountsRequireApproval  bool | ||||
| 	AccountsReasonRequired   bool | ||||
| 
 | ||||
| 	MediaMaxImageSize        int | ||||
| 	MediaMaxVideoSize        int | ||||
| 	MediaMinDescriptionChars int | ||||
| 	MediaMaxDescriptionChars int | ||||
| 
 | ||||
| 	StorageBackend       string | ||||
| 	StorageBasePath      string | ||||
| 	StorageServeProtocol string | ||||
| 	StorageServeHost     string | ||||
| 	StorageServeBasePath string | ||||
| 
 | ||||
| 	StatusesMaxChars           int | ||||
| 	StatusesCWMaxChars         int | ||||
| 	StatusesPollMaxOptions     int | ||||
| 	StatusesPollOptionMaxChars int | ||||
| 	StatusesMaxMediaFiles      int | ||||
| } | ||||
| 
 | ||||
| // GetFlagNames returns a struct containing the names of the various flags used for | ||||
| // initializing and storing urfavecli flag variables. | ||||
| func GetFlagNames() Flags { | ||||
|  | @ -270,7 +311,8 @@ func GetFlagNames() Flags { | |||
| 		TemplateBaseDir: "template-basedir", | ||||
| 
 | ||||
| 		AccountsOpenRegistration: "accounts-open-registration", | ||||
| 		AccountsRequireApproval:  "accounts-require-approval", | ||||
| 		AccountsApprovalRequired: "accounts-approval-required", | ||||
| 		AccountsReasonRequired:   "accounts-reason-required", | ||||
| 
 | ||||
| 		MediaMaxImageSize:        "media-max-image-size", | ||||
| 		MediaMaxVideoSize:        "media-max-video-size", | ||||
|  | @ -311,7 +353,8 @@ func GetEnvNames() Flags { | |||
| 		TemplateBaseDir: "GTS_TEMPLATE_BASEDIR", | ||||
| 
 | ||||
| 		AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION", | ||||
| 		AccountsRequireApproval:  "GTS_ACCOUNTS_REQUIRE_APPROVAL", | ||||
| 		AccountsApprovalRequired: "GTS_ACCOUNTS_APPROVAL_REQUIRED", | ||||
| 		AccountsReasonRequired:   "GTS_ACCOUNTS_REASON_REQUIRED", | ||||
| 
 | ||||
| 		MediaMaxImageSize:        "GTS_MEDIA_MAX_IMAGE_SIZE", | ||||
| 		MediaMaxVideoSize:        "GTS_MEDIA_MAX_VIDEO_SIZE", | ||||
|  |  | |||
							
								
								
									
										177
									
								
								internal/config/default.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								internal/config/default.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,177 @@ | |||
| package config | ||||
| 
 | ||||
| // TestDefault returns a default config for testing | ||||
| func TestDefault() *Config { | ||||
| 	defaults := GetTestDefaults() | ||||
| 	return &Config{ | ||||
| 		LogLevel:        defaults.LogLevel, | ||||
| 		ApplicationName: defaults.ApplicationName, | ||||
| 		Host:            defaults.Host, | ||||
| 		Protocol:        defaults.Protocol, | ||||
| 		DBConfig: &DBConfig{ | ||||
| 			Type:            defaults.DbType, | ||||
| 			Address:         defaults.DbAddress, | ||||
| 			Port:            defaults.DbPort, | ||||
| 			User:            defaults.DbUser, | ||||
| 			Password:        defaults.DbPassword, | ||||
| 			Database:        defaults.DbDatabase, | ||||
| 			ApplicationName: defaults.ApplicationName, | ||||
| 		}, | ||||
| 		TemplateConfig: &TemplateConfig{ | ||||
| 			BaseDir: defaults.TemplateBaseDir, | ||||
| 		}, | ||||
| 		AccountsConfig: &AccountsConfig{ | ||||
| 			OpenRegistration: defaults.AccountsOpenRegistration, | ||||
| 			RequireApproval:  defaults.AccountsRequireApproval, | ||||
| 			ReasonRequired:   defaults.AccountsReasonRequired, | ||||
| 		}, | ||||
| 		MediaConfig: &MediaConfig{ | ||||
| 			MaxImageSize:        defaults.MediaMaxImageSize, | ||||
| 			MaxVideoSize:        defaults.MediaMaxVideoSize, | ||||
| 			MinDescriptionChars: defaults.MediaMinDescriptionChars, | ||||
| 			MaxDescriptionChars: defaults.MediaMaxDescriptionChars, | ||||
| 		}, | ||||
| 		StorageConfig: &StorageConfig{ | ||||
| 			Backend:       defaults.StorageBackend, | ||||
| 			BasePath:      defaults.StorageBasePath, | ||||
| 			ServeProtocol: defaults.StorageServeProtocol, | ||||
| 			ServeHost:     defaults.StorageServeHost, | ||||
| 			ServeBasePath: defaults.StorageServeBasePath, | ||||
| 		}, | ||||
| 		StatusesConfig: &StatusesConfig{ | ||||
| 			MaxChars:           defaults.StatusesMaxChars, | ||||
| 			CWMaxChars:         defaults.StatusesCWMaxChars, | ||||
| 			PollMaxOptions:     defaults.StatusesPollMaxOptions, | ||||
| 			PollOptionMaxChars: defaults.StatusesPollOptionMaxChars, | ||||
| 			MaxMediaFiles:      defaults.StatusesMaxMediaFiles, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // Default returns a config with all default values set | ||||
| func Default() *Config { | ||||
| 	defaults := GetDefaults() | ||||
| 	return &Config{ | ||||
| 		LogLevel:        defaults.LogLevel, | ||||
| 		ApplicationName: defaults.ApplicationName, | ||||
| 		Host:            defaults.Host, | ||||
| 		Protocol:        defaults.Protocol, | ||||
| 		DBConfig: &DBConfig{ | ||||
| 			Type:            defaults.DbType, | ||||
| 			Address:         defaults.DbAddress, | ||||
| 			Port:            defaults.DbPort, | ||||
| 			User:            defaults.DbUser, | ||||
| 			Password:        defaults.DbPassword, | ||||
| 			Database:        defaults.DbDatabase, | ||||
| 			ApplicationName: defaults.ApplicationName, | ||||
| 		}, | ||||
| 		TemplateConfig: &TemplateConfig{ | ||||
| 			BaseDir: defaults.TemplateBaseDir, | ||||
| 		}, | ||||
| 		AccountsConfig: &AccountsConfig{ | ||||
| 			OpenRegistration: defaults.AccountsOpenRegistration, | ||||
| 			RequireApproval:  defaults.AccountsRequireApproval, | ||||
| 			ReasonRequired:   defaults.AccountsReasonRequired, | ||||
| 		}, | ||||
| 		MediaConfig: &MediaConfig{ | ||||
| 			MaxImageSize:        defaults.MediaMaxImageSize, | ||||
| 			MaxVideoSize:        defaults.MediaMaxVideoSize, | ||||
| 			MinDescriptionChars: defaults.MediaMinDescriptionChars, | ||||
| 			MaxDescriptionChars: defaults.MediaMaxDescriptionChars, | ||||
| 		}, | ||||
| 		StorageConfig: &StorageConfig{ | ||||
| 			Backend:       defaults.StorageBackend, | ||||
| 			BasePath:      defaults.StorageBasePath, | ||||
| 			ServeProtocol: defaults.StorageServeProtocol, | ||||
| 			ServeHost:     defaults.StorageServeHost, | ||||
| 			ServeBasePath: defaults.StorageServeBasePath, | ||||
| 		}, | ||||
| 		StatusesConfig: &StatusesConfig{ | ||||
| 			MaxChars:           defaults.StatusesMaxChars, | ||||
| 			CWMaxChars:         defaults.StatusesCWMaxChars, | ||||
| 			PollMaxOptions:     defaults.StatusesPollMaxOptions, | ||||
| 			PollOptionMaxChars: defaults.StatusesPollOptionMaxChars, | ||||
| 			MaxMediaFiles:      defaults.StatusesMaxMediaFiles, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func GetDefaults() Defaults { | ||||
| 	return Defaults{ | ||||
| 		LogLevel:        "info", | ||||
| 		ApplicationName: "gotosocial", | ||||
| 		ConfigPath:      "", | ||||
| 		Host:            "", | ||||
| 		Protocol:        "https", | ||||
| 
 | ||||
| 		DbType:     "postgres", | ||||
| 		DbAddress:  "localhost", | ||||
| 		DbPort:     5432, | ||||
| 		DbUser:     "postgres", | ||||
| 		DbPassword: "postgres", | ||||
| 		DbDatabase: "postgres", | ||||
| 
 | ||||
| 		TemplateBaseDir: "./web/template/", | ||||
| 
 | ||||
| 		AccountsOpenRegistration: true, | ||||
| 		AccountsRequireApproval:  true, | ||||
| 		AccountsReasonRequired:   true, | ||||
| 
 | ||||
| 		MediaMaxImageSize:        1048576, //1mb | ||||
| 		MediaMaxVideoSize:        5242880, //5mb | ||||
| 		MediaMinDescriptionChars: 0, | ||||
| 		MediaMaxDescriptionChars: 500, | ||||
| 
 | ||||
| 		StorageBackend:       "local", | ||||
| 		StorageBasePath:      "/gotosocial/storage", | ||||
| 		StorageServeProtocol: "https", | ||||
| 		StorageServeHost:     "localhost", | ||||
| 		StorageServeBasePath: "/fileserver", | ||||
| 
 | ||||
| 		StatusesMaxChars:           5000, | ||||
| 		StatusesCWMaxChars:         100, | ||||
| 		StatusesPollMaxOptions:     6, | ||||
| 		StatusesPollOptionMaxChars: 50, | ||||
| 		StatusesMaxMediaFiles:      6, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func GetTestDefaults() Defaults { | ||||
| 	return Defaults{ | ||||
| 		LogLevel:        "trace", | ||||
| 		ApplicationName: "gotosocial", | ||||
| 		ConfigPath:      "", | ||||
| 		Host:            "localhost:8080", | ||||
| 		Protocol:        "http", | ||||
| 
 | ||||
| 		DbType:     "postgres", | ||||
| 		DbAddress:  "localhost", | ||||
| 		DbPort:     5432, | ||||
| 		DbUser:     "postgres", | ||||
| 		DbPassword: "postgres", | ||||
| 		DbDatabase: "postgres", | ||||
| 
 | ||||
| 		TemplateBaseDir: "./web/template/", | ||||
| 
 | ||||
| 		AccountsOpenRegistration: true, | ||||
| 		AccountsRequireApproval:  true, | ||||
| 		AccountsReasonRequired:   true, | ||||
| 
 | ||||
| 		MediaMaxImageSize:        1048576, //1mb | ||||
| 		MediaMaxVideoSize:        5242880, //5mb | ||||
| 		MediaMinDescriptionChars: 0, | ||||
| 		MediaMaxDescriptionChars: 500, | ||||
| 
 | ||||
| 		StorageBackend:       "local", | ||||
| 		StorageBasePath:      "/gotosocial/storage", | ||||
| 		StorageServeProtocol: "http", | ||||
| 		StorageServeHost:     "localhost:8080", | ||||
| 		StorageServeBasePath: "/fileserver", | ||||
| 
 | ||||
| 		StatusesMaxChars:           5000, | ||||
| 		StatusesCWMaxChars:         100, | ||||
| 		StatusesPollMaxOptions:     6, | ||||
| 		StatusesPollOptionMaxChars: 50, | ||||
| 		StatusesMaxMediaFiles:      6, | ||||
| 	} | ||||
| } | ||||
|  | @ -139,7 +139,7 @@ func (suite *MediaTestSuite) TearDownTest() { | |||
| 
 | ||||
| func (suite *MediaTestSuite) TestSetHeaderOrAvatarForAccountID() { | ||||
| 	// load test image | ||||
| 	f, err := ioutil.ReadFile("./test/test-jpeg.jpg") | ||||
| 	f, err := ioutil.ReadFile("../../testrig/media/test-jpeg.jpg") | ||||
| 	assert.Nil(suite.T(), err) | ||||
| 
 | ||||
| 	ma, err := suite.mediaHandler.SetHeaderOrAvatarForAccountID(f, "weeeeeee", "header") | ||||
|  |  | |||
							
								
								
									
										8
									
								
								testrig/config.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								testrig/config.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| package testrig | ||||
| 
 | ||||
| import "github.com/superseriousbusiness/gotosocial/internal/config" | ||||
| 
 | ||||
| // NewTestConfig returns a config initialized with test defaults | ||||
| func NewTestConfig() *config.Config { | ||||
| 	return config.TestDefault() | ||||
| } | ||||
|  | @ -1,6 +1,9 @@ | |||
| package testrig | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 
 | ||||
| 	"github.com/sirupsen/logrus" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/db" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||||
|  | @ -23,65 +26,74 @@ var testModels []interface{} = []interface{}{ | |||
| 	&oauth.Client{}, | ||||
| } | ||||
| 
 | ||||
| // NewTestDB returns a new initialized, empty database for testing | ||||
| func NewTestDB() db.DB { | ||||
| 	config := NewTestConfig() | ||||
| 	l := logrus.New() | ||||
| 	l.SetLevel(logrus.TraceLevel) | ||||
| 	testDB, err := db.New(context.Background(), config, l) | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	return testDB | ||||
| } | ||||
| 
 | ||||
| // StandardDBSetup populates a given db with all the necessary tables/models for perfoming tests. | ||||
| func StandardDBSetup(db db.DB) error { | ||||
| func StandardDBSetup(db db.DB) { | ||||
| 	for _, m := range testModels { | ||||
| 		if err := db.CreateTable(m); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestTokens() { | ||||
| 	for _, v := range NewTestTokens() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestClients() { | ||||
| 	for _, v := range NewTestClients() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestApplications() { | ||||
| 	for _, v := range NewTestApplications() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestUsers() { | ||||
| 	for _, v := range NewTestUsers() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestAccounts() { | ||||
| 	for _, v := range NewTestAccounts() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestAttachments() { | ||||
| 	for _, v := range NewTestAttachments() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	for _, v := range TestStatuses() { | ||||
| 	for _, v := range NewTestStatuses() { | ||||
| 		if err := db.Put(v); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| // StandardDBTeardown drops all the standard testing tables/models from the database to ensure it's clean for the next test. | ||||
| func StandardDBTeardown(db db.DB) error { | ||||
| func StandardDBTeardown(db db.DB) { | ||||
| 	for _, m := range testModels { | ||||
| 		if err := db.DropTable(m); err != nil { | ||||
| 			return err | ||||
| 			panic(err) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
							
								
								
									
										1
									
								
								testrig/media/test-corrupted.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								testrig/media/test-corrupted.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-blurhash.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-blurhash.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 8.6 KiB | 
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-processed.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-processed.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 293 KiB | 
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-thumbnail.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-jpeg-thumbnail.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 6.6 KiB | 
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-jpeg.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-jpeg.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 263 KiB | 
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-with-exif.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-with-exif.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.2 MiB | 
							
								
								
									
										
											BIN
										
									
								
								testrig/media/test-without-exif.jpg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testrig/media/test-without-exif.jpg
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 1.2 MiB | 
|  | @ -10,7 +10,7 @@ import ( | |||
| 	"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||||
| ) | ||||
| 
 | ||||
| func TestTokens() map[string]*oauth.Token { | ||||
| func NewTestTokens() map[string]*oauth.Token { | ||||
| 	tokens := map[string]*oauth.Token{ | ||||
| 		"local_account_1": { | ||||
| 			ID:              "64cf4214-33ab-4220-b5ca-4a6a12263b20", | ||||
|  | @ -26,7 +26,7 @@ func TestTokens() map[string]*oauth.Token { | |||
| 	return tokens | ||||
| } | ||||
| 
 | ||||
| func TestClients() map[string]*oauth.Client { | ||||
| func NewTestClients() map[string]*oauth.Client { | ||||
| 	clients := map[string]*oauth.Client{ | ||||
| 		"local_account_1": { | ||||
| 			ID:     "73b48d42-029d-4487-80fc-329a5cf67869", | ||||
|  | @ -38,7 +38,7 @@ func TestClients() map[string]*oauth.Client { | |||
| 	return clients | ||||
| } | ||||
| 
 | ||||
| func TestApplications() map[string]*gtsmodel.Application { | ||||
| func NewTestApplications() map[string]*gtsmodel.Application { | ||||
| 	apps := map[string]*gtsmodel.Application{ | ||||
| 		"application_1": { | ||||
| 			ID:           "f88697b8-ee3d-46c2-ac3f-dbb85566c3cc", | ||||
|  | @ -54,7 +54,7 @@ func TestApplications() map[string]*gtsmodel.Application { | |||
| 	return apps | ||||
| } | ||||
| 
 | ||||
| func TestUsers() map[string]*gtsmodel.User { | ||||
| func NewTestUsers() map[string]*gtsmodel.User { | ||||
| 	users := map[string]*gtsmodel.User{ | ||||
| 		"unconfirmed_account": { | ||||
| 			ID:                     "0f7b1d24-1e49-4ee0-bc7e-fd87b7289eea", | ||||
|  | @ -181,7 +181,7 @@ func TestUsers() map[string]*gtsmodel.User { | |||
| 	return users | ||||
| } | ||||
| 
 | ||||
| func TestAccounts() map[string]*gtsmodel.Account { | ||||
| func NewTestAccounts() map[string]*gtsmodel.Account { | ||||
| 	accounts := map[string]*gtsmodel.Account{ | ||||
| 		"unconfirmed_account": { | ||||
| 			ID:                    "59e197f5-87cd-4be8-ac7c-09082ccc4b4d", | ||||
|  | @ -440,7 +440,7 @@ func TestAccounts() map[string]*gtsmodel.Account { | |||
| 	return accounts | ||||
| } | ||||
| 
 | ||||
| func TestAttachments() map[string]*gtsmodel.MediaAttachment { | ||||
| func NewTestAttachments() map[string]*gtsmodel.MediaAttachment { | ||||
| 	return map[string]*gtsmodel.MediaAttachment{ | ||||
| 		// "admin_account_status_1": { | ||||
| 
 | ||||
|  | @ -448,7 +448,7 @@ func TestAttachments() map[string]*gtsmodel.MediaAttachment { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestStatuses() map[string]*gtsmodel.Status { | ||||
| func NewTestStatuses() map[string]*gtsmodel.Status { | ||||
| 	return map[string]*gtsmodel.Status{ | ||||
| 		"admin_account_status_1": { | ||||
| 			ID:             "502ccd6f-0edf-48d7-9016-2dfa4d3714cd", | ||||
|  |  | |||
							
								
								
									
										24
									
								
								testrig/storage.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								testrig/storage.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| package testrig | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/sirupsen/logrus" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/config" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/storage" | ||||
| ) | ||||
| 
 | ||||
| // NewTestStorage returns a new in memory storage with the given config | ||||
| func NewTestStorage(c *config.Config, log *logrus.Logger) storage.Storage { | ||||
| 	s, err := storage.NewInMem(c, log) | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	return s | ||||
| } | ||||
| 
 | ||||
| func StandardStorageSetup(s storage.Storage) { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func StandardStorageTeardown(s storage.Storage) { | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue