[MM-39583] - Intermediary web login page: Workspace Cookies (#19256)
* [MM-39583] - Intermediary web login page: Workspace Cookies * only cloud * fix error with license check * feedback impl * improvement * make improvements Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8ad9a22e77
Коммит
664af506a3
@@ -251,6 +251,26 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
return th
|
||||
}
|
||||
|
||||
func SetupAndApplyConfigBeforeLogin(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
||||
if testing.Short() {
|
||||
tb.SkipNow()
|
||||
}
|
||||
|
||||
if mainHelper == nil {
|
||||
tb.SkipNow()
|
||||
}
|
||||
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, nil, nil)
|
||||
th.App.UpdateConfig(updateConfig)
|
||||
th.InitLogin()
|
||||
return th
|
||||
}
|
||||
|
||||
func SetupConfig(tb testing.TB, updateConfig func(cfg *model.Config)) *TestHelper {
|
||||
if testing.Short() {
|
||||
tb.SkipNow()
|
||||
|
||||
@@ -1852,6 +1852,11 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.App.AttachSessionCookies(c.AppContext, w, r)
|
||||
}
|
||||
|
||||
// For context see: https://mattermost.atlassian.net/browse/MM-39583
|
||||
if c.App.Srv().License() != nil && *c.App.Srv().License().Features.Cloud {
|
||||
c.App.AttachCloudSessionCookie(c.AppContext, w, r)
|
||||
}
|
||||
|
||||
userTermsOfService, err := c.App.GetUserTermsOfService(user.Id)
|
||||
if err != nil && err.StatusCode != http.StatusNotFound {
|
||||
c.Err = err
|
||||
|
||||
@@ -3640,6 +3640,46 @@ 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()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
_, resp, _ := th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
val := strings.Split(resp.Header["Set-Cookie"][0], ";")
|
||||
cloudSessionCookie := strings.Split(val[0], "=")[1]
|
||||
domain := strings.Split(val[2], "=")[1]
|
||||
|
||||
assert.Equal(t, "testchips", cloudSessionCookie)
|
||||
assert.Equal(t, "mattermost.com", domain)
|
||||
})
|
||||
|
||||
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()
|
||||
defer th.TearDown()
|
||||
|
||||
_, 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)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCBALogin(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user