1
|
|
|
<?php |
2
|
|
|
define("ENCRYPTPTION_STORAGE_MODE","InstructionFile"); |
3
|
|
|
require_once "../encryption/EncryptionUtil.php"; |
4
|
|
|
require_once "../Ks3Client.class.php"; |
5
|
|
|
require_once "../Ks3EncryptionClient.class.php"; |
6
|
|
|
require_once "TestUtil.php"; |
7
|
|
|
require_once "PUnit.php"; |
8
|
|
|
require_once "../lib/RequestCore.class.php"; |
9
|
|
|
class SDKTest extends PUnit{ |
10
|
|
|
protected $bucket = "php-sdk-test"; |
11
|
|
|
protected $key = "test==中/文?"; |
12
|
|
|
protected $key_copy = "test中/文_copy?"; |
13
|
|
|
protected $accesskey = ""; |
14
|
|
|
protected $secrectkey = ""; |
15
|
|
|
protected $client; |
16
|
|
|
protected $encryptionClient; |
17
|
|
|
protected $cachedir; |
18
|
|
|
protected $sseckey; |
19
|
|
|
public function __construct(){ |
20
|
|
|
$this->client=new Ks3Client($this->accesskey,$this->secrectkey); |
21
|
|
|
$this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
22
|
|
|
$filename = "secret.key"; |
23
|
|
|
$handle = fopen($filename, "r"); |
24
|
|
|
$sseckey = fread($handle, filesize ($filename)); |
25
|
|
|
fclose($handle); |
26
|
|
|
$this->sseckey = $sseckey; |
27
|
|
|
$this->encryptionClient = new Ks3EncryptionClient($this->accesskey,$this->secrectkey,$sseckey); |
28
|
|
|
} |
29
|
|
|
public function before(){ |
30
|
|
|
if($this->client->bucketExists(array("Bucket"=>$this->bucket))){ |
|
|
|
|
31
|
|
|
$keys = array(); |
32
|
|
|
$objects = $this->client->listObjects(array("Bucket"=>$this->bucket)); |
|
|
|
|
33
|
|
|
foreach ($objects["Contents"] as $object) { |
34
|
|
|
array_push($keys, $object["Key"]); |
35
|
|
|
} |
36
|
|
|
$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
|
|
|
|
37
|
|
|
}else{ |
38
|
|
|
$this->client->createBucket(array("Bucket"=>$this->bucket)); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
public function testListBuckets(){ |
42
|
|
|
$buckets = $this->client->listBuckets(); |
|
|
|
|
43
|
|
|
$found = FALSE; |
44
|
|
|
foreach ($buckets as $bucket) { |
45
|
|
|
if($bucket["Name"] == $this->bucket) |
46
|
|
|
$found = TRUE; |
47
|
|
|
} |
48
|
|
|
if(!$found) |
49
|
|
|
throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
public function testDeleteBucket(){ |
53
|
|
|
$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>"")); |
|
|
|
|
54
|
|
|
$ex = NULL; |
55
|
|
|
try{ |
56
|
|
|
$this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
|
|
|
|
57
|
|
|
}catch(Exception $e){ |
58
|
|
|
$ex = $e; |
59
|
|
|
} |
60
|
|
|
if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
61
|
|
|
throw new Exception("delete bucket expected BucketNotEmpty but ".$ex); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
public function testBucketCORS(){ |
65
|
|
|
$this->client->setBucketCORS($args = array( |
|
|
|
|
66
|
|
|
"Bucket"=>$this->bucket, |
67
|
|
|
"CORS"=>array( |
68
|
|
|
array( |
69
|
|
|
"AllowedMethod"=>array("GET","PUT"), |
70
|
|
|
"AllowedOrigin"=>array("http://www.kingsoft.com"), |
71
|
|
|
"AllowedHeader"=>array("*"), |
72
|
|
|
"ExposeHeader"=>array("*"), |
73
|
|
|
"MaxAgeSeconds"=>10 |
74
|
|
|
), |
75
|
|
|
array( |
76
|
|
|
"AllowedMethod"=>array("GET","PUT"), |
77
|
|
|
"AllowedOrigin"=>array("*"), |
78
|
|
|
"AllowedHeader"=>array("*"), |
79
|
|
|
"ExposeHeader"=>array("*"), |
80
|
|
|
"MaxAgeSeconds"=>10 |
81
|
|
|
) |
82
|
|
|
))); |
83
|
|
|
$cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
|
|
|
|
84
|
|
|
$this->assertEquals(count($cors),2,"bucket cors count "); |
85
|
|
|
$this->client->deleteBucketCORS(array("Bucket"=>$this->bucket)); |
|
|
|
|
86
|
|
|
$cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
87
|
|
|
$this->assertEquals(count($cors),0,"bucket cors count "); |
88
|
|
|
} |
89
|
|
|
public function testCreateBucket(){ |
90
|
|
|
$ex = NULL; |
91
|
|
|
try{ |
92
|
|
|
$this->client->createBucket(array("Bucket"=>$this->bucket)); |
93
|
|
|
}catch(Exception $e){ |
94
|
|
|
$ex = $e; |
95
|
|
|
} |
96
|
|
|
if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
97
|
|
|
throw new Exception("create bucket expected BucketAlreadyExists but ".$ex); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
public function testACL(){ |
101
|
|
|
$this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read")); |
|
|
|
|
102
|
|
|
$acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket)); |
|
|
|
|
103
|
|
|
$this->assertEquals($acl,"public-read","bucket acl"); |
104
|
|
|
} |
105
|
|
|
public function testBucketLogging(){ |
106
|
|
|
$this->client->setBucketLogging(array( |
|
|
|
|
107
|
|
|
"Bucket"=>$this->bucket, |
108
|
|
|
"BucketLogging"=>array( |
109
|
|
|
"Enable"=>TRUE, |
110
|
|
|
"TargetBucket"=>$this->bucket, |
111
|
|
|
"TargetPrefix"=>"X-KSS" |
112
|
|
|
) |
113
|
|
|
)); |
114
|
|
|
$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
|
|
|
|
115
|
|
|
$this->assertEquals($logging["Enable"],TRUE,"bucket logging enable"); |
116
|
|
|
|
117
|
|
|
$this->client->setBucketLogging(array( |
118
|
|
|
"Bucket"=>$this->bucket, |
119
|
|
|
"BucketLogging"=>array( |
120
|
|
|
"Enable"=>FALSE,//是否开启 |
121
|
|
|
) |
122
|
|
|
)); |
123
|
|
|
$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
124
|
|
|
$this->assertEquals($logging["Enable"],FALSE,"bucket logging enable"); |
125
|
|
|
} |
126
|
|
|
public function testBucketLocation(){ |
127
|
|
|
$location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket)); |
|
|
|
|
128
|
|
|
$this->assertEquals($location,"HANGZHOU","bucket location "); |
129
|
|
|
} |
130
|
|
|
public function testPutObjectByContentAndGetObjectContent(){ |
131
|
|
|
$args = array( |
132
|
|
|
"Bucket"=>$this->bucket, |
133
|
|
|
"Key"=>$this->key, |
134
|
|
|
"Content"=>"1234",//要上传的内容 |
135
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
136
|
|
|
"ObjectMeta"=>array( |
137
|
|
|
"Content-Type"=>"application/xml", |
138
|
|
|
"Content-Length"=>3 |
139
|
|
|
), |
140
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
141
|
|
|
"x-kss-meta-test"=>"test" |
142
|
|
|
) |
143
|
|
|
); |
144
|
|
|
$this->client->putObjectByContent($args); |
145
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists "); |
|
|
|
|
146
|
|
|
$meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
|
|
|
147
|
|
|
$this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
148
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
149
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length"); |
150
|
|
|
$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl "); |
|
|
|
|
151
|
|
|
|
152
|
|
|
$s3Object = $this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
|
|
|
153
|
|
|
$this->assertEquals($s3Object["Content"],"123","s3 object content"); |
154
|
|
|
$meta = $s3Object["Meta"]; |
155
|
|
|
$this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
156
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
157
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length"); |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
public function testPutObjectByFile(){ |
161
|
|
|
$args = array( |
162
|
|
|
"Bucket"=>$this->bucket, |
163
|
|
|
"Key"=>$this->key, |
164
|
|
|
"Content"=>array( |
165
|
|
|
"content"=>$this->cachedir."test_file" |
166
|
|
|
),//要上传的内容 |
167
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
168
|
|
|
"ObjectMeta"=>array( |
169
|
|
|
"Content-Type"=>"application/xml", |
170
|
|
|
"Content-Length"=>100 |
171
|
|
|
), |
172
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
173
|
|
|
"x-kss-meta-test"=>"test" |
174
|
|
|
) |
175
|
|
|
); |
176
|
|
|
$this->client->putObjectByFile($args); |
|
|
|
|
177
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists "); |
178
|
|
|
$meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
179
|
|
|
$this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
180
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
181
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Length"],100,"Content-Length"); |
182
|
|
|
$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl "); |
183
|
|
|
} |
184
|
|
|
public function testObjectAcl(){ |
185
|
|
|
$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
186
|
|
|
"Content"=>"1234","ACL"=>"private")); |
187
|
|
|
$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl"); |
188
|
|
|
$this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read")); |
|
|
|
|
189
|
|
|
$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
190
|
|
|
} |
191
|
|
|
public function testDeleteObject(){ |
192
|
|
|
$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
193
|
|
|
"Content"=>"1234")); |
194
|
|
|
$this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
|
|
|
195
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
196
|
|
|
} |
197
|
|
|
public function testDeleteObjects(){ |
198
|
|
|
$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
199
|
|
|
"Content"=>"1234")); |
200
|
|
|
$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key))); |
201
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
202
|
|
|
} |
203
|
|
|
public function testCopyObject(){ |
204
|
|
|
$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
205
|
|
|
"Content"=>"1234")); |
206
|
|
|
$this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key))); |
|
|
|
|
207
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits"); |
208
|
|
|
$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE |
209
|
|
|
,"object exits"); |
210
|
|
|
} |
211
|
|
|
public function testPutAndGetObject(){ |
212
|
|
|
$args = array( |
213
|
|
|
"Bucket"=>$this->bucket, |
214
|
|
|
"Key"=>$this->key, |
215
|
|
|
"Content"=>array( |
216
|
|
|
"content"=>$this->cachedir."test_file" |
217
|
|
|
),//要上传的内容 |
218
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
219
|
|
|
"ObjectMeta"=>array( |
220
|
|
|
"Content-Type"=>"application/xml", |
221
|
|
|
), |
222
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
223
|
|
|
"x-kss-meta-test"=>"test" |
224
|
|
|
) |
225
|
|
|
); |
226
|
|
|
$this->client->putObjectByFile($args); |
227
|
|
|
$this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key,"WriteTo"=>$this->cachedir."down")); |
228
|
|
|
$md5 = md5_file($this->cachedir."down"); |
229
|
|
|
$md5pre = md5_file($this->cachedir."test_file"); |
230
|
|
|
@unlink($this->cachedir."down"); |
|
|
|
|
231
|
|
|
$this->assertEquals($md5,$md5pre,"contentmd5"); |
232
|
|
|
} |
233
|
|
|
public function testPutAndGetObjectRanges(){ |
234
|
|
|
$args = array( |
235
|
|
|
"Bucket"=>$this->bucket, |
236
|
|
|
"Key"=>$this->key, |
237
|
|
|
"Content"=>array( |
238
|
|
|
"content"=>$this->cachedir."test_file" |
239
|
|
|
),//要上传的内容 |
240
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
241
|
|
|
"ObjectMeta"=>array( |
242
|
|
|
"Content-Type"=>"application/xml", |
243
|
|
|
), |
244
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
245
|
|
|
"x-kss-meta-test"=>"test" |
246
|
|
|
) |
247
|
|
|
); |
248
|
|
|
$this->client->putObjectByFile($args); |
249
|
|
|
rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."test_file")); |
250
|
|
|
} |
251
|
|
|
public function testInitAndAbortMultipart(){ |
252
|
|
|
$initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
|
|
|
253
|
|
|
$uid = $initResult["UploadId"]; |
254
|
|
|
$listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
|
|
|
255
|
|
|
$this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
|
|
|
256
|
|
|
$ex = NULL; |
257
|
|
|
try{ |
258
|
|
|
$this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
259
|
|
|
}catch(Exception $e){ |
260
|
|
|
$ex = $e; |
261
|
|
|
} |
262
|
|
|
if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
263
|
|
|
throw new Exception("create bucket expected NoSuchUpload but ".$ex); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
public function testMultipartUpload(){ |
267
|
|
|
generateFile(1024*1024,$this->cachedir."multi"); |
268
|
|
|
//初始化分开上传,获取uploadid |
269
|
|
|
$args = array( |
270
|
|
|
"Bucket"=>$this->bucket, |
271
|
|
|
"Key"=>$this->key, |
272
|
|
|
"ACL"=>"public-read", |
273
|
|
|
"UserMeta"=>array( |
274
|
|
|
"x-kss-meta-test"=>"example" |
275
|
|
|
), |
276
|
|
|
"ObjectMeta"=>array( |
277
|
|
|
"Content-Type"=>"application/xml" |
278
|
|
|
) |
279
|
|
|
); |
280
|
|
|
$uploadid = $this->client->initMultipartUpload($args); |
281
|
|
|
$uploadid = $uploadid["UploadId"];//获取到uploadid |
282
|
|
|
//开始上传 |
283
|
|
|
$file = $this->cachedir."multi";//要上传的文件 |
284
|
|
|
$partsize = 1024*100; |
285
|
|
|
$resource = fopen($file,"r"); |
286
|
|
|
$stat = fstat($resource); |
287
|
|
|
$total = $stat["size"];//获取文件的总大小 |
288
|
|
|
fclose($resource); |
289
|
|
|
$count = (int)(($total-1)/$partsize)+1;;//计算文件需要分几块上传 |
290
|
|
|
for($i = 0;$i < $count;$i++){ |
291
|
|
|
//依次上传每一块 |
292
|
|
|
$args=array( |
293
|
|
|
"Bucket"=>$this->bucket, |
294
|
|
|
"Key"=>$this->key, |
295
|
|
|
"Options"=>array( |
296
|
|
|
"partNumber"=>$i+1, |
297
|
|
|
"uploadId"=>$uploadid |
298
|
|
|
), |
299
|
|
|
"ObjectMeta"=>array( |
300
|
|
|
"Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
301
|
|
|
), |
302
|
|
|
"Content"=>array( |
303
|
|
|
"content"=>$file, |
304
|
|
|
"seek_position"=>$partsize*$i//跳过之前已经上传的 |
305
|
|
|
) |
306
|
|
|
); |
307
|
|
|
$etag = $this->client->uploadPart($args); |
|
|
|
|
308
|
|
|
$etag = $etag["ETag"]; |
|
|
|
|
309
|
|
|
} |
310
|
|
|
$parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
311
|
|
|
//结束上传 |
312
|
|
|
$args=array( |
313
|
|
|
"Bucket"=>$this->bucket, |
314
|
|
|
"Key"=>$this->key, |
315
|
|
|
"Options"=>array("uploadId"=>$uploadid), |
316
|
|
|
"Parts"=>$parts["Parts"]//使用之前列出的块完成分开上传 |
317
|
|
|
); |
318
|
|
|
$result = $this->client->completeMultipartUpload($args); |
|
|
|
|
319
|
|
|
$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
320
|
|
|
$meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
321
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
322
|
|
|
$this->assertEquals($meta["ObjectMeta"]["Content-Length"],filesize($this->cachedir."multi"),"Content-Length"); |
323
|
|
|
$this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"example","x-kss-meta-test"); |
324
|
|
|
rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."multi")); |
325
|
|
|
@unlink($this->cachedir."multi"); |
|
|
|
|
326
|
|
|
} |
327
|
|
|
public function testListBucketsPresignedUrl(){ |
328
|
|
|
$url = $this->client->generatePresignedUrl( |
|
|
|
|
329
|
|
|
array( |
330
|
|
|
"Method"=>"GET", |
331
|
|
|
"Options"=>array("Expires"=>60*10), |
332
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
333
|
|
|
)); |
334
|
|
|
$httpRequest = new RequestCore($url); |
335
|
|
|
$httpRequest->set_method("GET"); |
336
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
337
|
|
|
$httpRequest->send_request(); |
338
|
|
|
$body = $httpRequest->get_response_body (); |
339
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code"); |
340
|
|
|
} |
341
|
|
|
public function testHeadBucketPresignedUrl(){ |
342
|
|
|
$url = $this->client->generatePresignedUrl( |
343
|
|
|
array( |
344
|
|
|
"Method"=>"HEAD", |
345
|
|
|
"Bucket"=>$this->bucket, |
346
|
|
|
"Options"=>array("Expires"=>60*10), |
347
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
348
|
|
|
) |
349
|
|
|
); |
350
|
|
|
$httpRequest = new RequestCore($url); |
351
|
|
|
$httpRequest->set_method("HEAD"); |
352
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
353
|
|
|
$httpRequest->send_request(); |
354
|
|
|
$body = $httpRequest->get_response_body (); |
355
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head bucket status code"); |
356
|
|
|
} |
357
|
|
|
public function testDeleteBucketPresignedUrl(){ |
358
|
|
|
$this->client->putObjectByContent(array( |
359
|
|
|
"Bucket"=>$this->bucket, |
360
|
|
|
"Key"=>$this->key, |
361
|
|
|
"Content"=>"123" |
362
|
|
|
) |
363
|
|
|
); |
364
|
|
|
$url = $this->client->generatePresignedUrl( |
365
|
|
|
array( |
366
|
|
|
"Method"=>"DELETE", |
367
|
|
|
"Bucket"=>$this->bucket, |
368
|
|
|
"Options"=>array("Expires"=>60*10), |
369
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
370
|
|
|
) |
371
|
|
|
); |
372
|
|
|
$httpRequest = new RequestCore($url); |
373
|
|
|
$httpRequest->set_method("DELETE"); |
374
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
375
|
|
|
$httpRequest->send_request(); |
376
|
|
|
$body = $httpRequest->get_response_body (); |
377
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code"); |
378
|
|
|
} |
379
|
|
|
public function testGetBucketAclPresignedUrl(){ |
380
|
|
|
$url = $this->client->generatePresignedUrl( |
381
|
|
|
array( |
382
|
|
|
"Method"=>"GET", |
383
|
|
|
"Bucket"=>$this->bucket, |
384
|
|
|
"Options"=>array("Expires"=>60*10,"acl"=>NULL), |
385
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
386
|
|
|
) |
387
|
|
|
); |
388
|
|
|
$httpRequest = new RequestCore($url); |
389
|
|
|
$httpRequest->set_method("GET"); |
390
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
391
|
|
|
$httpRequest->send_request(); |
392
|
|
|
$body = $httpRequest->get_response_body (); |
393
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket acl status code"); |
394
|
|
|
} |
395
|
|
|
public function testPutBucketPresignedUrl(){ |
396
|
|
|
$url = $this->client->generatePresignedUrl( |
397
|
|
|
array( |
398
|
|
|
"Method"=>"PUT", |
399
|
|
|
"Bucket"=>$this->bucket, |
400
|
|
|
"Options"=>array("Expires"=>60*10), |
401
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
402
|
|
|
) |
403
|
|
|
); |
404
|
|
|
$httpRequest = new RequestCore($url); |
405
|
|
|
$httpRequest->set_method("PUT"); |
406
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
407
|
|
|
$httpRequest->send_request(); |
408
|
|
|
$body = $httpRequest->get_response_body (); |
409
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code"); |
410
|
|
|
} |
411
|
|
|
public function testPutBucketAclPresignedUrl(){ |
412
|
|
|
$url = $this->client->generatePresignedUrl( |
413
|
|
|
array( |
414
|
|
|
"Method"=>"PUT", |
415
|
|
|
"Bucket"=>$this->bucket, |
416
|
|
|
"Options"=>array("Expires"=>60*10,"acl"=>NULL), |
417
|
|
|
"Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read") |
418
|
|
|
) |
419
|
|
|
); |
420
|
|
|
$httpRequest = new RequestCore($url); |
421
|
|
|
$httpRequest->set_method("PUT"); |
422
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
423
|
|
|
$httpRequest->add_header("x-kss-acl","public-read"); |
424
|
|
|
$httpRequest->send_request(); |
425
|
|
|
$body = $httpRequest->get_response_body (); |
426
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket acl status code"); |
427
|
|
|
$this->assertEquals($this->client->getBucketAcl(array("Bucket"=>$this->bucket)),"public-read","bucket acl"); |
428
|
|
|
} |
429
|
|
|
public function testListObjectsPresignedUrl(){ |
430
|
|
|
$url = $this->client->generatePresignedUrl(array( |
431
|
|
|
"Method"=>"GET", |
432
|
|
|
"Bucket"=>$this->bucket, |
433
|
|
|
"Options"=>array("Expires"=>60*10,"delimiter"=>"/"), |
434
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
435
|
|
|
) |
436
|
|
|
); |
437
|
|
|
$httpRequest = new RequestCore($url); |
438
|
|
|
$httpRequest->set_method("GET"); |
439
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
440
|
|
|
$httpRequest->send_request(); |
441
|
|
|
$body = $httpRequest->get_response_body (); |
442
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list objects status code"); |
443
|
|
|
} |
444
|
|
|
public function testGetBucketLoggingPresignedUrl(){ |
445
|
|
|
$url = $this->client->generatePresignedUrl(array( |
446
|
|
|
"Method"=>"GET", |
447
|
|
|
"Bucket"=>$this->bucket, |
448
|
|
|
"Options"=>array("Expires"=>60*10,"logging"=>""), |
449
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
450
|
|
|
) |
451
|
|
|
); |
452
|
|
|
$httpRequest = new RequestCore($url); |
453
|
|
|
$httpRequest->set_method("GET"); |
454
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
455
|
|
|
$httpRequest->send_request(); |
456
|
|
|
$body = $httpRequest->get_response_body (); |
457
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket logging status code"); |
458
|
|
|
} |
459
|
|
|
public function testPutBucketLoggingPresignedUrl(){ |
460
|
|
|
$xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />'); |
461
|
|
|
$xml = $xml->asXml(); |
462
|
|
|
$url = $this->client->generatePresignedUrl( |
463
|
|
|
array( |
464
|
|
|
"Method"=>"PUT", |
465
|
|
|
"Bucket"=>$this->bucket, |
466
|
|
|
"Options"=>array("Expires"=>60*10,"logging"=>NULL), |
467
|
|
|
"Headers"=>array("Content-Type"=>"application/xml") |
468
|
|
|
) |
469
|
|
|
); |
470
|
|
|
$httpRequest = new RequestCore($url); |
471
|
|
|
$httpRequest->set_method("PUT"); |
472
|
|
|
$httpRequest->add_header("Content-Type","application/xml"); |
473
|
|
|
$httpRequest->add_header("Content-Length",strlen($xml)); |
|
|
|
|
474
|
|
|
$httpRequest->request_body=$xml; |
475
|
|
|
$httpRequest->send_request(); |
476
|
|
|
$body = $httpRequest->get_response_body (); |
477
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket logging status code"); |
478
|
|
|
} |
479
|
|
|
public function testGetBucketLocationPresignedUrl(){ |
480
|
|
|
$url = $this->client->generatePresignedUrl( |
481
|
|
|
array( |
482
|
|
|
"Method"=>"GET", |
483
|
|
|
"Bucket"=>$this->bucket, |
484
|
|
|
"Options"=>array("Expires"=>60*10,"location"=>NULL), |
485
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
486
|
|
|
) |
487
|
|
|
); |
488
|
|
|
$httpRequest = new RequestCore($url); |
489
|
|
|
$httpRequest->set_method("GET"); |
490
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
491
|
|
|
$httpRequest->send_request(); |
492
|
|
|
$body = $httpRequest->get_response_body (); |
493
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket location status code"); |
494
|
|
|
} |
495
|
|
|
public function testDeleteObjectPresignedUrl(){ |
496
|
|
|
$this->client->putObjectByContent(array( |
497
|
|
|
"Bucket"=>$this->bucket, |
498
|
|
|
"Key"=>$this->key, |
499
|
|
|
"Content"=>"123" |
500
|
|
|
) |
501
|
|
|
); |
502
|
|
|
$url = $this->client->generatePresignedUrl( |
503
|
|
|
array( |
504
|
|
|
"Method"=>"DELETE", |
505
|
|
|
"Bucket"=>$this->bucket, |
506
|
|
|
"Key"=>$this->key, |
507
|
|
|
"Options"=>array("Expires"=>60*10), |
508
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
509
|
|
|
) |
510
|
|
|
); |
511
|
|
|
$httpRequest = new RequestCore($url); |
512
|
|
|
$httpRequest->set_method("DELETE"); |
513
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
514
|
|
|
$httpRequest->send_request(); |
515
|
|
|
$body = $httpRequest->get_response_body (); |
516
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,204,"delete object status code"); |
517
|
|
|
} |
518
|
|
|
public function testGetObjectPresignedUrl(){ |
519
|
|
|
$this->client->putObjectByContent(array( |
520
|
|
|
"Bucket"=>$this->bucket, |
521
|
|
|
"Key"=>$this->key, |
522
|
|
|
"Content"=>"123" |
523
|
|
|
) |
524
|
|
|
); |
525
|
|
|
$url = $this->client->generatePresignedUrl( |
526
|
|
|
array( |
527
|
|
|
"Bucket"=>$this->bucket, |
528
|
|
|
"Key"=>$this->key, |
529
|
|
|
"Options"=>array("Expires"=>60*10), |
530
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
531
|
|
|
) |
532
|
|
|
); |
533
|
|
|
$httpRequest = new RequestCore($url); |
534
|
|
|
$httpRequest->set_method("GET"); |
535
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
536
|
|
|
$httpRequest->send_request(); |
537
|
|
|
$body = $httpRequest->get_response_body (); |
538
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object status code"); |
539
|
|
|
$this->assertEquals($body,"123","get object body"); |
540
|
|
|
} |
541
|
|
|
public function testPutObjectPresignedUrl(){ |
542
|
|
|
$body = "123"; |
543
|
|
|
$url = $this->client->generatePresignedUrl( |
544
|
|
|
array( |
545
|
|
|
"Method"=>"PUT", |
546
|
|
|
"Bucket"=>$this->bucket, |
547
|
|
|
"Key"=>$this->key, |
548
|
|
|
"Options"=>array("Expires"=>60*10), |
549
|
|
|
"Headers"=>array("Content-Type"=>"application/ocet-stream") |
550
|
|
|
) |
551
|
|
|
); |
552
|
|
|
$httpRequest = new RequestCore($url); |
553
|
|
|
$httpRequest->set_method("PUT"); |
554
|
|
|
$httpRequest->add_header("Content-Type","application/ocet-stream"); |
555
|
|
|
$httpRequest->add_header("Content-Length",strlen($body)); |
556
|
|
|
$httpRequest->request_body=$body; |
557
|
|
|
$httpRequest->send_request(); |
558
|
|
|
$body = $httpRequest->get_response_body (); |
559
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object status code"); |
560
|
|
|
} |
561
|
|
|
public function testHeadObjectPresignedUrl(){ |
562
|
|
|
$this->testPutObjectPresignedUrl(); |
563
|
|
|
$url = $this->client->generatePresignedUrl( |
564
|
|
|
array( |
565
|
|
|
"Method"=>"HEAD", |
566
|
|
|
"Bucket"=>$this->bucket, |
567
|
|
|
"Key"=>$this->key, |
568
|
|
|
"Options"=>array("Expires"=>60*10), |
569
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
570
|
|
|
) |
571
|
|
|
); |
572
|
|
|
$httpRequest = new RequestCore($url); |
573
|
|
|
$httpRequest->set_method("HEAD"); |
574
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
575
|
|
|
$httpRequest->send_request(); |
576
|
|
|
$body = $httpRequest->get_response_body (); |
577
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head object status code"); |
578
|
|
|
} |
579
|
|
|
public function testGetObjectAclPresignedUrl(){ |
580
|
|
|
$this->testPutObjectPresignedUrl(); |
581
|
|
|
$url = $this->client->generatePresignedUrl( |
582
|
|
|
array( |
583
|
|
|
"Method"=>"GET", |
584
|
|
|
"Bucket"=>$this->bucket, |
585
|
|
|
"Key"=>$this->key, |
586
|
|
|
"Options"=>array("Expires"=>60*10,"acl"=>NULL), |
587
|
|
|
"Headers"=>array("Content-Type"=>"text/plain") |
588
|
|
|
) |
589
|
|
|
); |
590
|
|
|
$httpRequest = new RequestCore($url); |
591
|
|
|
$httpRequest->set_method("GET"); |
592
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
593
|
|
|
$httpRequest->send_request(); |
594
|
|
|
$body = $httpRequest->get_response_body (); |
595
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object acl status code"); |
596
|
|
|
} |
597
|
|
|
public function testPutObjectAclPresignedUrl(){ |
598
|
|
|
$this->testPutObjectPresignedUrl(); |
599
|
|
|
$url = $this->client->generatePresignedUrl( |
600
|
|
|
array( |
601
|
|
|
"Method"=>"PUT", |
602
|
|
|
"Bucket"=>$this->bucket, |
603
|
|
|
"Key"=>$this->key, |
604
|
|
|
"Options"=>array("Expires"=>60*10,"acl"=>NULL), |
605
|
|
|
"Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read") |
606
|
|
|
) |
607
|
|
|
); |
608
|
|
|
$httpRequest = new RequestCore($url); |
609
|
|
|
$httpRequest->set_method("PUT"); |
610
|
|
|
$httpRequest->add_header("Content-Type","text/plain"); |
611
|
|
|
$httpRequest->add_header("x-kss-acl","public-read"); |
612
|
|
|
$httpRequest->send_request(); |
613
|
|
|
$body = $httpRequest->get_response_body (); |
614
|
|
|
$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object acl status code"); |
615
|
|
|
} |
616
|
|
|
public function testPutObjectSSEAndGetHeadObject(){ |
617
|
|
|
$args = array( |
618
|
|
|
"Bucket"=>$this->bucket, |
619
|
|
|
"Key"=>$this->key, |
620
|
|
|
"Content"=>"12345",//要上传的内容 |
621
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
622
|
|
|
"ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
623
|
|
|
"Content-Type"=>"binay/ocet-stream" |
624
|
|
|
), |
625
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
626
|
|
|
"x-kss-meta-test"=>"test" |
627
|
|
|
), |
628
|
|
|
"SSE"=>array( |
629
|
|
|
"Algm"=>"AES256"//暂时支持AES256 |
630
|
|
|
) |
631
|
|
|
); |
632
|
|
|
$result = $this->client->putObjectByContent($args); |
633
|
|
|
$this->assertEquals($result["SSEAlgm"],"AES256"); |
634
|
|
|
|
635
|
|
|
$args = array( |
636
|
|
|
"Bucket"=>$this->bucket, |
637
|
|
|
"Key"=>$this->key |
638
|
|
|
); |
639
|
|
|
$result = $this->client->getObjectMeta($args); |
640
|
|
|
$this->assertEquals($result["ObjectMeta"]["SSEAlgm"],"AES256"); |
641
|
|
|
rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5("12345")); |
642
|
|
|
} |
643
|
|
|
public function testPutObjectSSECAndGetHeadObject(){ |
644
|
|
|
$args = array( |
645
|
|
|
"Bucket"=>$this->bucket, |
646
|
|
|
"Key"=>$this->key, |
647
|
|
|
"Content"=>"12345",//要上传的内容 |
648
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
649
|
|
|
"ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
650
|
|
|
"Content-Type"=>"binay/ocet-stream" |
651
|
|
|
), |
652
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
653
|
|
|
"x-kss-meta-test"=>"test" |
654
|
|
|
), |
655
|
|
|
"SSEC"=>array( |
656
|
|
|
"Key"=>$this->sseckey |
657
|
|
|
) |
658
|
|
|
); |
659
|
|
|
$result = $this->client->putObjectByContent($args); |
660
|
|
|
$this->assertEquals($result["SSECAlgm"],"AES256"); |
661
|
|
|
$this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
662
|
|
|
|
663
|
|
|
$args = array( |
664
|
|
|
"Bucket"=>$this->bucket, |
665
|
|
|
"Key"=>$this->key, |
666
|
|
|
"SSEC"=>array( |
667
|
|
|
"Key"=>$this->sseckey |
668
|
|
|
) |
669
|
|
|
); |
670
|
|
|
$result = $this->client->getObjectMeta($args); |
671
|
|
|
$this->assertEquals($result["ObjectMeta"]["SSECAlgm"],"AES256"); |
672
|
|
|
$this->assertEquals($result["ObjectMeta"]["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
673
|
|
|
|
674
|
|
|
$args = array( |
675
|
|
|
"Bucket"=>$this->bucket, |
676
|
|
|
"Key"=>$this->key, |
677
|
|
|
"WriteTo"=>$this->cachedir."down", //文件保存路径,必须提供。可以是resource |
678
|
|
|
"SSEC"=>array( |
679
|
|
|
"Key"=>$this->sseckey |
680
|
|
|
) |
681
|
|
|
); |
682
|
|
|
$this->client->getObject($args); |
683
|
|
|
$this->assertEquals("12345",file_get_contents($this->cachedir."down")); |
684
|
|
|
@unlink($this->cachedir."down"); |
|
|
|
|
685
|
|
|
} |
686
|
|
|
public function testMultipartUploadSSE(){ |
687
|
|
|
$file = $this->cachedir."test_file"; |
688
|
|
|
$args = array( |
689
|
|
|
"Bucket"=>$this->bucket, |
690
|
|
|
"Key"=>$this->key, |
691
|
|
|
"SSE"=>array( |
692
|
|
|
"Algm"=>"AES256" |
693
|
|
|
) |
694
|
|
|
); |
695
|
|
|
$uploadid = $this->client->initMultipartUpload($args); |
696
|
|
|
|
697
|
|
|
$this->assertEquals($uploadid["SSEAlgm"],"AES256"); |
698
|
|
|
|
699
|
|
|
$uploadid = $uploadid["UploadId"]; |
700
|
|
|
//开始上传 |
701
|
|
|
$args=array( |
702
|
|
|
"Bucket"=>$this->bucket, |
703
|
|
|
"Key"=>$this->key, |
704
|
|
|
"Options"=>array( |
705
|
|
|
"partNumber"=>1, |
706
|
|
|
"uploadId"=>$uploadid |
707
|
|
|
), |
708
|
|
|
"Content"=>array( |
709
|
|
|
"content"=>$file |
710
|
|
|
) |
711
|
|
|
); |
712
|
|
|
$etag = $this->client->uploadPart($args); |
713
|
|
|
|
714
|
|
|
$this->assertEquals($etag["SSEAlgm"],"AES256"); |
715
|
|
|
$etag = $etag["ETag"]; |
|
|
|
|
716
|
|
|
|
717
|
|
|
$parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
718
|
|
|
//结束上传 |
719
|
|
|
$args=array( |
720
|
|
|
"Bucket"=>$this->bucket, |
721
|
|
|
"Key"=>$this->key, |
722
|
|
|
"Options"=>array("uploadId"=>$uploadid), |
723
|
|
|
"Parts"=>$parts["Parts"], |
724
|
|
|
); |
725
|
|
|
$result = $this->client->completeMultipartUpload($args); |
726
|
|
|
$this->assertEquals($result["SSEAlgm"],"AES256"); |
727
|
|
|
} |
728
|
|
|
public function testMultipartUploadSSEC(){ |
729
|
|
|
$file = $this->cachedir."test_file"; |
730
|
|
|
$args = array( |
731
|
|
|
"Bucket"=>$this->bucket, |
732
|
|
|
"Key"=>$this->key, |
733
|
|
|
"SSEC"=>array( |
734
|
|
|
"Key"=>$this->sseckey |
735
|
|
|
) |
736
|
|
|
); |
737
|
|
|
$uploadid = $this->client->initMultipartUpload($args); |
738
|
|
|
|
739
|
|
|
$this->assertEquals($uploadid["SSECAlgm"],"AES256"); |
740
|
|
|
$this->assertEquals($uploadid["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
741
|
|
|
|
742
|
|
|
$uploadid = $uploadid["UploadId"]; |
743
|
|
|
//开始上传 |
744
|
|
|
$args=array( |
745
|
|
|
"Bucket"=>$this->bucket, |
746
|
|
|
"Key"=>$this->key, |
747
|
|
|
"Options"=>array( |
748
|
|
|
"partNumber"=>1, |
749
|
|
|
"uploadId"=>$uploadid |
750
|
|
|
), |
751
|
|
|
"Content"=>array( |
752
|
|
|
"content"=>$file |
753
|
|
|
), |
754
|
|
|
"SSEC"=>array( |
755
|
|
|
"Key"=>$this->sseckey |
756
|
|
|
) |
757
|
|
|
); |
758
|
|
|
$etag = $this->client->uploadPart($args); |
759
|
|
|
|
760
|
|
|
$this->assertEquals($etag["SSECAlgm"],"AES256"); |
761
|
|
|
$this->assertEquals($etag["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
762
|
|
|
|
763
|
|
|
$etag = $etag["ETag"]; |
|
|
|
|
764
|
|
|
|
765
|
|
|
$parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
766
|
|
|
//结束上传 |
767
|
|
|
$args=array( |
768
|
|
|
"Bucket"=>$this->bucket, |
769
|
|
|
"Key"=>$this->key, |
770
|
|
|
"Options"=>array("uploadId"=>$uploadid), |
771
|
|
|
"Parts"=>$parts["Parts"], |
772
|
|
|
); |
773
|
|
|
$result = $this->client->completeMultipartUpload($args); |
774
|
|
|
$this->assertEquals($result["SSECAlgm"],"AES256"); |
775
|
|
|
$this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
776
|
|
|
} |
777
|
|
|
public function testCopySSECObject(){ |
778
|
|
|
$args = array( |
779
|
|
|
"Bucket"=>$this->bucket, |
780
|
|
|
"Key"=>$this->key, |
781
|
|
|
"Content"=>"12345",//要上传的内容 |
782
|
|
|
"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
783
|
|
|
"ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
784
|
|
|
"Content-Type"=>"binay/ocet-stream" |
785
|
|
|
), |
786
|
|
|
"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
787
|
|
|
"x-kss-meta-test"=>"test" |
788
|
|
|
), |
789
|
|
|
"SSEC"=>array( |
790
|
|
|
"Key"=>$this->sseckey |
791
|
|
|
) |
792
|
|
|
); |
793
|
|
|
$result = $this->client->putObjectByContent($args); |
|
|
|
|
794
|
|
|
|
795
|
|
|
$args = array( |
796
|
|
|
"Bucket"=>$this->bucket, |
797
|
|
|
"Key"=>"copy".$this->key_copy, |
798
|
|
|
"CopySource"=>array( |
799
|
|
|
"Bucket"=>$this->bucket, |
800
|
|
|
"Key"=>$this->key |
801
|
|
|
), |
802
|
|
|
"SSECSource"=>array( |
803
|
|
|
"Key"=>$this->sseckey |
804
|
|
|
), |
805
|
|
|
"SSEC"=>array( |
806
|
|
|
"Key"=>$this->sseckey |
807
|
|
|
) |
808
|
|
|
); |
809
|
|
|
$result = $this->client->copyObject($args); |
810
|
|
|
} |
811
|
|
|
public function testPutObjectByContentAndGetObjectUsingEncyptionMeta(){ |
812
|
|
|
for($i = 45 ;$i < 60;$i++){ |
813
|
|
|
|
814
|
|
|
$content = EncryptionUtil::genereateOnceUsedKey($i); |
815
|
|
|
|
816
|
|
|
$args = array( |
817
|
|
|
"Bucket"=>$this->bucket, |
818
|
|
|
"Key"=>$this->key, |
819
|
|
|
"ACL"=>"public-read", |
820
|
|
|
"Content"=>$content |
821
|
|
|
); |
822
|
|
|
$this->encryptionClient->putObjectByContent($args); |
823
|
|
|
rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
824
|
|
|
$this->cachedir."down",md5($args["Content"])); |
825
|
|
|
} |
826
|
|
|
} |
827
|
|
|
public function testPutObjectByFileAndGetObjectUsingEncyptionMeta(){ |
828
|
|
|
$args = array( |
829
|
|
|
"Bucket"=>$this->bucket, |
830
|
|
|
"Key"=>$this->key, |
831
|
|
|
"ACL"=>"public-read", |
832
|
|
|
"Content"=>array( |
833
|
|
|
"content"=>$this->cachedir."test_file" |
834
|
|
|
) |
835
|
|
|
); |
836
|
|
|
$this->encryptionClient->putObjectByFile($args); |
837
|
|
|
rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
838
|
|
|
$this->cachedir."down",md5_file($this->cachedir."test_file")); |
839
|
|
|
} |
840
|
|
|
public function testMultipartUploadUsingEncyptionMeta(){ |
841
|
|
|
generateFile(1024*1024,$this->cachedir."multi"); |
842
|
|
|
//初始化分开上传,获取uploadid |
843
|
|
|
$args = array( |
844
|
|
|
"Bucket"=>$this->bucket, |
845
|
|
|
"Key"=>$this->key, |
846
|
|
|
); |
847
|
|
|
$uploadid = $this->encryptionClient->initMultipartUpload($args); |
848
|
|
|
$uploadid = $uploadid["UploadId"];//获取到uploadid |
849
|
|
|
//开始上传 |
850
|
|
|
|
851
|
|
|
$file = $this->cachedir."multi";//要上传的文件 |
852
|
|
|
$partsize = 1024*100; |
853
|
|
|
$resource = fopen($file,"r"); |
854
|
|
|
$stat = fstat($resource); |
855
|
|
|
$total = $stat["size"];//获取文件的总大小 |
856
|
|
|
fclose($resource); |
857
|
|
|
$count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传 |
858
|
|
|
for($i = 0;$i < $count;$i++){ |
859
|
|
|
//依次上传每一块 |
860
|
|
|
echo "upload".$i."\r\n"; |
861
|
|
|
$args=array( |
862
|
|
|
"Bucket"=>$this->bucket, |
863
|
|
|
"Key"=>$this->key, |
864
|
|
|
"LastPart"=>($i===$count-1), |
865
|
|
|
"Options"=>array( |
866
|
|
|
"partNumber"=>$i+1, |
867
|
|
|
"uploadId"=>$uploadid |
868
|
|
|
), |
869
|
|
|
"ObjectMeta"=>array( |
870
|
|
|
"Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
871
|
|
|
), |
872
|
|
|
"Content"=>array( |
873
|
|
|
"content"=>$file, |
874
|
|
|
"seek_position"=>$partsize*$i//跳过之前已经上传的 |
875
|
|
|
) |
876
|
|
|
); |
877
|
|
|
$etag = $this->encryptionClient->uploadPart($args); |
878
|
|
|
$etag = $etag["ETag"]; |
|
|
|
|
879
|
|
|
} |
880
|
|
|
$parts = $this->encryptionClient->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
|
|
|
|
881
|
|
|
//结束上传 |
882
|
|
|
$args=array( |
883
|
|
|
"Bucket"=>$this->bucket, |
884
|
|
|
"Key"=>$this->key, |
885
|
|
|
"Options"=>array("uploadId"=>$uploadid), |
886
|
|
|
"Parts"=>$parts["Parts"]//使用之前列出的块完成分开上传 |
887
|
|
|
); |
888
|
|
|
$result = $this->encryptionClient->completeMultipartUpload($args); |
|
|
|
|
889
|
|
|
|
890
|
|
|
rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
891
|
|
|
$this->cachedir."down",md5_file($file)); |
892
|
|
|
@unlink($this->cachedir."multi"); |
|
|
|
|
893
|
|
|
} |
894
|
|
|
public function testPutObjectByContentAndGetObject(){ |
895
|
|
|
@unlink($this->cachedir."down"); |
|
|
|
|
896
|
|
|
$content = EncryptionUtil::genereateOnceUsedKey(500); |
897
|
|
|
$args = array( |
898
|
|
|
"Bucket"=>$this->bucket, |
899
|
|
|
"Key"=>$this->key, |
900
|
|
|
"ACL"=>"public-read", |
901
|
|
|
"Content"=>$content |
902
|
|
|
); |
903
|
|
|
$this->encryptionClient->putObjectByContent($args); |
904
|
|
|
$start = (int)rand(0,520); |
905
|
|
|
$end = (int)rand($start,520); |
906
|
|
|
$s3Object = $this->encryptionClient->getObject( |
907
|
|
|
array("Bucket"=>$this->bucket,"Key"=>$this->key, |
908
|
|
|
"Range"=>"bytes=".$start."-".$end) |
909
|
|
|
); |
910
|
|
|
$this->assertEquals(substr($content,$start,$end-$start+1),$s3Object["Content"]); |
911
|
|
|
} |
912
|
|
|
public function test01(){ |
913
|
|
|
$this->client->listObjects(array("Bucket"=>$this->bucket)); |
914
|
|
|
} |
915
|
|
|
} |
916
|
|
|
$test = new SDKTest(); |
917
|
|
|
$methods = array( |
918
|
|
|
//"testRangeGetFile", |
919
|
|
|
"testObjectAcl" |
920
|
|
|
); |
921
|
|
|
$test->run(); |
922
|
|
|
?> |
|
|
|
|
923
|
|
|
|