-
Notifications
You must be signed in to change notification settings - Fork 91
/
bucket_referer_test.go
110 lines (96 loc) · 2.47 KB
/
bucket_referer_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
package cos
import (
"context"
"encoding/base64"
"encoding/xml"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestBucketService_GetReferer(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
vs := values{
"referer": "",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<RefererConfiguration>
<Status>Enabled</Status>
<RefererType>White-List</RefererType>
<DomainList>
<Domain>*.qq.com</Domain>
<Domain>*.qcloud.com</Domain>
</DomainList>
<EmptyReferConfiguration>Allow</EmptyReferConfiguration>
</RefererConfiguration>`)
})
res, _, err := client.Bucket.GetReferer(context.Background())
if err != nil {
t.Fatalf("Bucket.GetReferer returned error %v", err)
}
want := &BucketGetRefererResult{
XMLName: xml.Name{Local: "RefererConfiguration"},
Status: "Enabled",
RefererType: "White-List",
DomainList: []string{
"*.qq.com",
"*.qcloud.com",
},
EmptyReferConfiguration: "Allow",
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Bucket.GetReferer returned %+v, want %+v", res, want)
}
}
func TestBucketService_PutReferer(t *testing.T) {
setup()
defer teardown()
opt := &BucketPutRefererOptions{
Status: "Enabled",
RefererType: "White-List",
DomainList: []string{
"*.qq.com",
"*.qcloud.com",
},
EmptyReferConfiguration: "Allow",
}
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
vs := values{
"referer": "",
}
testFormValues(t, r, vs)
body := new(BucketPutRefererOptions)
xml.NewDecoder(r.Body).Decode(body)
want := opt
want.XMLName = xml.Name{Local: "RefererConfiguration"}
if !reflect.DeepEqual(body, want) {
t.Errorf("Bucket.PutReferer request\n body: %+v\nwant %+v\n", body, want)
}
})
_, err := client.Bucket.PutReferer(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.PutReferer returned error: %v", err)
}
}
func TestBucketService_DeleteReferer(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
vs := values{
"referer": "",
}
testFormValues(t, r, vs)
if r.Header.Get("Content-Md5") != base64.StdEncoding.EncodeToString(calMD5Digest([]byte(""))) {
t.Errorf("Bucket.DeleteReferer Md5 error")
}
})
_, err := client.Bucket.DeleteReferer(context.Background())
if err != nil {
t.Fatalf("Bucket.DeleteReferer returned error: %v", err)
}
}