Updates the create remote cluster endpoint to require a default team id (#28709)

Support for RemoteClusters without a default team id is in place for
old servers that created those connections before v10.1. This change
forbids the creation of new RemoteClusters without providing this
field, and will be removed when manual invites are implemented.

Co-authored-by: Caleb Roseland <caleb@calebroseland.com>
Этот коммит содержится в:
Miguel de la Cruz
2024-10-18 12:22:27 +02:00
коммит произвёл GitHub
родитель ad50357792
Коммит 5a923e0b94
3 изменённых файлов: 27 добавлений и 4 удалений

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

@@ -86,11 +86,14 @@
type: object
required:
- name
- default_team_id
properties:
name:
type: string
display_name:
type: string
default_team_id:
type: string
password:
type: string
description: |

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

@@ -382,6 +382,11 @@ func createRemoteCluster(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if rcWithTeamAndPassword.DefaultTeamId == "" {
c.SetInvalidParam("remote_cluster.default_team_id")
return
}
if rcWithTeamAndPassword.DisplayName == "" {
rcWithTeamAndPassword.DisplayName = rcWithTeamAndPassword.Name
}

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

@@ -185,7 +185,6 @@ func TestCreateRemoteCluster(t *testing.T) {
rcWithTeamAndPassword := &model.RemoteClusterWithPassword{
RemoteCluster: &model.RemoteCluster{
Name: "remotecluster",
SiteURL: "http://example.com",
DefaultTeamId: model.NewId(),
Token: model.NewId(),
},
@@ -222,13 +221,29 @@ func TestCreateRemoteCluster(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065" })
t.Run("Should not work if no default team id is provided", func(t *testing.T) {
rcWithoutDefaultTeamId := &model.RemoteClusterWithPassword{
RemoteCluster: &model.RemoteCluster{
Name: "remotecluster-nodefaultteamid",
Token: model.NewId(),
},
Password: "",
}
rcWithInvite, resp, err := th.SystemAdminClient.CreateRemoteCluster(context.Background(), rcWithoutDefaultTeamId)
CheckBadRequestStatus(t, resp)
require.Error(t, err)
require.ErrorContains(t, err, "remote_cluster.default_team_id")
require.Zero(t, rcWithInvite)
})
t.Run("Should generate a password if none is given", func(t *testing.T) {
// clean the password and check the response
rcWithTeamNoPassword := &model.RemoteClusterWithPassword{
RemoteCluster: &model.RemoteCluster{
Name: "remotecluster-nopasswd",
SiteURL: "http://no-passwd.example.com",
Token: model.NewId(),
Name: "remotecluster-nopasswd",
DefaultTeamId: model.NewId(),
Token: model.NewId(),
},
Password: "",
}