-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_test.go
66 lines (54 loc) · 1.54 KB
/
url_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
package url
import (
"net/url"
"testing"
"time"
)
func TestSign(t *testing.T) {
u, err := url.Parse("https://example.com/path?key=value")
if err != nil {
t.Error(err)
}
signedURL, err := sign(u, 0)
if err != nil {
t.Error(err)
}
// Verify that the "signature" parameter was added to the query string
if signedURL.Query().Get("signature") == "" {
t.Error("signature parameter not added to query string")
}
// Verify that the "key" parameter is in s query string
if signedURL.Query().Get("key") == "" {
t.Error("key parameter was removed from query string")
}
}
func TestSignTemporary(t *testing.T) {
u, err := url.Parse("https://example.com/path?key=value")
if err != nil {
t.Error(err)
}
expiration := time.Hour
signedURL, err := sign(u, expiration)
if err != nil {
t.Error(err)
}
// Verify that the "expires" parameter was added to the query string
if signedURL.Query().Get("expires") == "" {
t.Error("expires parameter not added to query string")
}
// Verify that the "signature" parameter was added to the query string
if signedURL.Query().Get("signature") == "" {
t.Error("signature parameter not added to query string")
}
}
func TestSign_WithExistingSignatureParameter(t *testing.T) {
u, err := url.Parse("https://example.com/path?key=value&signature=abc")
if err != nil {
t.Error(err)
}
_, err = sign(u, 0)
// Verify that the function returns an error when the "signature" parameter already exists in the query string
if err != ErrSignatureExists {
t.Error("expected ErrSignatureExists, got", err)
}
}