[MM-48385] Validate against a list of auth services (#22154)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
aa61f8dfbb
Коммит
a03033ef15
@@ -231,6 +231,10 @@ func ValidateUserImportData(data *UserImportData) *model.AppError {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.auth_data_and_service_dependency.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if appErr := validateAuthService(data.AuthService); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
if data.Password != nil && *data.Password == "" {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.password_length.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
@@ -312,6 +316,29 @@ func ValidateUserImportData(data *UserImportData) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
var validAuthServices = []string{
|
||||
"",
|
||||
model.UserAuthServiceEmail,
|
||||
model.UserAuthServiceGitlab,
|
||||
model.UserAuthServiceSaml,
|
||||
model.UserAuthServiceLdap,
|
||||
model.ServiceGoogle,
|
||||
model.ServiceOffice365,
|
||||
}
|
||||
|
||||
func validateAuthService(authService *string) *model.AppError {
|
||||
if authService == nil {
|
||||
return nil
|
||||
}
|
||||
for _, valid := range validAuthServices {
|
||||
if *authService == valid {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_teams_import_data.invalid_auth_service.error", map[string]any{"AuthService": *authService}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func ValidateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
||||
if data == nil {
|
||||
return nil
|
||||
|
||||
@@ -646,7 +646,7 @@ func TestImportValidateUserAuth(t *testing.T) {
|
||||
}{
|
||||
{nil, nil, true},
|
||||
{ptrStr(""), ptrStr(""), true},
|
||||
{ptrStr("foo"), ptrStr("foo"), true},
|
||||
{ptrStr("foo"), ptrStr("foo"), false},
|
||||
{nil, ptrStr(""), true},
|
||||
{ptrStr(""), nil, true},
|
||||
|
||||
@@ -669,7 +669,6 @@ func TestImportValidateUserAuth(t *testing.T) {
|
||||
require.Nil(t, err, fmt.Sprintf("authService: %v, authData: %v", test.authService, test.authData))
|
||||
} else {
|
||||
require.NotNil(t, err, fmt.Sprintf("authService: %v, authData: %v", test.authService, test.authData))
|
||||
require.Equal(t, "app.import.validate_user_import_data.auth_data_and_service_dependency.error", err.Id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5723,6 +5723,10 @@
|
||||
"id": "app.import.validate_user_import_data.username_missing.error",
|
||||
"translation": "Missing require user property: username."
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_user_teams_import_data.invalid_auth_service.error",
|
||||
"translation": "Invalid auth service: {{.AuthService}}"
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_user_teams_import_data.invalid_roles.error",
|
||||
"translation": "Invalid roles for User's Team Membership."
|
||||
|
||||
Ссылка в новой задаче
Block a user