-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
object_acl_test.go
174 lines (152 loc) · 4.26 KB
/
object_acl_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package cos
import (
"context"
"encoding/xml"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestObjectService_GetACL(t *testing.T) {
setup()
defer teardown()
name := "test/hello.txt"
mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
vs := values{
"acl": "",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<AccessControlPolicy>
<Owner>
<ID>qcs::cam::uin/100000760461:uin/100000760461</ID>
<DisplayName>qcs::cam::uin/100000760461:uin/100000760461</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RootAccount">
<ID>qcs::cam::uin/100000760461:uin/100000760461</ID>
<DisplayName>qcs::cam::uin/100000760461:uin/100000760461</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RootAccount">
<ID>qcs::cam::uin/100000760461:uin/100000760461</ID>
<DisplayName>qcs::cam::uin/100000760461:uin/100000760461</DisplayName>
</Grantee>
<Permission>READ</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>`)
})
ref, _, err := client.Object.GetACL(context.Background(), name)
if err != nil {
t.Fatalf("Object.GetACL returned error: %v", err)
}
want := &ObjectGetACLResult{
XMLName: xml.Name{Local: "AccessControlPolicy"},
Owner: &Owner{
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
AccessControlList: []ACLGrant{
{
Grantee: &ACLGrantee{
Type: "RootAccount",
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
Permission: "FULL_CONTROL",
},
{
Grantee: &ACLGrantee{
Type: "RootAccount",
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
Permission: "READ",
},
},
}
if !reflect.DeepEqual(ref, want) {
t.Errorf("Object.GetACL returned %+v, want %+v", ref, want)
}
}
func TestObjectService_PutACL_with_header_opt(t *testing.T) {
setup()
defer teardown()
opt := &ObjectPutACLOptions{
Header: &ACLHeaderOptions{
XCosACL: "private",
},
}
name := "test/hello.txt"
mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
vs := values{
"acl": "",
}
testFormValues(t, r, vs)
testHeader(t, r, "x-cos-acl", "private")
want := 0
v, _ := r.Body.Read([]byte{})
if !reflect.DeepEqual(v, want) {
t.Errorf("Object.PutACL request body: %#v, want %#v", v, want)
}
})
_, err := client.Object.PutACL(context.Background(), name, opt)
if err != nil {
t.Fatalf("Object.PutACL returned error: %v", err)
}
}
func TestObjectService_PutACL_with_body_opt(t *testing.T) {
setup()
defer teardown()
opt := &ObjectPutACLOptions{
Body: &ACLXml{
Owner: &Owner{
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
AccessControlList: []ACLGrant{
{
Grantee: &ACLGrantee{
Type: "RootAccount",
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
Permission: "FULL_CONTROL",
},
{
Grantee: &ACLGrantee{
Type: "RootAccount",
ID: "qcs::cam::uin/100000760461:uin/100000760461",
DisplayName: "qcs::cam::uin/100000760461:uin/100000760461",
},
Permission: "READ",
},
},
},
}
name := "test/hello.txt"
mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) {
v := new(ACLXml)
xml.NewDecoder(r.Body).Decode(v)
testMethod(t, r, http.MethodPut)
vs := values{
"acl": "",
}
testFormValues(t, r, vs)
testHeader(t, r, "x-cos-acl", "")
want := opt.Body
want.XMLName = xml.Name{Local: "AccessControlPolicy"}
if !reflect.DeepEqual(v, want) {
t.Errorf("Object.PutACL request body: %+v, want %+v", v, want)
}
})
_, err := client.Object.PutACL(context.Background(), name, opt)
if err != nil {
t.Fatalf("Object.PutACL returned error: %v", err)
}
}