github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/app/license_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/v5/model"
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestLoadLicense(t *testing.T) {
    15  	th := Setup(t)
    16  	defer th.TearDown()
    17  
    18  	th.App.Srv().LoadLicense()
    19  	require.Nil(t, th.App.Srv().License(), "shouldn't have a valid license")
    20  }
    21  
    22  func TestSaveLicense(t *testing.T) {
    23  	th := Setup(t)
    24  	defer th.TearDown()
    25  
    26  	b1 := []byte("junk")
    27  
    28  	_, err := th.App.Srv().SaveLicense(b1)
    29  	require.NotNil(t, err, "shouldn't have saved license")
    30  }
    31  
    32  func TestRemoveLicense(t *testing.T) {
    33  	th := Setup(t)
    34  	defer th.TearDown()
    35  
    36  	err := th.App.Srv().RemoveLicense()
    37  	require.Nil(t, err, "should have removed license")
    38  }
    39  
    40  func TestSetLicense(t *testing.T) {
    41  	th := Setup(t)
    42  	defer th.TearDown()
    43  
    44  	l1 := &model.License{}
    45  	l1.Features = &model.Features{}
    46  	l1.Customer = &model.Customer{}
    47  	l1.StartsAt = model.GetMillis() - 1000
    48  	l1.ExpiresAt = model.GetMillis() + 100000
    49  	ok := th.App.Srv().SetLicense(l1)
    50  	require.True(t, ok, "license should have worked")
    51  
    52  	l3 := &model.License{}
    53  	l3.Features = &model.Features{}
    54  	l3.Customer = &model.Customer{}
    55  	l3.StartsAt = model.GetMillis() + 10000
    56  	l3.ExpiresAt = model.GetMillis() + 100000
    57  	ok = th.App.Srv().SetLicense(l3)
    58  	require.True(t, ok, "license should have passed")
    59  }
    60  
    61  func TestGetSanitizedClientLicense(t *testing.T) {
    62  	th := Setup(t)
    63  	defer th.TearDown()
    64  
    65  	l1 := &model.License{}
    66  	l1.Features = &model.Features{}
    67  	l1.Customer = &model.Customer{}
    68  	l1.Customer.Name = "TestName"
    69  	l1.SkuName = "SKU NAME"
    70  	l1.SkuShortName = "SKU SHORT NAME"
    71  	l1.StartsAt = model.GetMillis() - 1000
    72  	l1.ExpiresAt = model.GetMillis() + 100000
    73  	th.App.Srv().SetLicense(l1)
    74  
    75  	m := th.App.Srv().GetSanitizedClientLicense()
    76  
    77  	_, ok := m["Name"]
    78  	assert.False(t, ok)
    79  	_, ok = m["SkuName"]
    80  	assert.False(t, ok)
    81  	_, ok = m["SkuShortName"]
    82  	assert.False(t, ok)
    83  }