From 0e2b321e6f5ab5983bc3428aa455dac7012c36ee Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 13 Jan 2017 15:17:50 -0500 Subject: Refactor and migrate more functions out of api into app package (#5063) --- app/file_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/file_test.go (limited to 'app/file_test.go') 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") + } +} -- cgit v1.2.3-1-g7c22