diff options
Diffstat (limited to 'app/file_test.go')
-rw-r--r-- | app/file_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/file_test.go b/app/file_test.go new file mode 100644 index 000000000..9df03315e --- /dev/null +++ b/app/file_test.go @@ -0,0 +1,33 @@ +// 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") + } +} |