-
Notifications
You must be signed in to change notification settings - Fork 14
/
signer_test.go
125 lines (102 loc) · 2.61 KB
/
signer_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package getstream_test
import (
"github.com/GetStream/stream-go"
"testing"
)
func TestGenerateToken(t *testing.T) {
signer := getstream.Signer{
Secret: "test_secret",
}
token := signer.GenerateToken("some message")
if token != "8SZVOYgCH6gy-ZjBTq_9vydr7TQ" {
t.Fail()
return
}
}
func TestURLSafe(t *testing.T) {
signer := getstream.Signer{}
result := signer.UrlSafe("some+test/string=foo=")
if result != "some-test_string=foo" {
t.Fail()
return
}
}
func TestFeedScopeToken(t *testing.T) {
client, err := getstream.New(&getstream.Config{
APIKey: "a_key",
APISecret: "tfq2sdqpj9g446sbv653x3aqmgn33hsn8uzdc9jpskaw8mj6vsnhzswuwptuj9su",
AppID: "123456",
Location: "us-east"})
if err != nil {
t.Fail()
return
}
feed, err := client.FlatFeed("flat", "bob")
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateFeedScopeToken(
getstream.ScopeContextFeed,
getstream.ScopeActionRead,
feed.FeedIDWithoutColon())
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateFeedScopeToken(
getstream.ScopeContextActivities,
getstream.ScopeActionWrite,
feed.FeedIDWithoutColon())
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateFeedScopeToken(
getstream.ScopeContextFollower,
getstream.ScopeActionDelete,
feed.FeedIDWithoutColon())
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateFeedScopeToken(
getstream.ScopeContextAll,
getstream.ScopeActionAll,
feed.FeedIDWithoutColon())
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateFeedScopeToken(getstream.ScopeContextFeed, getstream.ScopeActionRead, "")
if err != nil {
t.Fail()
}
}
func TestUserScopeToken(t *testing.T) {
client, err := getstream.New(&getstream.Config{
APIKey: "a_key",
APISecret: "tfq2sdqpj9g446sbv653x3aqmgn33hsn8uzdc9jpskaw8mj6vsnhzswuwptuj9su",
AppID: "123456",
Location: "us-east"})
if err != nil {
t.Fail()
return
}
user := "bob"
_, err = client.Signer.GenerateUserScopeToken(getstream.ScopeContextFeed, getstream.ScopeActionRead, user)
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateUserScopeToken(getstream.ScopeContextActivities, getstream.ScopeActionWrite, user)
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateUserScopeToken(getstream.ScopeContextFollower, getstream.ScopeActionDelete, user)
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateUserScopeToken(getstream.ScopeContextAll, getstream.ScopeActionAll, user)
if err != nil {
t.Fail()
}
_, err = client.Signer.GenerateUserScopeToken(getstream.ScopeContextFeed, getstream.ScopeActionRead, "")
if err != nil {
t.Fail()
}
}