-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoints_test.go
124 lines (100 loc) · 2.71 KB
/
endpoints_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
package pubnub
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
type fakeEndpointOpts struct {
pubnub *PubNub
}
func (o *fakeEndpointOpts) buildPath() (string, error) {
return "/my/path", nil
}
func (o *fakeEndpointOpts) buildQuery() (*url.Values, error) {
q := &url.Values{}
q.Set("a", "2")
q.Set("b", "hey")
return q, nil
}
func (o *fakeEndpointOpts) buildBody() ([]byte, error) {
return []byte("myBody"), nil
}
func (o *fakeEndpointOpts) jobQueue() chan *JobQItem {
return o.pubnub.jobQueue
}
func (o *fakeEndpointOpts) config() Config {
return *o.pubnub.Config
}
func (o *fakeEndpointOpts) client() *http.Client {
return o.pubnub.GetClient()
}
func (o *fakeEndpointOpts) validate() error {
return nil
}
func (o *fakeEndpointOpts) context() Context {
return o.context()
}
func (o *fakeEndpointOpts) httpMethod() string {
return "GET"
}
func (o *fakeEndpointOpts) operationType() OperationType {
return PNSubscribeOperation
}
func (o *fakeEndpointOpts) telemetryManager() *TelemetryManager {
return o.pubnub.telemetryManager
}
func xTestBuildURL(t *testing.T) {
assert := assert.New(t)
pnc := NewConfig()
pn := NewPubNub(pnc)
e := &fakeEndpointOpts{
pubnub: pn,
}
url, err := buildURL(e)
assert.Nil(err)
assert.Equal("https://ps.pndsn.com/my/path?a=2&b=hey", url.RequestURI())
}
func TestSignatureV2(t *testing.T) {
assert := assert.New(t)
httpMethod := "POST"
pubKey := "demo"
secKey := "wMfbo9G0xVUG8yfTfYw5qIdfJkTd7A"
path := "/v3/pam/demo/grant"
query := "PoundsSterling=%C2%A313.37×tamp=123456789"
body := `{
"ttl": 1440,
"permissions": {
"resources" : {
"channels": {
"inbox-jay": 3
},
"groups": {},
"users": {},
"spaces": {}
},
"patterns" : {
"channels": {},
"groups": {},
"users": {},
"spaces": {}
},
"meta": {
"user-id": "[email protected]",
"contains-unicode": "The 💩 test."
}
}
}`
sigv2 := createSignatureV2FromStrings(httpMethod, pubKey, secKey, path, query, body, nil)
assert.Equal("v2.k80LsDMD-sImA8rCBj-ntRKhZ8mSjHY8Ivngt9W3Yc4", sigv2)
}
func TestSignatureV2_1(t *testing.T) {
assert := assert.New(t)
httpMethod := "GET"
pubKey := "pub-c-03f156ea-a2e3-4c35-a733-9535824be897"
secKey := "sec-c-MmUxNTZjMmYtNzFkNS00ODkzLWE2YjctNmQ4YzE5NWNmZDA3"
path := "/v1/objects/sub-c-d7da9e58-c997-11e9-a139-dab2c75acd6f/spaces/pandu-ut-sid/users"
query := "l_obj=0.4545555556&l_pam=1.145&pnsdk=PubNubCSharp4.0.34.0&requestid=19e1dee9-2f87-45d6-97e5-3f4d3f9779a2×tamp=1568724043&uuid=mytestuuid"
sigv2 := createSignatureV2FromStrings(httpMethod, pubKey, secKey, path, query, "", nil)
assert.Equal("v2.-S0k_J_rdoXqQTrQ7A3EVNxDSyupCv7OEPpS2EXukm4", sigv2)
}