MM-8840: Add GlobalRelay Configuration Settings (#8304)
* Added new GlobalRelay config settings * Adding default values to global relay config * Migrate global relay config tests to table driven tests
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
b2dd00dd5b
Коммит
5ed3b42629
24
i18n/en.json
24
i18n/en.json
@@ -4946,6 +4946,30 @@
|
|||||||
"id": "model.config.is_valid.message_export.batch_size.app_error",
|
"id": "model.config.is_valid.message_export.batch_size.app_error",
|
||||||
"translation": "Message export job BatchSize must be a positive integer"
|
"translation": "Message export job BatchSize must be a positive integer"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.export_type.app_error",
|
||||||
|
"translation": "Message export job ExportFormat must be one of either 'actiance' or 'globalrelay'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.global_relay.config_missing.app_error",
|
||||||
|
"translation": "Message export job ExportFormat is set to 'globalrelay', but GlobalRelaySettings are missing"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.global_relay.customer_type.app_error",
|
||||||
|
"translation": "Message export GlobalRelaySettings.CustomerType must be set to one of either 'A9' or 'A10'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.global_relay.email_address.app_error",
|
||||||
|
"translation": "Message export job GlobalRelaySettings.EmailAddress must be set to a valid email address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.global_relay.smtp_username.app_error",
|
||||||
|
"translation": "Message export job GlobalRelaySettings.SmtpUsername must be set"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "model.config.is_valid.message_export.global_relay.smtp_password.app_error",
|
||||||
|
"translation": "Message export job GlobalRelaySettings.SmtpPassword must be set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "model.config.is_valid.message_export.daily_runtime.app_error",
|
"id": "model.config.is_valid.message_export.daily_runtime.app_error",
|
||||||
"translation": "Message export job DailyRuntime must be a 24-hour time stamp in the form HH:MM."
|
"translation": "Message export job DailyRuntime must be a 24-hour time stamp in the form HH:MM."
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ const (
|
|||||||
|
|
||||||
COMPLIANCE_EXPORT_TYPE_ACTIANCE = "actiance"
|
COMPLIANCE_EXPORT_TYPE_ACTIANCE = "actiance"
|
||||||
COMPLIANCE_EXPORT_TYPE_GLOBALRELAY = "globalrelay"
|
COMPLIANCE_EXPORT_TYPE_GLOBALRELAY = "globalrelay"
|
||||||
|
GLOBALRELAY_CUSTOMER_TYPE_A9 = "A9"
|
||||||
|
GLOBALRELAY_CUSTOMER_TYPE_A10 = "A10"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceSettings struct {
|
type ServiceSettings struct {
|
||||||
@@ -1627,6 +1629,28 @@ func (s *PluginSettings) SetDefaults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GlobalRelayMessageExportSettings struct {
|
||||||
|
CustomerType *string // must be either A9 or A10, dictates SMTP server url
|
||||||
|
SmtpUsername *string
|
||||||
|
SmtpPassword *string
|
||||||
|
EmailAddress *string // the address to send messages to
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GlobalRelayMessageExportSettings) SetDefaults() {
|
||||||
|
if s.CustomerType == nil {
|
||||||
|
s.CustomerType = NewString(GLOBALRELAY_CUSTOMER_TYPE_A9)
|
||||||
|
}
|
||||||
|
if s.SmtpUsername == nil {
|
||||||
|
s.SmtpUsername = NewString("")
|
||||||
|
}
|
||||||
|
if s.SmtpPassword == nil {
|
||||||
|
s.SmtpPassword = NewString("")
|
||||||
|
}
|
||||||
|
if s.EmailAddress == nil {
|
||||||
|
s.EmailAddress = NewString("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type MessageExportSettings struct {
|
type MessageExportSettings struct {
|
||||||
EnableExport *bool
|
EnableExport *bool
|
||||||
ExportFormat *string
|
ExportFormat *string
|
||||||
@@ -1635,7 +1659,7 @@ type MessageExportSettings struct {
|
|||||||
BatchSize *int
|
BatchSize *int
|
||||||
|
|
||||||
// formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format
|
// formatter-specific settings - these are only expected to be non-nil if ExportFormat is set to the associated format
|
||||||
GlobalRelayEmailAddress *string
|
GlobalRelaySettings *GlobalRelayMessageExportSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MessageExportSettings) SetDefaults() {
|
func (s *MessageExportSettings) SetDefaults() {
|
||||||
@@ -1666,6 +1690,11 @@ func (s *MessageExportSettings) SetDefaults() {
|
|||||||
if s.BatchSize == nil {
|
if s.BatchSize == nil {
|
||||||
s.BatchSize = NewInt(10000)
|
s.BatchSize = NewInt(10000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.GlobalRelaySettings == nil {
|
||||||
|
s.GlobalRelaySettings = &GlobalRelayMessageExportSettings{}
|
||||||
|
s.GlobalRelaySettings.SetDefaults()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigFunc func() *Config
|
type ConfigFunc func() *Config
|
||||||
@@ -2199,10 +2228,18 @@ func (mes *MessageExportSettings) isValid(fs FileSettings) *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY {
|
if *mes.ExportFormat == COMPLIANCE_EXPORT_TYPE_GLOBALRELAY {
|
||||||
// validating email addresses is hard - just make sure it contains an '@' sign
|
if mes.GlobalRelaySettings == nil {
|
||||||
// see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
|
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.config_missing.app_error", nil, "", http.StatusBadRequest)
|
||||||
if mes.GlobalRelayEmailAddress == nil || !strings.Contains(*mes.GlobalRelayEmailAddress, "@") {
|
} else if mes.GlobalRelaySettings.CustomerType == nil || (*mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A9 && *mes.GlobalRelaySettings.CustomerType != GLOBALRELAY_CUSTOMER_TYPE_A10) {
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay_email_address.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
} else if mes.GlobalRelaySettings.EmailAddress == nil || !strings.Contains(*mes.GlobalRelaySettings.EmailAddress, "@") {
|
||||||
|
// validating email addresses is hard - just make sure it contains an '@' sign
|
||||||
|
// see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
|
||||||
|
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.email_address.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
} else if mes.GlobalRelaySettings.SmtpUsername == nil || *mes.GlobalRelaySettings.SmtpUsername == "" {
|
||||||
|
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_username.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
} else if mes.GlobalRelaySettings.SmtpPassword == nil || *mes.GlobalRelaySettings.SmtpPassword == "" {
|
||||||
|
return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.smtp_password.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,21 +183,123 @@ func TestMessageExportSettingsIsValidActiance(t *testing.T) {
|
|||||||
require.Nil(t, mes.isValid(*fs))
|
require.Nil(t, mes.isValid(*fs))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageExportSettingsIsValidGlobalRelay(t *testing.T) {
|
func TestMessageExportSettingsIsValidGlobalRelaySettingsMissing(t *testing.T) {
|
||||||
fs := &FileSettings{
|
fs := &FileSettings{
|
||||||
DriverName: NewString("foo"), // bypass file location check
|
DriverName: NewString("foo"), // bypass file location check
|
||||||
}
|
}
|
||||||
mes := &MessageExportSettings{
|
mes := &MessageExportSettings{
|
||||||
EnableExport: NewBool(true),
|
EnableExport: NewBool(true),
|
||||||
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||||
ExportFromTimestamp: NewInt64(0),
|
ExportFromTimestamp: NewInt64(0),
|
||||||
DailyRunTime: NewString("15:04"),
|
DailyRunTime: NewString("15:04"),
|
||||||
BatchSize: NewInt(100),
|
BatchSize: NewInt(100),
|
||||||
GlobalRelayEmailAddress: NewString("test@mattermost.com"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// should pass because everything is valid
|
// should fail because globalrelay settings are missing
|
||||||
require.Nil(t, mes.isValid(*fs))
|
require.Error(t, mes.isValid(*fs))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidCustomerType(t *testing.T) {
|
||||||
|
fs := &FileSettings{
|
||||||
|
DriverName: NewString("foo"), // bypass file location check
|
||||||
|
}
|
||||||
|
mes := &MessageExportSettings{
|
||||||
|
EnableExport: NewBool(true),
|
||||||
|
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||||
|
ExportFromTimestamp: NewInt64(0),
|
||||||
|
DailyRunTime: NewString("15:04"),
|
||||||
|
BatchSize: NewInt(100),
|
||||||
|
GlobalRelaySettings: &GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString("Invalid"),
|
||||||
|
EmailAddress: NewString("valid@mattermost.com"),
|
||||||
|
SmtpUsername: NewString("SomeUsername"),
|
||||||
|
SmtpPassword: NewString("SomePassword"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// should fail because customer type is invalid
|
||||||
|
require.Error(t, mes.isValid(*fs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidEmailAddress(t *testing.T) {
|
||||||
|
func TestMessageExportSettingsGlobalRelaySettings(t *testing.T) {
|
||||||
|
fs := &FileSettings{
|
||||||
|
DriverName: NewString("foo"), // bypass file location check
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
value *GlobalRelayMessageExportSettings
|
||||||
|
success bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"Invalid email address",
|
||||||
|
&GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A9),
|
||||||
|
EmailAddress: NewString("invalidEmailAddress"),
|
||||||
|
SmtpUsername: NewString("SomeUsername"),
|
||||||
|
SmtpPassword: NewString("SomePassword"),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Missing smtp username",
|
||||||
|
&GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
|
||||||
|
EmailAddress: NewString("valid@mattermost.com"),
|
||||||
|
SmtpPassword: NewString("SomePassword"),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Invalid smtp username",
|
||||||
|
&GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
|
||||||
|
EmailAddress: NewString("valid@mattermost.com"),
|
||||||
|
SmtpUsername: NewString(""),
|
||||||
|
SmtpPassword: NewString("SomePassword"),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Invalid smtp password",
|
||||||
|
&GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
|
||||||
|
EmailAddress: NewString("valid@mattermost.com"),
|
||||||
|
SmtpUsername: NewString("SomeUsername"),
|
||||||
|
SmtpPassword: NewString(""),
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Valid data",
|
||||||
|
&GlobalRelayMessageExportSettings{
|
||||||
|
CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A9),
|
||||||
|
EmailAddress: NewString("valid@mattermost.com"),
|
||||||
|
SmtpUsername: NewString("SomeUsername"),
|
||||||
|
SmtpPassword: NewString("SomePassword"),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
mes := &MessageExportSettings{
|
||||||
|
EnableExport: NewBool(true),
|
||||||
|
ExportFormat: NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
|
||||||
|
ExportFromTimestamp: NewInt64(0),
|
||||||
|
DailyRunTime: NewString("15:04"),
|
||||||
|
BatchSize: NewInt(100),
|
||||||
|
GlobalRelaySettings: tt.value,
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.success {
|
||||||
|
require.Nil(t, mes.isValid(*fs))
|
||||||
|
} else {
|
||||||
|
require.Error(t, mes.isValid(*fs))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMessageExportSetDefaults(t *testing.T) {
|
func TestMessageExportSetDefaults(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user