Allows creating new remote clusters without providing a password (#27864)

* Allows creating new remote clusters without providing a password

If the endpoint receives a request with no password, it will generate
one internally and return it in the response, so the frotend can show
it to the user.

* Use a random string instead of a UUID for the generated password

* Update function name to avoid CString reference and adds assertion

* Update server/channels/utils/textgeneration.go

Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>

* Extends the charset

---------

Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>
Этот коммит содержится в:
Miguel de la Cruz
2024-08-08 12:18:21 +02:00
коммит произвёл GitHub
родитель 06d8c857ea
Коммит eec9a4742a
5 изменённых файлов: 69 добавлений и 20 удалений

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

@@ -195,17 +195,35 @@ func TestCreateRemoteCluster(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065" })
t.Run("Should enforce the presence of the password", func(t *testing.T) {
t.Run("Should generate a password if none is given", func(t *testing.T) {
// clean the password and check the response
rcWithTeamAndPassword.Password = ""
rcWithTeamNoPassword := &model.RemoteClusterWithPassword{
RemoteCluster: &model.RemoteCluster{
Name: "remotecluster-nopasswd",
SiteURL: "http://no-passwd.example.com",
Token: model.NewId(),
},
Password: "",
}
rcWithInvite, resp, err := th.SystemAdminClient.CreateRemoteCluster(context.Background(), rcWithTeamAndPassword)
CheckBadRequestStatus(t, resp)
require.Error(t, err)
require.Empty(t, rcWithInvite)
rcWithInvite, resp, err := th.SystemAdminClient.CreateRemoteCluster(context.Background(), rcWithTeamNoPassword)
CheckCreatedStatus(t, resp)
require.NoError(t, err)
require.NotZero(t, rcWithInvite.Invite)
// when the password is not provided, it is returned as part
// of the response
require.NotZero(t, rcWithInvite.Password)
require.Len(t, rcWithInvite.Password, 16)
// reset password for the next tests
rcWithTeamAndPassword.Password = "mysupersecret"
rc, appErr := th.App.GetRemoteCluster(rcWithInvite.RemoteCluster.RemoteId)
require.Nil(t, appErr)
require.Equal(t, rcWithTeamNoPassword.Name, rc.Name)
rci, appErr := th.App.DecryptRemoteClusterInvite(rcWithInvite.Invite, rcWithInvite.Password)
require.Nil(t, appErr)
require.Equal(t, rc.RemoteId, rci.RemoteId)
require.Equal(t, rc.RemoteToken, rci.Token)
require.Equal(t, th.App.GetSiteURL(), rci.SiteURL)
})
t.Run("Should return a sanitized remote cluster and its invite", func(t *testing.T) {
@@ -216,6 +234,9 @@ func TestCreateRemoteCluster(t *testing.T) {
require.NotZero(t, rcWithInvite.Invite)
require.Zero(t, rcWithInvite.RemoteCluster.Token)
require.Zero(t, rcWithInvite.RemoteCluster.RemoteToken)
// when the password is provided as an input, is not returned
// by the endpoint
require.Zero(t, rcWithInvite.Password)
rc, appErr := th.App.GetRemoteCluster(rcWithInvite.RemoteCluster.RemoteId)
require.Nil(t, appErr)