Update client license etag to handle new features (#2716)

Этот коммит содержится в:
Joram Wilander
2016-04-15 08:48:14 -04:00
коммит произвёл Harrison Healey
родитель 9243b8761a
Коммит c6c3f1e478
6 изменённых файлов: 68 добавлений и 15 удалений

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

@@ -153,20 +153,13 @@ func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request) {
config := utils.ClientLicense
var etag string
if config["IsLicensed"] == "false" {
etag = model.Etag(config["IsLicensed"])
} else {
etag = model.Etag(config["IsLicensed"], config["IssuedAt"])
}
etag := utils.GetClientLicenseEtag()
if HandleEtag(etag, w, r) {
return
}
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
clientLicense := utils.ClientLicense
w.Write([]byte(model.MapToJson(config)))
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(model.MapToJson(clientLicense)))
}

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

@@ -4,13 +4,14 @@
package api
import (
"github.com/mattermost/platform/utils"
"testing"
)
func TestGetLicenceConfig(t *testing.T) {
Setup()
if result, err := Client.GetClientLicenceConfig(); err != nil {
if result, err := Client.GetClientLicenceConfig(""); err != nil {
t.Fatal(err)
} else {
cfg := result.Data.(map[string]string)
@@ -18,5 +19,31 @@ func TestGetLicenceConfig(t *testing.T) {
if _, ok := cfg["IsLicensed"]; !ok {
t.Fatal(cfg)
}
// test etag caching
if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
t.Fatal(err)
} else if len(cache_result.Data.(map[string]string)) != 0 {
t.Log(cache_result.Data)
t.Fatal("cache should be empty")
}
utils.ClientLicense["IsLicensed"] = "true"
if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
t.Fatal(err)
} else if len(cache_result.Data.(map[string]string)) == 0 {
t.Fatal("result should not be empty")
}
utils.ClientLicense["SomeFeature"] = "true"
if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
t.Fatal(err)
} else if len(cache_result.Data.(map[string]string)) == 0 {
t.Fatal("result should not be empty")
}
utils.ClientLicense = map[string]string{"IsLicensed": "false"}
}
}