MM-23244: Validate that AuthData and AuthService fields are mutually inclusive. (#14175)

* MM-23244: Validate that either both or neither AuthData and AuthService fields are set.

* MM-23244: Readability improvement.

* MM-23244: Adds translation. Tests for error id.

* MM-23244: Fix test.

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Martin Kraft
2020-04-09 18:51:27 -04:00
коммит произвёл GitHub
родитель bfb380630c
Коммит a9ea3587bb
4 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package app
import (
"fmt"
"path/filepath"
"strings"
"testing"
@@ -632,6 +633,43 @@ func TestImportValidateUserImportData(t *testing.T) {
checkError(t, validateUserImportData(&data))
}
func TestImportValidateUserAuth(t *testing.T) {
tests := []struct {
authService *string
authData *string
isValid bool
}{
{nil, nil, true},
{ptrStr(""), ptrStr(""), true},
{ptrStr("foo"), ptrStr("foo"), true},
{nil, ptrStr(""), true},
{ptrStr(""), nil, true},
{ptrStr("foo"), nil, false},
{ptrStr("foo"), ptrStr(""), false},
{nil, ptrStr("foo"), false},
{ptrStr(""), ptrStr("foo"), false},
}
for _, test := range tests {
data := UserImportData{
Username: ptrStr("bob"),
Email: ptrStr("bob@example.com"),
AuthService: test.authService,
AuthData: test.authData,
}
err := validateUserImportData(&data)
if test.isValid {
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)
}
}
}
func TestImportValidateUserTeamsImportData(t *testing.T) {
// Invalid Name.