[MM-41022] - Fix panic when AllowCookiesSubdomain setting is false (#19339)

* [MM-41022] - Cloud: Panic after log in when AllowCookiesSubdomain setting is false

* remove print

* improvement

* remove configration setting from flow

* fix tests

* feedback impl

* feedback impl
Этот коммит содержится в:
Allan Guwatudde
2022-01-17 18:50:40 +03:00
коммит произвёл GitHub
родитель 0a06b3e808
Коммит ee92bda912
2 изменённых файлов: 42 добавлений и 7 удалений

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

@@ -3643,7 +3643,6 @@ func TestLoginCookies(t *testing.T) {
t.Run("should return cookie with MMCLOUDURL for cloud installations", func(t *testing.T) {
updateConfig := func(cfg *model.Config) {
*cfg.ServiceSettings.AllowCookiesForSubdomains = true
*cfg.ServiceSettings.SiteURL = "https://testchips.cloud.mattermost.com"
}
th := SetupAndApplyConfigBeforeLogin(t, updateConfig).InitBasic()
@@ -3661,9 +3660,29 @@ func TestLoginCookies(t *testing.T) {
assert.Equal(t, "mattermost.com", domain)
})
t.Run("should NOT return cookie with MMCLOUDURL for cloud installations without expected format of cloud URL", func(t *testing.T) {
updateConfig := func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = "https://testchips.com" // correct cloud URL would be https://testchips.cloud.mattermost.com
}
th := SetupAndApplyConfigBeforeLogin(t, updateConfig).InitBasic()
defer th.TearDown()
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
_, resp, _ := th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
cloudSessionCookie := ""
for _, cookie := range resp.Header["Set-Cookie"] {
if match := regexp.MustCompile("^" + model.SessionCookieCloudUrl + "=([a-z0-9]+)").FindStringSubmatch(cookie); match != nil {
cloudSessionCookie = match[1]
}
}
// no cookie set
assert.Equal(t, "", cloudSessionCookie)
})
t.Run("should NOT return cookie with MMCLOUDURL for NON cloud installations", func(t *testing.T) {
updateConfig := func(cfg *model.Config) {
*cfg.ServiceSettings.AllowCookiesForSubdomains = true
*cfg.ServiceSettings.SiteURL = "https://testchips.com"
}
th := SetupAndApplyConfigBeforeLogin(t, updateConfig).InitBasic()