// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. package app import ( "testing" "github.com/mattermost/platform/model" ) func TestGeneratePublicLinkHash(t *testing.T) { filename1 := model.NewId() + "/" + model.NewRandomString(16) + ".txt" filename2 := model.NewId() + "/" + model.NewRandomString(16) + ".txt" salt1 := model.NewRandomString(32) salt2 := model.NewRandomString(32) hash1 := GeneratePublicLinkHash(filename1, salt1) hash2 := GeneratePublicLinkHash(filename2, salt1) hash3 := GeneratePublicLinkHash(filename1, salt2) if hash1 != GeneratePublicLinkHash(filename1, salt1) { t.Fatal("hash should be equal for the same file name and salt") } if hash1 == hash2 { t.Fatal("hashes for different files should not be equal") } if hash1 == hash3 { t.Fatal("hashes for the same file with different salts should not be equal") } }