mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* TestGetLicenseFileFromDisk: avoid using fileutils.FindConfigFile * config: abstract config-related file access, extend memory store * simplify config validate to avoid file knowledge * fix relative file tests * cluster: fix ConfigChanged event The old and new configurations were swapped when notifying the enterprise code of configuration changes, creating needless instability in propagating config updates across a cluster. * config/database: ignore duplicates * test cleanup * remove unnecessary Save() in test
58 lines
2.6 KiB
Go
58 lines
2.6 KiB
Go
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateLicense(t *testing.T) {
|
|
b1 := []byte("junk")
|
|
if ok, _ := ValidateLicense(b1); ok {
|
|
t.Fatal("should have failed - bad license")
|
|
}
|
|
|
|
b2 := []byte("junkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunkjunk")
|
|
if ok, _ := ValidateLicense(b2); ok {
|
|
t.Fatal("should have failed - bad license")
|
|
}
|
|
}
|
|
|
|
func TestGetLicenseFileLocation(t *testing.T) {
|
|
fileName := GetLicenseFileLocation("")
|
|
if len(fileName) == 0 {
|
|
t.Fatal("invalid default file name")
|
|
}
|
|
|
|
fileName = GetLicenseFileLocation("mattermost.mattermost-license")
|
|
if fileName != "mattermost.mattermost-license" {
|
|
t.Fatal("invalid file name")
|
|
}
|
|
}
|
|
|
|
func TestGetLicenseFileFromDisk(t *testing.T) {
|
|
t.Run("missing file", func(t *testing.T) {
|
|
fileBytes := GetLicenseFileFromDisk("thisfileshouldnotexist.mattermost-license")
|
|
assert.Empty(t, fileBytes, "invalid bytes")
|
|
})
|
|
|
|
t.Run("not a license file", func(t *testing.T) {
|
|
f, err := ioutil.TempFile("", "TestGetLicenseFileFromDisk")
|
|
require.NoError(t, err)
|
|
defer os.Remove(f.Name())
|
|
ioutil.WriteFile(f.Name(), []byte("not a license"), 0777)
|
|
|
|
fileBytes := GetLicenseFileFromDisk(f.Name())
|
|
require.NotEmpty(t, fileBytes, "should have read the file")
|
|
|
|
success, _ := ValidateLicense(fileBytes)
|
|
assert.False(t, success, "should have been an invalid file")
|
|
})
|
|
}
|