blob: 683b574b87f44dbbb65707b7d3313b0c0796509a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright (c) 2017-present 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")
}
}
|