github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/app/license_test.go (about) 1 // Copyright (c) 2016-present Xenia, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "testing" 8 9 "github.com/xzl8028/xenia-server/model" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestLoadLicense(t *testing.T) { 14 th := Setup(t) 15 defer th.TearDown() 16 17 th.App.LoadLicense() 18 if th.App.License() != nil { 19 t.Fatal("shouldn't have a valid license") 20 } 21 } 22 23 func TestSaveLicense(t *testing.T) { 24 th := Setup(t) 25 defer th.TearDown() 26 27 b1 := []byte("junk") 28 29 if _, err := th.App.SaveLicense(b1); err == nil { 30 t.Fatal("shouldn't have saved license") 31 } 32 } 33 34 func TestRemoveLicense(t *testing.T) { 35 th := Setup(t) 36 defer th.TearDown() 37 38 if err := th.App.RemoveLicense(); err != nil { 39 t.Fatal("should have removed license") 40 } 41 } 42 43 func TestSetLicense(t *testing.T) { 44 th := Setup(t) 45 defer th.TearDown() 46 47 l1 := &model.License{} 48 l1.Features = &model.Features{} 49 l1.Customer = &model.Customer{} 50 l1.StartsAt = model.GetMillis() - 1000 51 l1.ExpiresAt = model.GetMillis() + 100000 52 if ok := th.App.SetLicense(l1); !ok { 53 t.Fatal("license should have worked") 54 } 55 56 l3 := &model.License{} 57 l3.Features = &model.Features{} 58 l3.Customer = &model.Customer{} 59 l3.StartsAt = model.GetMillis() + 10000 60 l3.ExpiresAt = model.GetMillis() + 100000 61 if ok := th.App.SetLicense(l3); !ok { 62 t.Fatal("license should have passed") 63 } 64 } 65 66 func TestClientLicenseEtag(t *testing.T) { 67 th := Setup(t) 68 defer th.TearDown() 69 70 etag1 := th.App.GetClientLicenseEtag(false) 71 72 th.App.SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "true"}) 73 74 etag2 := th.App.GetClientLicenseEtag(false) 75 if etag1 == etag2 { 76 t.Fatal("etags should not match") 77 } 78 79 th.App.SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "false"}) 80 81 etag3 := th.App.GetClientLicenseEtag(false) 82 if etag2 == etag3 { 83 t.Fatal("etags should not match") 84 } 85 } 86 87 func TestGetSanitizedClientLicense(t *testing.T) { 88 th := Setup(t) 89 defer th.TearDown() 90 91 l1 := &model.License{} 92 l1.Features = &model.Features{} 93 l1.Customer = &model.Customer{} 94 l1.Customer.Name = "TestName" 95 l1.SkuName = "SKU NAME" 96 l1.SkuShortName = "SKU SHORT NAME" 97 l1.StartsAt = model.GetMillis() - 1000 98 l1.ExpiresAt = model.GetMillis() + 100000 99 th.App.SetLicense(l1) 100 101 m := th.App.GetSanitizedClientLicense() 102 103 _, ok := m["Name"] 104 assert.False(t, ok) 105 _, ok = m["SkuName"] 106 assert.False(t, ok) 107 _, ok = m["SkuShortName"] 108 assert.False(t, ok) 109 }