MM-60980: Add RemoteClusterInvite.IsValid (#28624)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
73fc99b577
Коммит
e6d6881917
@@ -13,6 +13,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -368,6 +369,22 @@ type RemoteClusterInvite struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func (rci *RemoteClusterInvite) IsValid() *AppError {
|
||||
if !IsValidId(rci.RemoteId) {
|
||||
return NewAppError("RemoteClusterInvite.IsValid", "model.remote_cluster_invite.is_valid.remote_id.app_error", nil, "id="+rci.RemoteId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if rci.Token == "" {
|
||||
return NewAppError("RemoteClusterInvite.IsValid", "model.remote_cluster_invite.is_valid.token.app_error", nil, "Token empty", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if _, err := url.ParseRequestURI(rci.SiteURL); err != nil {
|
||||
return NewAppError("RemoteClusterInvite.IsValid", "model.remote_cluster_invite.is_valid.site_url.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rci *RemoteClusterInvite) Encrypt(password string) ([]byte, error) {
|
||||
raw, err := json.Marshal(&rci)
|
||||
if err != nil {
|
||||
|
||||
@@ -78,6 +78,34 @@ func TestRemoteClusterMsgIsValid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteClusterInviteIsValid(t *testing.T) {
|
||||
id := NewId()
|
||||
url := "https://localhost:8080/test"
|
||||
token := NewId()
|
||||
|
||||
data := []struct {
|
||||
name string
|
||||
invite *RemoteClusterInvite
|
||||
valid bool
|
||||
}{
|
||||
{name: "Zero value", invite: &RemoteClusterInvite{}, valid: false},
|
||||
{name: "Missing remote id", invite: &RemoteClusterInvite{Token: token, SiteURL: url}, valid: false},
|
||||
{name: "Missing site url", invite: &RemoteClusterInvite{RemoteId: id, Token: token}, valid: false},
|
||||
{name: "Bad site url", invite: &RemoteClusterInvite{RemoteId: id, Token: token, SiteURL: ":/localhost"}, valid: false},
|
||||
{name: "Missing token", invite: &RemoteClusterInvite{RemoteId: id, SiteURL: url}, valid: false},
|
||||
{name: "RemoteClusterInvite valid", invite: &RemoteClusterInvite{RemoteId: id, Token: token, SiteURL: url}, valid: true},
|
||||
}
|
||||
|
||||
for _, item := range data {
|
||||
appErr := item.invite.IsValid()
|
||||
if item.valid {
|
||||
assert.Nil(t, appErr, item.name)
|
||||
} else {
|
||||
assert.NotNil(t, appErr, item.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFixTopics(t *testing.T) {
|
||||
testData := []struct {
|
||||
topics string
|
||||
|
||||
Ссылка в новой задаче
Block a user