Test.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. <?php
  2. namespace Qcloud\Cos\Tests;
  3. use Qcloud\Cos\Client;
  4. use Qcloud\Cos\Exception\ServiceResponseException;
  5. class BucketTest extends \PHPUnit_Framework_TestCase
  6. {
  7. private $cosClient;
  8. private $bucket;
  9. protected function setUp()
  10. {
  11. $this->bucket = getenv('COS_BUCKET');
  12. TestHelper::nuke($this->bucket);
  13. $this->cosClient = new Client(array('region' => getenv('COS_REGION'),
  14. 'credentials' => array(
  15. 'appId' => getenv('COS_APPID'),
  16. 'secretId' => getenv('COS_KEY'),
  17. 'secretKey' => getenv('COS_SECRET'))));
  18. sleep(5);
  19. }
  20. protected function tearDown()
  21. {
  22. TestHelper::nuke($this->bucket);
  23. }
  24. /**********************************
  25. * TestBucket
  26. **********************************/
  27. /*
  28. * put bucket,bucket已经存在
  29. * BucketAlreadyOwnedByYou
  30. * 409
  31. */
  32. public function testCreateExistingBucket()
  33. {
  34. try {
  35. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  36. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  37. } catch (ServiceResponseException $e) {
  38. $this->assertTrue($e->getExceptionCode() === 'BucketAlreadyOwnedByYou' && $e->getStatusCode() === 409);
  39. }
  40. }
  41. /*
  42. * put bucket,bucket名称非法
  43. * InvalidBucketName
  44. * 400
  45. */
  46. public function testCreateInvalidBucket()
  47. {
  48. try {
  49. $this->cosClient->createBucket(array('Bucket' => 'qwe_213'));
  50. } catch (ServiceResponseException $e) {
  51. $this->assertTrue($e->getExceptionCode() === 'InvalidBucketName' && $e->getStatusCode() === 400);
  52. }
  53. }
  54. /*
  55. * put bucket,设置bucket公公权限为private
  56. * 200
  57. */
  58. public function testCreatePrivateBucket()
  59. {
  60. try {
  61. $this->cosClient->createBucket(
  62. array(
  63. 'Bucket' => $this->bucket,
  64. 'ACL'=>'private'
  65. ));
  66. } catch (ServiceResponseException $e) {
  67. $this->assertFalse(true, $e);
  68. }
  69. }
  70. /*
  71. * put bucket,设置bucket公公权限为public-read
  72. * 200
  73. */
  74. public function testCreatePublicReadBucket()
  75. {
  76. try {
  77. $this->cosClient->createBucket(
  78. array(
  79. 'Bucket' => $this->bucket,
  80. 'ACL'=>'public-read'
  81. ));
  82. } catch (ServiceResponseException $e) {
  83. $this->assertFalse(true, $e);
  84. }
  85. }
  86. /*
  87. * put bucket,公共权限非法
  88. * InvalidArgument
  89. * 400
  90. */
  91. public function testCreateInvalidACLBucket()
  92. {
  93. try {
  94. $this->cosClient->createBucket(
  95. array(
  96. 'Bucket' => $this->bucket,
  97. 'ACL'=>'public'
  98. ));
  99. } catch (ServiceResponseException $e) {
  100. $this->assertTrue($e->getExceptionCode() === 'InvalidArgument' && $e->getStatusCode() === 400);
  101. }
  102. }
  103. /*
  104. * put bucket acl,设置bucket公共权限为private
  105. * 200
  106. */
  107. public function testPutBucketAclPrivate()
  108. {
  109. try {
  110. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  111. $this->cosClient->PutBucketAcl(
  112. array(
  113. 'Bucket' => $this->bucket,
  114. 'ACL'=>'private'
  115. ));
  116. } catch (ServiceResponseException $e) {
  117. $this->assertFalse(true, $e);
  118. }
  119. }
  120. /*
  121. * put bucket acl,设置bucket公共权限为public-read
  122. * 200
  123. */
  124. public function testPutBucketAclPublicRead()
  125. {
  126. try {
  127. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  128. $this->cosClient->PutBucketAcl(
  129. array(
  130. 'Bucket' => $this->bucket,
  131. 'ACL'=>'public-read'
  132. ));
  133. } catch (ServiceResponseException $e) {
  134. $this->assertFalse(true, $e);
  135. }
  136. }
  137. /*
  138. * put bucket acl,公共权限非法
  139. * InvalidArgument
  140. * 400
  141. */
  142. public function testPutBucketAclInvalid()
  143. {
  144. try {
  145. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  146. $this->cosClient->PutBucketAcl(
  147. array(
  148. 'Bucket' => $this->bucket,
  149. 'ACL'=>'public'
  150. ));
  151. } catch (ServiceResponseException $e) {
  152. $this->assertTrue($e->getExceptionCode() === 'InvalidArgument' && $e->getStatusCode() === 400);
  153. }
  154. }
  155. /*
  156. * put bucket acl,设置bucket账号权限为grant-read
  157. * 200
  158. */
  159. public function testPutBucketAclReadToUser()
  160. {
  161. try {
  162. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  163. $this->cosClient->PutBucketAcl(array(
  164. 'Bucket' => $this->bucket,
  165. 'GrantRead' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  166. } catch (ServiceResponseException $e) {
  167. $this->assertFalse(true, $e);
  168. }
  169. }
  170. /*
  171. * put bucket acl,设置bucket账号权限为grant-write
  172. * 200
  173. */
  174. public function testPutBucketAclWriteToUser()
  175. {
  176. try {
  177. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  178. $this->cosClient->PutBucketAcl(array(
  179. 'Bucket' => $this->bucket,
  180. 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  181. } catch (ServiceResponseException $e) {
  182. $this->assertFalse(true, $e);
  183. }
  184. }
  185. /*
  186. * put bucket acl,设置bucket账号权限为grant-full-control
  187. * 200
  188. */
  189. public function testPutBucketAclFullToUser()
  190. {
  191. try {
  192. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  193. $this->cosClient->PutBucketAcl(array(
  194. 'Bucket' => $this->bucket,
  195. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  196. } catch (ServiceResponseException $e) {
  197. $this->assertFalse(true, $e);
  198. }
  199. }
  200. /*
  201. * put bucket acl,设置bucket账号权限,同时授权给多个账户
  202. * 200
  203. */
  204. public function testPutBucketAclToUsers()
  205. {
  206. try {
  207. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  208. $this->cosClient->PutBucketAcl(array(
  209. 'Bucket' => $this->bucket,
  210. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970",id="qcs::cam::uin/2779643970:uin/2779643970",id="qcs::cam::uin/2779643970:uin/2779643970"'));
  211. } catch (ServiceResponseException $e) {
  212. $this->assertFalse(true, $e);
  213. }
  214. }
  215. /*
  216. * put bucket acl,设置bucket账号权限,授权给子账号
  217. * 200
  218. */
  219. public function testPutBucketAclToSubuser()
  220. {
  221. try {
  222. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  223. $this->cosClient->PutBucketAcl(array(
  224. 'Bucket' => $this->bucket,
  225. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  226. } catch (ServiceResponseException $e) {
  227. $this->assertFalse(true, $e);
  228. }
  229. }
  230. /*
  231. * put bucket acl,设置bucket账号权限,同时指定read、write和fullcontrol
  232. * 200
  233. */
  234. public function testPutBucketAclReadWriteFull()
  235. {
  236. try {
  237. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  238. $this->cosClient->PutBucketAcl(array(
  239. 'Bucket' => $this->bucket,
  240. 'GrantRead' => 'id="qcs::cam::uin/123:uin/123"',
  241. 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',
  242. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',));
  243. } catch (ServiceResponseException $e) {
  244. $this->assertFalse(true, $e);
  245. }
  246. }
  247. /*
  248. * put bucket acl,设置bucket账号权限,grant值非法
  249. * InvalidArgument
  250. * 400
  251. */
  252. public function testPutBucketAclInvalidGrant()
  253. {
  254. try {
  255. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  256. $this->cosClient->PutBucketAcl(array(
  257. 'Bucket' => $this->bucket,
  258. 'GrantFullControl' => 'id="qcs::camuin/321023:uin/2779643970"',));
  259. } catch (ServiceResponseException $e) {
  260. $this->assertTrue($e->getExceptionCode() === 'InvalidArgument' && $e->getStatusCode() === 400);
  261. }
  262. }
  263. /*
  264. * put bucket acl,设置bucket账号权限,通过body方式授权
  265. * 200
  266. */
  267. public function testPutBucketAclByBody()
  268. {
  269. try {
  270. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  271. $this->cosClient->PutBucketAcl(array(
  272. 'Bucket' => $this->bucket,
  273. 'Grants' => array(
  274. array(
  275. 'Grantee' => array(
  276. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  277. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  278. 'Type' => 'CanonicalUser',
  279. ),
  280. 'Permission' => 'FULL_CONTROL',
  281. ),
  282. // ... repeated
  283. ),
  284. 'Owner' => array(
  285. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  286. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  287. )));
  288. } catch (ServiceResponseException $e) {
  289. $this->assertFalse(true, $e);
  290. }
  291. }
  292. /*
  293. * put bucket acl,设置bucket账号权限,通过body方式授权给anyone
  294. * 200
  295. */
  296. public function testPutBucketAclByBodyToAnyone()
  297. {
  298. try {
  299. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  300. $this->cosClient->PutBucketAcl(array(
  301. 'Bucket' => $this->bucket,
  302. 'Grants' => array(
  303. array(
  304. 'Grantee' => array(
  305. 'DisplayName' => 'qcs::cam::anyone:anyone',
  306. 'ID' => 'qcs::cam::anyone:anyone',
  307. 'Type' => 'CanonicalUser',
  308. ),
  309. 'Permission' => 'FULL_CONTROL',
  310. ),
  311. // ... repeated
  312. ),
  313. 'Owner' => array(
  314. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  315. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  316. )));
  317. } catch (ServiceResponseException $e) {
  318. $this->assertFalse(true, $e);
  319. }
  320. }
  321. /*
  322. * put bucket acl,bucket不存在
  323. * NoSuchBucket
  324. * 404
  325. */
  326. public function testPutBucketAclBucketNonexisted()
  327. {
  328. try {
  329. $this->cosClient->PutBucketAcl(array(
  330. 'Bucket' => $this->bucket,
  331. 'GrantFullControl' => 'id="qcs::cam::uin/321023:uin/2779643970"',));
  332. } catch (ServiceResponseException $e) {
  333. // echo($e->getExceptionCode());
  334. // echo($e->getStatusCode());
  335. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  336. }
  337. }
  338. /*
  339. * put bucket acl,覆盖设置
  340. * x200
  341. */
  342. public function testPutBucketAclCover()
  343. {
  344. try {
  345. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  346. $this->cosClient->PutBucketAcl(array(
  347. 'Bucket' => $this->bucket,
  348. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',
  349. 'GrantRead' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',
  350. 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  351. $this->cosClient->PutBucketAcl(array(
  352. 'Bucket' => $this->bucket,
  353. 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  354. } catch (ServiceResponseException $e) {
  355. $this->assertFalse(true, $e);
  356. }
  357. }
  358. /*
  359. * 正常head bucket
  360. * 200
  361. */
  362. public function testHeadBucket()
  363. {
  364. try {
  365. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  366. $this->cosClient->HeadBucket(array(
  367. 'Bucket' => $this->bucket));
  368. } catch (ServiceResponseException $e) {
  369. $this->assertFalse(true, $e);
  370. }
  371. }
  372. /*
  373. * head bucket,bucket不存在
  374. * NoSuchBucket
  375. * 404
  376. */
  377. public function testHeadBucketNonexisted()
  378. {
  379. try {
  380. $this->cosClient->HeadBucket(array(
  381. 'Bucket' => $this->bucket,));
  382. } catch (ServiceResponseException $e) {
  383. // echo($e->getExceptionCode());
  384. // echo($e->getStatusCode());
  385. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  386. }
  387. }
  388. /*
  389. * get bucket,bucket为空
  390. * 200
  391. */
  392. public function testGetBucketEmpty()
  393. {
  394. try {
  395. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  396. $this->cosClient->ListObjects(array(
  397. 'Bucket' => $this->bucket));
  398. } catch (ServiceResponseException $e) {
  399. $this->assertFalse(true, $e);
  400. }
  401. }
  402. /*
  403. * get bucket,bucket不存在
  404. * NoSuchBucket
  405. * 404
  406. */
  407. public function testGetBucketNonexisted()
  408. {
  409. try {
  410. $this->cosClient->ListObjects(array(
  411. 'Bucket' => $this->bucket,));
  412. } catch (ServiceResponseException $e) {
  413. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  414. }
  415. }
  416. /*
  417. * put bucket cors,cors规则包含多条
  418. * 200
  419. */
  420. public function testPutBucketCors()
  421. {
  422. try {
  423. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  424. $this->cosClient->putBucketCors(array(
  425. // Bucket is required
  426. 'Bucket' => $this->bucket,
  427. // CORSRules is required
  428. 'CORSRules' => array(
  429. array(
  430. 'ID' => '1234',
  431. 'AllowedHeaders' => array('*',),
  432. // AllowedMethods is required
  433. 'AllowedMethods' => array('PUT',),
  434. // AllowedOrigins is required
  435. 'AllowedOrigins' => array('*',),
  436. 'ExposeHeaders' => array('*',),
  437. 'MaxAgeSeconds' => 1,
  438. ),
  439. array(
  440. 'ID' => '12345',
  441. 'AllowedHeaders' => array('*',),
  442. // AllowedMethods is required
  443. 'AllowedMethods' => array('PUT',),
  444. // AllowedOrigins is required
  445. 'AllowedOrigins' => array('*',),
  446. 'ExposeHeaders' => array('*',),
  447. 'MaxAgeSeconds' => 1,
  448. ),
  449. // ... repeated
  450. ),
  451. ));
  452. $this->cosClient->getBucketCors(array(
  453. // Bucket is required
  454. 'Bucket' => $this->bucket,));
  455. } catch (ServiceResponseException $e) {
  456. $this->assertFalse(true, $e);
  457. }
  458. }
  459. /*
  460. * 正常get bucket cors
  461. * 200
  462. */
  463. public function testGetBucketCors()
  464. {
  465. try {
  466. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  467. $this->cosClient->putBucketCors(array(
  468. // Bucket is required
  469. 'Bucket' => $this->bucket,
  470. // CORSRules is required
  471. 'CORSRules' => array(
  472. array(
  473. 'ID' => '1234',
  474. 'AllowedHeaders' => array('*',),
  475. // AllowedMethods is required
  476. 'AllowedMethods' => array('PUT',),
  477. // AllowedOrigins is required
  478. 'AllowedOrigins' => array('*',),
  479. 'ExposeHeaders' => array('*',),
  480. 'MaxAgeSeconds' => 1,
  481. ),
  482. array(
  483. 'ID' => '12345',
  484. 'AllowedHeaders' => array('*',),
  485. // AllowedMethods is required
  486. 'AllowedMethods' => array('PUT',),
  487. // AllowedOrigins is required
  488. 'AllowedOrigins' => array('*',),
  489. 'ExposeHeaders' => array('*',),
  490. 'MaxAgeSeconds' => 1,
  491. ),
  492. // ... repeated
  493. ),
  494. ));
  495. $this->cosClient->getBucketCors(array(
  496. // Bucket is required
  497. 'Bucket' => $this->bucket,));
  498. } catch (ServiceResponseException $e) {
  499. $this->assertFalse(true, $e);
  500. }
  501. }
  502. /*
  503. * bucket未设置cors规则,发送get bucket cors
  504. * NoSuchCORSConfiguration
  505. * 404
  506. */
  507. public function testGetBucketCorsNull()
  508. {
  509. try {
  510. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  511. $this->cosClient->getBucketCors(array(
  512. // Bucket is required
  513. 'Bucket' => $this->bucket,));
  514. } catch (ServiceResponseException $e) {
  515. // echo($e->getExceptionCode());
  516. // echo($e->getStatusCode());
  517. $this->assertTrue($e->getExceptionCode() === 'NoSuchCORSConfiguration' && $e->getStatusCode() === 404);
  518. }
  519. }
  520. /*
  521. * bucket未设置cors规则,发送get bucket cors
  522. * NoSuchCORSConfiguration
  523. * 404
  524. */
  525. public function testGetBucketCorsNonExisted()
  526. {
  527. try {
  528. $this->cosClient->getBucketCors(array(
  529. // Bucket is required
  530. 'Bucket' => $this->bucket,));
  531. } catch (ServiceResponseException $e) {
  532. // echo($e->getExceptionCode());
  533. // echo($e->getStatusCode());
  534. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  535. }
  536. }
  537. /*
  538. * 正常get bucket lifecycle
  539. * 200
  540. */
  541. public function testGetBucketLifecycle()
  542. {
  543. try {
  544. $result = $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  545. $result = $this->cosClient->putBucketLifecycle(array(
  546. 'Bucket' => $this->bucket,
  547. 'Rules' => array(
  548. array(
  549. 'Status' => 'Enabled',
  550. 'Filter' => array(
  551. 'Tag' => array(
  552. 'Key' => 'datalevel',
  553. 'Value' => 'backup'
  554. )
  555. ),
  556. 'Transitions' => array(
  557. array(
  558. # 30天后转换为Standard_IA
  559. 'Days' => 30,
  560. 'StorageClass' => 'Standard_IA'),
  561. array(
  562. # 365天后转换为Archive
  563. 'Days' => 365,
  564. 'StorageClass' => 'Archive')
  565. ),
  566. 'Expiration' => array(
  567. # 3650天后过期删除
  568. 'Days' => 3650,
  569. )
  570. )
  571. )
  572. ));
  573. sleep(3);
  574. $result = $this->cosClient->getBucketLifecycle(array(
  575. // Bucket is required
  576. 'Bucket' => $this->bucket,
  577. ));
  578. } catch (ServiceResponseException $e) {
  579. $this->assertFalse(true, $e);
  580. }
  581. }
  582. /*
  583. * 正常delete bucket lifecycle
  584. * 200
  585. */
  586. public function testDeleteBucketLifecycle()
  587. {
  588. try {
  589. $result = $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  590. $result = $this->cosClient->putBucketLifecycle(array(
  591. 'Bucket' => $this->bucket,
  592. 'Rules' => array(
  593. array(
  594. 'Status' => 'Enabled',
  595. 'Filter' => array(
  596. 'Tag' => array(
  597. 'Key' => 'datalevel',
  598. 'Value' => 'backup'
  599. )
  600. ),
  601. 'Transitions' => array(
  602. array(
  603. # 30天后转换为Standard_IA
  604. 'Days' => 30,
  605. 'StorageClass' => 'Standard_IA'),
  606. array(
  607. # 365天后转换为Archive
  608. 'Days' => 365,
  609. 'StorageClass' => 'Archive')
  610. ),
  611. 'Expiration' => array(
  612. # 3650天后过期删除
  613. 'Days' => 3650,
  614. )
  615. )
  616. )
  617. ));
  618. $result = $this->cosClient->deleteBucketLifecycle(array(
  619. // Bucket is required
  620. 'Bucket' => $this->bucket,
  621. ));
  622. } catch (ServiceResponseException $e) {
  623. $this->assertFalse(true, $e);
  624. }
  625. }
  626. /*
  627. * put bucket lifecycle,请求body中不指定filter
  628. * 200
  629. */
  630. public function testPutBucketLifecycleNonFilter()
  631. {
  632. try {
  633. $result = $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  634. $result = $this->cosClient->putBucketLifecycle(array(
  635. // Bucket is required
  636. 'Bucket' => $this->bucket,
  637. // Rules is required
  638. 'Rules' => array(
  639. array(
  640. 'Expiration' => array(
  641. 'Days' => 1000,
  642. ),
  643. 'ID' => 'id1',
  644. // Status is required
  645. 'Status' => 'Enabled',
  646. 'Transitions' => array(
  647. array(
  648. 'Days' => 100,
  649. 'StorageClass' => 'Standard_IA'),
  650. ),
  651. // ... repeated
  652. ),
  653. )));
  654. } catch (ServiceResponseException $e) {
  655. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  656. }
  657. }
  658. /*
  659. * put bucket,bucket名称带有-
  660. * 200
  661. */
  662. public function testPutBucket2()
  663. {
  664. try {
  665. try{
  666. $this->cosClient->deleteBucket(array('Bucket' => '12345-'.$this->bucket));
  667. } catch (\Exception $e) {
  668. }
  669. $this->cosClient->createBucket(array('Bucket' => '12345-'.$this->bucket));
  670. $this->cosClient->deleteBucket(array('Bucket' => '12345-'.$this->bucket));
  671. } catch (ServiceResponseException $e) {
  672. $this->assertFalse(true, $e);
  673. }
  674. }
  675. /*
  676. * put bucket,bucket名称带有两个-
  677. * 200
  678. */
  679. public function testPutBucket3()
  680. {
  681. try {
  682. $this->cosClient->createBucket(array('Bucket' => $this->bucket.'-12333-4445'));
  683. $this->cosClient->deleteBucket(array('Bucket' => $this->bucket.'-12333-4445'));
  684. } catch (ServiceResponseException $e) {
  685. $this->assertFalse(true, $e);
  686. }
  687. }
  688. /*
  689. * 正常get bucket location
  690. * 200
  691. */
  692. public function testGetBucketLocation()
  693. {
  694. try {
  695. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  696. $this->cosClient->getBucketLocation(array('Bucket' => $this->bucket));
  697. } catch (ServiceResponseException $e) {
  698. $this->assertFalse(true, $e);
  699. }
  700. }
  701. /*
  702. * bucket不存在,发送get bucket location请求
  703. * NoSuchBucket
  704. * 404
  705. */
  706. public function testGetBucketLocationNonExisted()
  707. {
  708. try {
  709. $this->cosClient->getBucketLocation(array('Bucket' => $this->bucket));
  710. } catch (ServiceResponseException $e) {
  711. // echo($e->getExceptionCode());
  712. // echo($e->getStatusCode());
  713. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket' && $e->getStatusCode() === 404);
  714. }
  715. }
  716. /**********************************
  717. * TestObject
  718. **********************************/
  719. /*
  720. * put object,请求头部携带服务端加密参数
  721. * 200
  722. */
  723. public function testPutObjectEncryption()
  724. {
  725. try {
  726. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  727. $this->cosClient->putObject(array(
  728. 'Bucket' => $this->bucket,
  729. 'Key' => '11//32//43',
  730. 'Body' => 'Hello World!',
  731. 'ServerSideEncryption' => 'AES256'));
  732. } catch (ServiceResponseException $e) {
  733. $this->assertFalse(true, $e);
  734. }
  735. }
  736. /*
  737. * 上传文件Bucket不存在
  738. * NoSuchBucket
  739. * 404
  740. */
  741. public function testPutObjectIntoNonexistedBucket() {
  742. try {
  743. $this->cosClient->putObject(array(
  744. 'Bucket' => $this->bucket, 'Key' => 'hello.txt', 'Body' => 'Hello World'));
  745. } catch (ServiceResponseException $e) {
  746. $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket');
  747. $this->assertTrue($e->getStatusCode() === 404);
  748. }
  749. }
  750. /*
  751. * 上传小文件
  752. * 200
  753. */
  754. public function testUploadSmallObject() {
  755. try {
  756. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  757. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  758. } catch (ServiceResponseException $e) {
  759. $this->assertFalse(true, $e);
  760. }
  761. }
  762. /*
  763. * 上传空文件
  764. * 200
  765. */
  766. public function testPutObjectEmpty() {
  767. try {
  768. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  769. $this->cosClient->upload($this->bucket, '你好.txt', '123');
  770. } catch (ServiceResponseException $e) {
  771. $this->assertFalse(true, $e);
  772. }
  773. }
  774. /*
  775. * 上传已存在的文件
  776. * 200
  777. */
  778. public function testPutObjectExisted() {
  779. try {
  780. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  781. $this->cosClient->upload($this->bucket, '你好.txt', '1234124');
  782. $this->cosClient->upload($this->bucket, '你好.txt', '请二位qwe');
  783. } catch (ServiceResponseException $e) {
  784. $this->assertFalse(true, $e);
  785. }
  786. }
  787. /*
  788. * put object,请求头部携带自定义头部x-cos-meta-
  789. * 200
  790. */
  791. public function testPutObjectMeta() {
  792. try {
  793. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  794. $this->cosClient->putObject(array(
  795. 'Bucket' => $this->bucket,
  796. 'Key' => '你好.txt',
  797. 'Body' => '1234124',
  798. 'Metadata' => array(
  799. 'lew' => str_repeat('a', 1 * 1024),
  800. )));
  801. } catch (ServiceResponseException $e) {
  802. $this->assertFalse(true, $e);
  803. }
  804. }
  805. /*
  806. * put object,请求头部携带自定义头部x-cos-meta-
  807. * KeyTooLong
  808. * 400
  809. */
  810. public function testPutObjectMeta2K() {
  811. try {
  812. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  813. $this->cosClient->putObject(array(
  814. 'Bucket' => $this->bucket,
  815. 'Key' => '你好.txt',
  816. 'Body' => '1234124',
  817. 'Metadata' => array(
  818. 'lew' => str_repeat('a', 3 * 1024),
  819. )));
  820. } catch (ServiceResponseException $e) {
  821. // echo($e->getExceptionCode());
  822. // echo($e->getStatusCode());
  823. $this->assertTrue($e->getExceptionCode() === 'KeyTooLong' && $e->getStatusCode() === 400);
  824. }
  825. }
  826. /*
  827. * 上传复杂文件名的文件
  828. * 200
  829. */
  830. public function testUploadComplexObject() {
  831. try {
  832. $result = $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  833. $this->cosClient->upload($this->bucket, '→↓←→↖↗↙↘! \"#$%&\'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 'Hello World');
  834. } catch (ServiceResponseException $e) {
  835. $this->assertFalse(true, $e);
  836. }
  837. }
  838. /*
  839. * 上传大文件
  840. * 200
  841. */
  842. public function testUploadLargeObject() {
  843. try {
  844. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  845. $this->cosClient->upload($this->bucket, 'hello.txt', str_repeat('a', 9 * 1024 * 1024));
  846. } catch (ServiceResponseException $e) {
  847. $this->assertFalse(true, $e);
  848. }
  849. }
  850. /*
  851. * 下载文件
  852. * 200
  853. */
  854. public function testGetObject() {
  855. try {
  856. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  857. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  858. $this->cosClient->getObject(array(
  859. 'Bucket' => $this->bucket,
  860. 'Key' => '你好.txt',));
  861. } catch (ServiceResponseException $e) {
  862. $this->assertFalse(true, $e);
  863. }
  864. }
  865. /*
  866. * get object,object名称包含特殊字符
  867. * 200
  868. */
  869. public function testGetObjectSpecialName() {
  870. try {
  871. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  872. $this->cosClient->upload($this->bucket, '你好<>!@#^%^&*&(&^!@#@!.txt', 'Hello World');
  873. $this->cosClient->getObject(array(
  874. 'Bucket' => $this->bucket,
  875. 'Key' => '你好<>!@#^%^&*&(&^!@#@!.txt',));
  876. } catch (ServiceResponseException $e) {
  877. $this->assertFalse(true, $e);
  878. }
  879. }
  880. /*
  881. * get object,请求头部带if-match,参数值为true
  882. * 200
  883. */
  884. public function testGetObjectIfMatchTrue() {
  885. try {
  886. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  887. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  888. $this->cosClient->getObject(array(
  889. 'Bucket' => $this->bucket,
  890. 'Key' => '你好.txt',
  891. 'IfMatch' => '"b10a8db164e0754105b7a99be72e3fe5"'));
  892. } catch (ServiceResponseException $e) {
  893. $this->assertFalse(true, $e);
  894. }
  895. }
  896. /*
  897. * get object,请求头部带if-match,参数值为false
  898. * PreconditionFailed
  899. * 412
  900. */
  901. public function testGetObjectIfMatchFalse() {
  902. try {
  903. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  904. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  905. $this->cosClient->getObject(array(
  906. 'Bucket' => $this->bucket,
  907. 'Key' => '你好.txt',
  908. 'IfMatch' => '""'));
  909. } catch (ServiceResponseException $e) {
  910. // echo($e->getExceptionCode());
  911. // echo($e->getStatusCode());
  912. $this->assertTrue($e->getExceptionCode() === 'PreconditionFailed' && $e->getStatusCode() === 412);
  913. }
  914. }
  915. /*
  916. * get object,请求头部带if-none-match,参数值为true
  917. * 200
  918. */
  919. public function testGetObjectIfNoneMatchTrue() {
  920. try {
  921. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  922. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  923. $this->cosClient->getObject(array(
  924. 'Bucket' => $this->bucket,
  925. 'Key' => '你好.txt',
  926. 'IfNoneMatch' => '"b10a8db164e0754105b7a99be72e3fe5"'));
  927. } catch (ServiceResponseException $e) {
  928. $this->assertTrue($e->getExceptionCode() === 'NotModified' && $e->getStatusCode() === 304);
  929. }
  930. }
  931. /*
  932. * get object,请求头部带if-none-match,参数值为false
  933. * PreconditionFailed
  934. * 412
  935. */
  936. public function testGetObjectIfNoneMatchFalse() {
  937. try {
  938. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  939. $this->cosClient->upload($this->bucket, '你好.txt', 'Hello World');
  940. $this->cosClient->getObject(array(
  941. 'Bucket' => $this->bucket,
  942. 'Key' => '你好.txt',
  943. 'IfNoneMatch' => '""'));
  944. } catch (ServiceResponseException $e) {
  945. $this->assertFalse(true, $e);
  946. }
  947. }
  948. /*
  949. * 获取文件url
  950. * 200
  951. */
  952. public function testGetObjectUrl() {
  953. try{
  954. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  955. $this->cosClient->getObjectUrl($this->bucket, 'hello.txt', '+10 minutes');
  956. } catch (ServiceResponseException $e) {
  957. $this->assertFalse(true, $e);
  958. }
  959. }
  960. /*
  961. * 设置objectacl
  962. * 200
  963. */
  964. public function testPutObjectACL() {
  965. try {
  966. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  967. $this->cosClient->upload($this->bucket, '11', 'hello.txt');
  968. $this->cosClient->PutObjectAcl(array(
  969. 'Bucket' => $this->bucket,
  970. 'Key' => '11',
  971. 'Grants' => array(
  972. array(
  973. 'Grantee' => array(
  974. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  975. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  976. 'Type' => 'CanonicalUser',
  977. ),
  978. 'Permission' => 'FULL_CONTROL',
  979. ),
  980. // ... repeated
  981. ),
  982. 'Owner' => array(
  983. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  984. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  985. )));
  986. } catch (ServiceResponseException $e) {
  987. $this->assertFalse(true, $e);
  988. }
  989. }
  990. /*
  991. * 获取objectacl
  992. * 200
  993. */
  994. public function testGetObjectACL()
  995. {
  996. try {
  997. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  998. $this->cosClient->upload($this->bucket, '11', 'hello.txt');
  999. $this->cosClient->PutObjectAcl(array(
  1000. 'Bucket' => $this->bucket,
  1001. 'Key' => '11',
  1002. 'Grants' => array(
  1003. array(
  1004. 'Grantee' => array(
  1005. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1006. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1007. 'Type' => 'CanonicalUser',
  1008. ),
  1009. 'Permission' => 'FULL_CONTROL',
  1010. ),
  1011. // ... repeated
  1012. ),
  1013. 'Owner' => array(
  1014. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1015. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1016. )));
  1017. } catch (ServiceResponseException $e) {
  1018. $this->assertFalse(true, $e);
  1019. }
  1020. }
  1021. /*
  1022. * put object acl,设置object公共权限为private
  1023. * 200
  1024. */
  1025. public function testPutObjectAclPrivate()
  1026. {
  1027. try {
  1028. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1029. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1030. $this->cosClient->PutObjectAcl(
  1031. array(
  1032. 'Bucket' => $this->bucket,
  1033. 'Key' => '你好.txt',
  1034. 'ACL'=>'private'
  1035. ));
  1036. } catch (ServiceResponseException $e) {
  1037. $this->assertFalse(true, $e);
  1038. }
  1039. }
  1040. /*
  1041. * put object acl,设置object公共权限为public-read
  1042. * 200
  1043. */
  1044. public function testPutObjectAclPublicRead()
  1045. {
  1046. try {
  1047. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1048. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1049. $this->cosClient->PutObjectAcl(
  1050. array(
  1051. 'Bucket' => $this->bucket,
  1052. 'Key' => '你好.txt',
  1053. 'ACL'=>'public-read'
  1054. ));
  1055. } catch (ServiceResponseException $e) {
  1056. $this->assertFalse(true, $e);
  1057. }
  1058. }
  1059. /*
  1060. * put object acl,公共权限非法
  1061. * InvalidArgument
  1062. * 400
  1063. */
  1064. public function testPutObjectAclInvalid()
  1065. {
  1066. try {
  1067. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1068. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1069. $this->cosClient->PutObjectAcl(
  1070. array(
  1071. 'Bucket' => $this->bucket,
  1072. 'Key' => '你好.txt',
  1073. 'ACL'=>'public'
  1074. ));
  1075. } catch (ServiceResponseException $e) {
  1076. $this->assertTrue($e->getExceptionCode() === 'InvalidArgument' && $e->getStatusCode() === 400);
  1077. }
  1078. }
  1079. /*
  1080. * put object acl,设置object账号权限为grant-read
  1081. * 200
  1082. */
  1083. public function testPutObjectAclReadToUser()
  1084. {
  1085. try {
  1086. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1087. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1088. $this->cosClient->PutObjectAcl(array(
  1089. 'Bucket' => $this->bucket,
  1090. 'Key' => '你好.txt',
  1091. 'GrantRead' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  1092. } catch (ServiceResponseException $e) {
  1093. $this->assertFalse(true, $e);
  1094. }
  1095. }
  1096. /*
  1097. * put object acl,设置object账号权限为grant-write
  1098. * 200
  1099. */
  1100. // public function testPutObjectAclWriteToUser()
  1101. // {
  1102. // try {
  1103. // $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1104. // $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1105. // $this->cosClient->PutObjectAcl(array(
  1106. // 'Bucket' => $this->bucket,
  1107. // 'Key' => '你好.txt',
  1108. // 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  1109. // } catch (ServiceResponseException $e) {
  1110. // $this->assertFalse(true, $e);
  1111. // }
  1112. // }
  1113. /*
  1114. * put object acl,设置object账号权限为grant-full-control
  1115. * 200
  1116. */
  1117. public function testPutObjectAclFullToUser()
  1118. {
  1119. try {
  1120. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1121. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1122. $this->cosClient->PutObjectAcl(array(
  1123. 'Bucket' => $this->bucket,
  1124. 'Key' => '你好.txt',
  1125. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  1126. } catch (ServiceResponseException $e) {
  1127. $this->assertFalse(true, $e);
  1128. }
  1129. }
  1130. /*
  1131. * put object acl,设置object账号权限,同时授权给多个账户
  1132. * 200
  1133. */
  1134. public function testPutObjectAclToUsers()
  1135. {
  1136. try {
  1137. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1138. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1139. $this->cosClient->PutObjectAcl(array(
  1140. 'Bucket' => $this->bucket,
  1141. 'Key' => '你好.txt',
  1142. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970",id="qcs::cam::uin/2779643970:uin/2779643970",id="qcs::cam::uin/2779643970:uin/2779643970"'));
  1143. } catch (ServiceResponseException $e) {
  1144. $this->assertFalse(true, $e);
  1145. }
  1146. }
  1147. /*
  1148. * put object acl,设置object账号权限,授权给子账号
  1149. * 200
  1150. */
  1151. public function testPutObjectAclToSubuser()
  1152. {
  1153. try {
  1154. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1155. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1156. $this->cosClient->PutObjectAcl(array(
  1157. 'Bucket' => $this->bucket,
  1158. 'Key' => '你好.txt',
  1159. 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"'));
  1160. } catch (ServiceResponseException $e) {
  1161. $this->assertFalse(true, $e);
  1162. }
  1163. }
  1164. /*
  1165. * put object acl,设置object账号权限,同时指定read、write和fullcontrol
  1166. * 200
  1167. */
  1168. // public function testPutObjectAclReadWriteFull()
  1169. // {
  1170. // try {
  1171. // $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1172. // $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1173. // $this->cosClient->PutObjectAcl(array(
  1174. // 'Bucket' => $this->bucket,
  1175. // 'Key' => '你好.txt',
  1176. // 'GrantRead' => 'id="qcs::cam::uin/123:uin/123"',
  1177. // 'GrantWrite' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',
  1178. // 'GrantFullControl' => 'id="qcs::cam::uin/2779643970:uin/2779643970"',));
  1179. // } catch (ServiceResponseException $e) {
  1180. // $this->assertFalse(true, $e);
  1181. // }
  1182. // }
  1183. /*
  1184. * put object acl,设置object账号权限,grant值非法
  1185. * InvalidArgument
  1186. * 400
  1187. */
  1188. public function testPutObjectAclInvalidGrant()
  1189. {
  1190. try {
  1191. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1192. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1193. $this->cosClient->PutObjectAcl(array(
  1194. 'Bucket' => $this->bucket,
  1195. 'Key' => '你好.txt',
  1196. 'GrantFullControl' => 'id="qcs::camuin/321023:uin/2779643970"',));
  1197. } catch (ServiceResponseException $e) {
  1198. $this->assertTrue($e->getExceptionCode() === 'InvalidArgument' && $e->getStatusCode() === 400);
  1199. }
  1200. }
  1201. /*
  1202. * put object acl,设置object账号权限,通过body方式授权
  1203. * 200
  1204. */
  1205. public function testPutObjectAclByBody()
  1206. {
  1207. try {
  1208. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1209. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1210. $this->cosClient->PutObjectAcl(array(
  1211. 'Bucket' => $this->bucket,
  1212. 'Key' => '你好.txt',
  1213. 'Grants' => array(
  1214. array(
  1215. 'Grantee' => array(
  1216. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1217. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1218. 'Type' => 'CanonicalUser',
  1219. ),
  1220. 'Permission' => 'FULL_CONTROL',
  1221. ),
  1222. // ... repeated
  1223. ),
  1224. 'Owner' => array(
  1225. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1226. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1227. )));
  1228. } catch (ServiceResponseException $e) {
  1229. $this->assertFalse(true, $e);
  1230. }
  1231. }
  1232. /*
  1233. * put object acl,设置object账号权限,通过body方式授权给anyone
  1234. * 200
  1235. */
  1236. public function testPutObjectAclByBodyToAnyone()
  1237. {
  1238. try {
  1239. $this->cosClient->createBucket(array('Bucket' => $this->bucket));
  1240. $this->cosClient->putObject(array('Bucket' => $this->bucket,'Key' => '你好.txt', 'Body' => '123'));
  1241. $this->cosClient->putObjectAcl(array(
  1242. 'Bucket' => $this->bucket,
  1243. 'Key' => '你好.txt',
  1244. 'Grants' => array(
  1245. array(
  1246. 'Grantee' => array(
  1247. 'DisplayName' => 'qcs::cam::anyone:anyone',
  1248. 'ID' => 'qcs::cam::anyone:anyone',
  1249. 'Type' => 'CanonicalUser',
  1250. ),
  1251. 'Permission' => 'FULL_CONTROL',
  1252. ),
  1253. // ... repeated
  1254. ),
  1255. 'Owner' => array(
  1256. 'DisplayName' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1257. 'ID' => 'qcs::cam::uin/2779643970:uin/2779643970',
  1258. )));
  1259. } catch (ServiceResponseException $e) {
  1260. $this->assertFalse(true, $e);
  1261. }
  1262. }
  1263. }