MM-64718 Improve validation of thread follower imports (#33287)
* MM-64718 Improve validation of thread follower imports * Add additional test cases and restucture tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4bb35c5043
Коммит
4b77485e8f
@@ -563,6 +563,14 @@ func ValidatePostImportData(data *PostImportData, maxPostSize int) *model.AppErr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if data.ThreadFollowers != nil {
|
||||||
|
for _, follower := range *data.ThreadFollowers {
|
||||||
|
if err := ValidateThreadFollowerImportData(&follower); err != nil {
|
||||||
|
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.thread_follower.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,6 +695,14 @@ func ValidateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if data.ThreadFollowers != nil {
|
||||||
|
for _, follower := range *data.ThreadFollowers {
|
||||||
|
if err := ValidateThreadFollowerImportData(&follower); err != nil {
|
||||||
|
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.thread_follower.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,6 +733,18 @@ func ValidateEmojiImportData(data *EmojiImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValidateThreadFollowerImportData(data *ThreadFollowerImportData) *model.AppError {
|
||||||
|
if data == nil {
|
||||||
|
return model.NewAppError("BulkImport", "app.import.validate_thread_follower_data.empty.error", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.User == nil || *data.User == "" {
|
||||||
|
return model.NewAppError("BulkImport", "app.import.validate_thread_follower_data.user_missing.error", nil, "", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func isValidTrueOrFalseString(value string) bool {
|
func isValidTrueOrFalseString(value string) bool {
|
||||||
return value == "true" || value == "false"
|
return value == "true" || value == "false"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1541,6 +1541,58 @@ func TestImportValidateEmojiImportData(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportValidateThreadFollowerImportData(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
testName string
|
||||||
|
input *ThreadFollowerImportData
|
||||||
|
expectError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testName: "success",
|
||||||
|
input: &ThreadFollowerImportData{
|
||||||
|
LastViewed: model.NewPointer(int64(0)),
|
||||||
|
UnreadMentions: model.NewPointer(int64(0)),
|
||||||
|
User: model.NewPointer("user1"),
|
||||||
|
},
|
||||||
|
expectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "nil",
|
||||||
|
input: nil,
|
||||||
|
expectError: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "nil user",
|
||||||
|
input: &ThreadFollowerImportData{
|
||||||
|
LastViewed: model.NewPointer(int64(0)),
|
||||||
|
UnreadMentions: model.NewPointer(int64(0)),
|
||||||
|
User: nil,
|
||||||
|
},
|
||||||
|
expectError: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "empty user",
|
||||||
|
input: &ThreadFollowerImportData{
|
||||||
|
LastViewed: model.NewPointer(int64(0)),
|
||||||
|
UnreadMentions: model.NewPointer(int64(0)),
|
||||||
|
User: model.NewPointer(""),
|
||||||
|
},
|
||||||
|
expectError: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.testName, func(t *testing.T) {
|
||||||
|
err := ValidateThreadFollowerImportData(tc.input)
|
||||||
|
if tc.expectError {
|
||||||
|
require.NotNil(t, err)
|
||||||
|
} else {
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func checkError(t *testing.T, err *model.AppError) {
|
func checkError(t *testing.T, err *model.AppError) {
|
||||||
require.NotNil(t, err, "Should have returned an error.")
|
require.NotNil(t, err, "Should have returned an error.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5762,6 +5762,10 @@
|
|||||||
"id": "app.import.validate_direct_post_import_data.message_missing.error",
|
"id": "app.import.validate_direct_post_import_data.message_missing.error",
|
||||||
"translation": "Missing required direct post property: message"
|
"translation": "Missing required direct post property: message"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "app.import.validate_direct_post_import_data.thread_follower.error",
|
||||||
|
"translation": "Failed to validate direct post thread follower data."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "app.import.validate_direct_post_import_data.unknown_flagger.error",
|
"id": "app.import.validate_direct_post_import_data.unknown_flagger.error",
|
||||||
"translation": "Direct post can only be flagged by members of the channel it is in. \"{{.Username}}\" is not a member."
|
"translation": "Direct post can only be flagged by members of the channel it is in. \"{{.Username}}\" is not a member."
|
||||||
@@ -5818,6 +5822,10 @@
|
|||||||
"id": "app.import.validate_post_import_data.team_missing.error",
|
"id": "app.import.validate_post_import_data.team_missing.error",
|
||||||
"translation": "Missing required Post property: Team."
|
"translation": "Missing required Post property: Team."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "app.import.validate_post_import_data.thread_follower.error",
|
||||||
|
"translation": "Failed to validate post thread follower data."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "app.import.validate_post_import_data.user_missing.error",
|
"id": "app.import.validate_post_import_data.user_missing.error",
|
||||||
"translation": "Missing required Post property: User."
|
"translation": "Missing required Post property: User."
|
||||||
@@ -5950,6 +5958,14 @@
|
|||||||
"id": "app.import.validate_team_import_data.type_missing.error",
|
"id": "app.import.validate_team_import_data.type_missing.error",
|
||||||
"translation": "Missing required team property: type."
|
"translation": "Missing required team property: type."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "app.import.validate_thread_follower_data.empty.error",
|
||||||
|
"translation": "Import follower data empty."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "app.import.validate_thread_follower_data.user_missing.error",
|
||||||
|
"translation": "Missing required follower property: user."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "app.import.validate_user_channels_import_data.channel_name_missing.error",
|
"id": "app.import.validate_user_channels_import_data.channel_name_missing.error",
|
||||||
"translation": "Channel name missing from User's Channel Membership."
|
"translation": "Channel name missing from User's Channel Membership."
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user