-
Notifications
You must be signed in to change notification settings - Fork 10
/
sign_test.go
45 lines (38 loc) · 1.71 KB
/
sign_test.go
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
34
35
36
37
38
39
40
41
42
43
44
45
package initdata
import (
"testing"
"time"
)
const (
signTestInitData = "query_id=AAHdF6IQAAAAAN0XohDhrOrc&user=%7B%22id%22%3A279058397%2C%22first_name%22%3A%22Vladislav%22%2C%22last_name%22%3A%22Kibenko%22%2C%22username%22%3A%22vdkfrost%22%2C%22language_code%22%3A%22ru%22%2C%22is_premium%22%3Atrue%7D&auth_date=1662771648"
signTestToken = "5768337691:AAH5YkoiEuPk8-FZa32hStHTqXiLPtAEhx8"
signTestHash = "c501b71e775f74ce10e377dea85a7ea24ecd640b223ea86dfe453e0eaed2e2b2"
)
var (
signTestAuthDate = time.Unix(1662771648, 0)
)
type testSignQueryString struct {
initData string
expectedErr error
}
var testsSignQueryString = []testSignQueryString{
// Default stable case. No fields to sanitize.
{
initData: "query_id=AAHdF6IQAAAAAN0XohDhrOrc&user=%7B%22id%22%3A279058397%2C%22first_name%22%3A%22Vladislav%22%2C%22last_name%22%3A%22Kibenko%22%2C%22username%22%3A%22vdkfrost%22%2C%22language_code%22%3A%22ru%22%2C%22is_premium%22%3Atrue%7D",
},
// Should ignore "auth_date" and "hash" fields.
{
initData: "query_id=AAHdF6IQAAAAAN0XohDhrOrc&user=%7B%22id%22%3A279058397%2C%22first_name%22%3A%22Vladislav%22%2C%22last_name%22%3A%22Kibenko%22%2C%22username%22%3A%22vdkfrost%22%2C%22language_code%22%3A%22ru%22%2C%22is_premium%22%3Atrue%7D&auth_date=1662771648&hash=c501b71e775f74ce10e377dea85a7ea24ecd640b223ea86dfe453e0eaed2e2b2",
},
}
func TestSignQueryString(t *testing.T) {
for _, test := range testsSignQueryString {
hash, err := SignQueryString(test.initData, signTestToken, signTestAuthDate)
if err != test.expectedErr {
t.Errorf("expected error to be %q. Received %q", test.expectedErr, err)
}
if hash != signTestHash {
t.Errorf("expected result to be %+v. Received %+v", signTestHash, hash)
}
}
}