Revert user_agent chanes made for PLT-959 #6945 to fix clients incorrectly being given incompaibile message (#7497)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
265392fa48
Коммит
7d23276b0c
30
web/web.go
30
web/web.go
@@ -5,7 +5,6 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NYTimes/gziphandler"
|
"github.com/NYTimes/gziphandler"
|
||||||
@@ -67,28 +66,19 @@ func pluginHandler(handler http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//map should be of minimum required browser version.
|
var browsersNotSupported string = "MSIE/8;MSIE/9;MSIE/10;Internet Explorer/8;Internet Explorer/9;Internet Explorer/10;Safari/7;Safari/8"
|
||||||
//var browsersNotSupported string = "MSIE/11;Internet Explorer/11;Safari/9;Chrome/43;Edge/15;Firefox/52"
|
|
||||||
//var browserMinimumSupported = [6]string{"MSIE/11", "Internet Explorer/11", "Safari/9", "Chrome/43", "Edge/15", "Firefox/52"}
|
|
||||||
var browserMinimumSupported = map[string]int{
|
|
||||||
"MSIE": 11,
|
|
||||||
"Internet Explorer": 11,
|
|
||||||
"Safari": 9,
|
|
||||||
"Chrome": 43,
|
|
||||||
"Edge": 15,
|
|
||||||
"Firefox": 52,
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckBrowserCompatability(ua *user_agent.UserAgent) bool {
|
func CheckBrowserCompatability(c *api.Context, r *http.Request) bool {
|
||||||
|
ua := user_agent.New(r.UserAgent())
|
||||||
bname, bversion := ua.Browser()
|
bname, bversion := ua.Browser()
|
||||||
|
|
||||||
l4g.Debug("Detected Browser: %v %v", bname, bversion)
|
browsers := strings.Split(browsersNotSupported, ";")
|
||||||
|
for _, browser := range browsers {
|
||||||
|
version := strings.Split(browser, "/")
|
||||||
|
|
||||||
curVersion := strings.Split(bversion, ".")
|
if strings.HasPrefix(bname, version[0]) && strings.HasPrefix(bversion, version[1]) {
|
||||||
intCurVersion, _ := strconv.Atoi(curVersion[0])
|
return false
|
||||||
|
}
|
||||||
if version, exist := browserMinimumSupported[bname]; exist && intCurVersion < version {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -96,7 +86,7 @@ func CheckBrowserCompatability(ua *user_agent.UserAgent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
if !CheckBrowserCompatability(user_agent.New(r.UserAgent())) {
|
if !CheckBrowserCompatability(c, r) {
|
||||||
w.Header().Set("Cache-Control", "no-store")
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
page := utils.NewHTMLTemplate("unsupported_browser", c.Locale)
|
page := utils.NewHTMLTemplate("unsupported_browser", c.Locale)
|
||||||
page.Props["Title"] = c.T("web.error.unsupported_browser.title")
|
page.Props["Title"] = c.T("web.error.unsupported_browser.title")
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
"github.com/mssola/user_agent"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ApiClient *model.Client
|
var ApiClient *model.Client
|
||||||
@@ -114,31 +113,3 @@ func TestIncomingWebhook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckBrowserCompatability(t *testing.T) {
|
|
||||||
|
|
||||||
//test should fail browser compatibility check with Mozilla FF 40.1
|
|
||||||
ua := "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
|
|
||||||
t.Logf("Checking Mozzila 40.1 with U.A. String: \n%v", ua)
|
|
||||||
if result := CheckBrowserCompatability(user_agent.New(ua)); result == true {
|
|
||||||
t.Error("Fail: should have failed browser compatibility")
|
|
||||||
} else {
|
|
||||||
t.Log("Pass: User Agent correctly failed!")
|
|
||||||
}
|
|
||||||
|
|
||||||
ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
|
|
||||||
t.Logf("Checking Chrome 60 with U.A. String: \n%v", ua)
|
|
||||||
if result := CheckBrowserCompatability(user_agent.New(ua)); result == false {
|
|
||||||
t.Error("Fail: should have passed browser compatibility")
|
|
||||||
} else {
|
|
||||||
t.Log("Pass: User Agent correctly passed!")
|
|
||||||
}
|
|
||||||
|
|
||||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
|
|
||||||
t.Logf("Checking Edge 14.14393 with U.A. String: \n%v", ua)
|
|
||||||
if result := CheckBrowserCompatability(user_agent.New(ua)); result == true {
|
|
||||||
t.Log("Warning: Edge should have failed browser compatibility. It is probably still detecting as Chrome.")
|
|
||||||
} else {
|
|
||||||
t.Log("Pass: User Agent correctly failed!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user