Fixing license (#3878)
* Fixing sanitize license * Fixing license * Fixing unit tests
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
c3ae3f20f5
Коммит
839f1ad444
@@ -173,12 +173,18 @@ func RemoveLicense() *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
etag := utils.GetClientLicenseEtag()
|
etag := utils.GetClientLicenseEtag(!c.IsSystemAdmin())
|
||||||
if HandleEtag(etag, w, r) {
|
if HandleEtag(etag, w, r) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
clientLicense := utils.ClientLicense
|
var clientLicense map[string]string
|
||||||
|
|
||||||
|
if c.IsSystemAdmin() {
|
||||||
|
clientLicense = utils.ClientLicense
|
||||||
|
} else {
|
||||||
|
clientLicense = utils.GetSanitizedClientLicense()
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||||
w.Write([]byte(model.MapToJson(clientLicense)))
|
w.Write([]byte(model.MapToJson(clientLicense)))
|
||||||
|
|||||||
@@ -922,7 +922,7 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
if c.IsSystemAdmin() {
|
if c.IsSystemAdmin() {
|
||||||
il.LicenseCfg = utils.ClientLicense
|
il.LicenseCfg = utils.ClientLicense
|
||||||
} else {
|
} else {
|
||||||
il.LicenseCfg = utils.GetSantizedClientLicense()
|
il.LicenseCfg = utils.GetSanitizedClientLicense()
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte(il.ToJson()))
|
w.Write([]byte(il.ToJson()))
|
||||||
|
|||||||
@@ -141,17 +141,23 @@ func getClientLicense(l *model.License) map[string]string {
|
|||||||
return props
|
return props
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetClientLicenseEtag() string {
|
func GetClientLicenseEtag(useSanitized bool) string {
|
||||||
value := ""
|
value := ""
|
||||||
|
|
||||||
for k, v := range ClientLicense {
|
lic := ClientLicense
|
||||||
|
|
||||||
|
if useSanitized {
|
||||||
|
lic = GetSanitizedClientLicense()
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range lic {
|
||||||
value += fmt.Sprintf("%s:%s;", k, v)
|
value += fmt.Sprintf("%s:%s;", k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return model.Etag(fmt.Sprintf("%x", md5.Sum([]byte(value))))
|
return model.Etag(fmt.Sprintf("%x", md5.Sum([]byte(value))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSantizedClientLicense() map[string]string {
|
func GetSanitizedClientLicense() map[string]string {
|
||||||
sanitizedLicense := make(map[string]string)
|
sanitizedLicense := make(map[string]string)
|
||||||
|
|
||||||
for k, v := range ClientLicense {
|
for k, v := range ClientLicense {
|
||||||
|
|||||||
@@ -50,18 +50,18 @@ func TestValidateLicense(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClientLicenseEtag(t *testing.T) {
|
func TestClientLicenseEtag(t *testing.T) {
|
||||||
etag1 := GetClientLicenseEtag()
|
etag1 := GetClientLicenseEtag(false)
|
||||||
|
|
||||||
ClientLicense["SomeFeature"] = "true"
|
ClientLicense["SomeFeature"] = "true"
|
||||||
|
|
||||||
etag2 := GetClientLicenseEtag()
|
etag2 := GetClientLicenseEtag(false)
|
||||||
if etag1 == etag2 {
|
if etag1 == etag2 {
|
||||||
t.Fatal("etags should not match")
|
t.Fatal("etags should not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientLicense["SomeFeature"] = "false"
|
ClientLicense["SomeFeature"] = "false"
|
||||||
|
|
||||||
etag3 := GetClientLicenseEtag()
|
etag3 := GetClientLicenseEtag(false)
|
||||||
if etag2 == etag3 {
|
if etag2 == etag3 {
|
||||||
t.Fatal("etags should not match")
|
t.Fatal("etags should not match")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user