PLT-6090 adding ability to read license file from disk (#5895)
* PLT-6090 adding ability to read license file from disk * Fixing unit test that fails only sometimes * Fixing test that fails randomly
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
fa40bfb9e6
Коммит
00bb479989
@@ -12,6 +12,8 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -112,6 +114,31 @@ func ValidateLicense(signed []byte) (bool, string) {
|
||||
return true, string(plaintext)
|
||||
}
|
||||
|
||||
func GetLicenseFileFromDisk(fileName string) []byte {
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
l4g.Error("Failed to open license key from disk at %v err=%v", fileName, err.Error())
|
||||
return nil
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
licenseBytes, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
l4g.Error("Failed to read license key from disk at %v err=%v", fileName, err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
return licenseBytes
|
||||
}
|
||||
|
||||
func GetLicenseFileLocation(fileLocation string) string {
|
||||
if fileLocation == "" {
|
||||
return FindDir("config") + "mattermost.mattermost-license"
|
||||
} else {
|
||||
return fileLocation
|
||||
}
|
||||
}
|
||||
|
||||
func getClientLicense(l *model.License) map[string]string {
|
||||
props := make(map[string]string)
|
||||
|
||||
|
||||
@@ -66,3 +66,31 @@ func TestClientLicenseEtag(t *testing.T) {
|
||||
t.Fatal("etags should not match")
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
fileBytes := GetLicenseFileFromDisk("thisfileshouldnotexist.mattermost-license")
|
||||
if len(fileBytes) > 0 {
|
||||
t.Fatal("invalid bytes")
|
||||
}
|
||||
|
||||
fileBytes = GetLicenseFileFromDisk(FindConfigFile("config.json"))
|
||||
if len(fileBytes) == 0 { // a valid bytes but should be a fail license
|
||||
t.Fatal("invalid bytes")
|
||||
}
|
||||
|
||||
if success, _ := ValidateLicense(fileBytes); success {
|
||||
t.Fatal("should have been an invalid file")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user