PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/codes-php/phpjakarta/tests/functional/WindowsAzure/Blob/BlobServiceFunctionalTest.php

http://bukuphpjs.codeplex.com
PHP | 2393 lines | 1530 code | 289 blank | 574 comment | 336 complexity | 63d1c1187f615ad4cb9e8a4c8e14a70a MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Functional\WindowsAzure\Blob
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Functional\WindowsAzure\Blob;
  24. use Tests\Framework\TestResources;
  25. use WindowsAzure\Blob\Models\BlobServiceOptions;
  26. use WindowsAzure\Blob\Models\CopyBlobOptions;
  27. use WindowsAzure\Blob\Models\CreateBlobSnapshotOptions;
  28. use WindowsAzure\Blob\Models\CreateContainerOptions;
  29. use WindowsAzure\Blob\Models\DeleteBlobOptions;
  30. use WindowsAzure\Blob\Models\DeleteContainerOptions;
  31. use WindowsAzure\Blob\Models\GetBlobMetadataOptions;
  32. use WindowsAzure\Blob\Models\GetBlobOptions;
  33. use WindowsAzure\Blob\Models\GetBlobPropertiesOptions;
  34. use WindowsAzure\Blob\Models\ListBlobsOptions;
  35. use WindowsAzure\Blob\Models\ListContainersOptions;
  36. use WindowsAzure\Blob\Models\PublicAccessType;
  37. use WindowsAzure\Blob\Models\SetBlobMetadataOptions;
  38. use WindowsAzure\Blob\Models\SetContainerMetadataOptions;
  39. use WindowsAzure\Common\ServiceException;
  40. use WindowsAzure\Common\Internal\Resources;
  41. use WindowsAzure\Common\Internal\StorageServiceSettings;
  42. use WindowsAzure\Common\Internal\Utilities;
  43. class BlobServiceFunctionalTest extends FunctionalTestBase
  44. {
  45. /**
  46. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  47. */
  48. public function testGetServicePropertiesNoOptions()
  49. {
  50. $serviceProperties = BlobServiceFunctionalTestData::getDefaultServiceProperties();
  51. $shouldReturn = false;
  52. try {
  53. $this->restProxy->setServiceProperties($serviceProperties);
  54. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  55. } catch (ServiceException $e) {
  56. // Expect failure in emulator, as v1.6 doesn't support this method
  57. if ($this->isEmulated()) {
  58. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  59. $shouldReturn = true;
  60. } else {
  61. throw $e;
  62. }
  63. }
  64. if($shouldReturn) {
  65. return;
  66. }
  67. $this->getServicePropertiesWorker(null);
  68. }
  69. /**
  70. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  71. */
  72. public function testGetServiceProperties()
  73. {
  74. $serviceProperties = BlobServiceFunctionalTestData::getDefaultServiceProperties();
  75. $shouldReturn = false;
  76. try {
  77. $this->restProxy->setServiceProperties($serviceProperties);
  78. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  79. } catch (ServiceException $e) {
  80. // Expect failure in emulator, as v1.6 doesn't support this method
  81. if ($this->isEmulated()) {
  82. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  83. $shouldReturn = true;
  84. } else {
  85. throw $e;
  86. }
  87. }
  88. if($shouldReturn) {
  89. return;
  90. }
  91. // Now look at the combos.
  92. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  93. foreach($interestingTimeouts as $timeout) {
  94. $options = new BlobServiceOptions();
  95. $options->setTimeout($timeout);
  96. $this->getServicePropertiesWorker($options);
  97. }
  98. }
  99. /**
  100. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  101. */
  102. private function getServicePropertiesWorker($options)
  103. {
  104. $effOptions = (is_null($options) ? new BlobServiceOptions() : $options);
  105. try {
  106. $ret = (is_null($options) ? $this->restProxy->getServiceProperties() : $this->restProxy->getServiceProperties($effOptions));
  107. if (!is_null($effOptions->getTimeout()) && $effOptions->getTimeout() < 1) {
  108. $this->True('Expect negative timeouts in $options to throw', false);
  109. } else {
  110. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  111. }
  112. $this->verifyServicePropertiesWorker($ret, null);
  113. } catch (ServiceException $e) {
  114. if ($this->isEmulated()) {
  115. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  116. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  117. } else {
  118. // Expect failure in emulator, as v1.6 doesn't support this method
  119. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  120. }
  121. } else {
  122. if (is_null($effOptions->getTimeout()) || $effOptions->getTimeout() >= 1) {
  123. throw $e;
  124. } else {
  125. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  126. }
  127. }
  128. }
  129. }
  130. private function verifyServicePropertiesWorker($ret, $serviceProperties)
  131. {
  132. if (is_null($serviceProperties)) {
  133. $serviceProperties = BlobServiceFunctionalTestData::getDefaultServiceProperties();
  134. }
  135. $sp = $ret->getValue();
  136. $this->assertNotNull($sp, 'getValue should be non-null');
  137. $l = $sp->getLogging();
  138. $this->assertNotNull($l, 'getValue()->getLogging() should be non-null');
  139. $this->assertEquals($serviceProperties->getLogging()->getVersion(), $l->getVersion(), 'getValue()->getLogging()->getVersion');
  140. $this->assertEquals($serviceProperties->getLogging()->getDelete(), $l->getDelete(), 'getValue()->getLogging()->getDelete');
  141. $this->assertEquals($serviceProperties->getLogging()->getRead(), $l->getRead(), 'getValue()->getLogging()->getRead');
  142. $this->assertEquals($serviceProperties->getLogging()->getWrite(), $l->getWrite(), 'getValue()->getLogging()->getWrite');
  143. $r = $l->getRetentionPolicy();
  144. $this->assertNotNull($r, 'getValue()->getLogging()->getRetentionPolicy should be non-null');
  145. $this->assertEquals($serviceProperties->getLogging()->getRetentionPolicy()->getDays(), $r->getDays(), 'getValue()->getLogging()->getRetentionPolicy()->getDays');
  146. $m = $sp->getMetrics();
  147. $this->assertNotNull($m, 'getValue()->getMetrics() should be non-null');
  148. $this->assertEquals($serviceProperties->getMetrics()->getVersion(), $m->getVersion(), 'getValue()->getMetrics()->getVersion');
  149. $this->assertEquals($serviceProperties->getMetrics()->getEnabled(), $m->getEnabled(), 'getValue()->getMetrics()->getEnabled');
  150. $this->assertEquals($serviceProperties->getMetrics()->getIncludeAPIs(), $m->getIncludeAPIs(), 'getValue()->getMetrics()->getIncludeAPIs');
  151. $r = $m->getRetentionPolicy();
  152. $this->assertNotNull($r, 'getValue()->getMetrics()->getRetentionPolicy should be non-null');
  153. $this->assertEquals($serviceProperties->getMetrics()->getRetentionPolicy()->getDays(), $r->getDays(), 'getValue()->getMetrics()->getRetentionPolicy()->getDays');
  154. }
  155. /**
  156. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  157. * @covers WindowsAzure\Blob\BlobRestProxy::setServiceProperties
  158. */
  159. public function testSetServicePropertiesNoOptions()
  160. {
  161. $serviceProperties = BlobServiceFunctionalTestData::getDefaultServiceProperties();
  162. $this->setServicePropertiesWorker($serviceProperties, null);
  163. }
  164. /**
  165. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  166. * @covers WindowsAzure\Blob\BlobRestProxy::setServiceProperties
  167. */
  168. public function testSetServiceProperties()
  169. {
  170. $interestingServiceProperties = BlobServiceFunctionalTestData::getInterestingServiceProperties();
  171. foreach($interestingServiceProperties as $serviceProperties) {
  172. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  173. foreach($interestingTimeouts as $timeout) {
  174. $options = new BlobServiceOptions();
  175. $options->setTimeout($timeout);
  176. $this->setServicePropertiesWorker($serviceProperties, $options);
  177. }
  178. }
  179. if (!$this->isEmulated()) {
  180. $this->restProxy->setServiceProperties($interestingServiceProperties[0]);
  181. }
  182. }
  183. /**
  184. * @covers WindowsAzure\Blob\BlobRestProxy::getServiceProperties
  185. * @covers WindowsAzure\Blob\BlobRestProxy::setServiceProperties
  186. */
  187. private function setServicePropertiesWorker($serviceProperties, $options)
  188. {
  189. try {
  190. if (is_null($options)) {
  191. $this->restProxy->setServiceProperties($serviceProperties);
  192. } else {
  193. $this->restProxy->setServiceProperties($serviceProperties, $options);
  194. }
  195. if (is_null($options)) {
  196. $options = new BlobServiceOptions();
  197. }
  198. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  199. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  200. } else {
  201. $this->assertFalse($this->isEmulated(), 'Should succeed when not running in emulator');
  202. }
  203. $ret = (is_null($options) ? $this->restProxy->getServiceProperties() : $this->restProxy->getServiceProperties($options));
  204. $this->verifyServicePropertiesWorker($ret, $serviceProperties);
  205. } catch (ServiceException $e) {
  206. if (is_null($options)) {
  207. $options = new BlobServiceOptions();
  208. }
  209. if ($this->isEmulated()) {
  210. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  211. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  212. } else {
  213. $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
  214. }
  215. } else {
  216. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  217. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  218. } else {
  219. throw $e;
  220. }
  221. }
  222. }
  223. }
  224. /**
  225. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  226. */
  227. public function testListContainersNoOptions()
  228. {
  229. $this->listContainersWorker(null);
  230. }
  231. /**
  232. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  233. */
  234. public function testListContainers()
  235. {
  236. $interestingListContainersOptions = BlobServiceFunctionalTestData::getInterestingListContainersOptions();
  237. foreach($interestingListContainersOptions as $options) {
  238. $this->listContainersWorker($options);
  239. }
  240. }
  241. /**
  242. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  243. */
  244. private function listContainersWorker($options)
  245. {
  246. $finished = false;
  247. while (!$finished) {
  248. try {
  249. $ret = (is_null($options) ? $this->restProxy->listContainers() : $this->restProxy->listContainers($options));
  250. if (is_null($options)) {
  251. $options = new ListContainersOptions();
  252. }
  253. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  254. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  255. }
  256. $this->verifyListContainersWorker($ret, $options);
  257. if (strlen($ret->getNextMarker()) == 0) {
  258. $finished = true;
  259. } else {
  260. $options->setMarker($ret->getNextMarker());
  261. }
  262. } catch (ServiceException $e) {
  263. $finished = true;
  264. if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) {
  265. throw $e;
  266. } else {
  267. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  268. }
  269. }
  270. }
  271. }
  272. private function verifyListContainersWorker($ret, $options)
  273. {
  274. // Cannot really check the next marker. Just make sure it is not null.
  275. $this->assertEquals($options->getMarker(), $ret->getMarker(), 'getMarker');
  276. $this->assertEquals($options->getMaxResults(), $ret->getMaxResults(), 'getMaxResults');
  277. $this->assertEquals($options->getPrefix(), $ret->getPrefix(), 'getPrefix');
  278. $this->assertNotNull($ret->getContainers(), 'getBlobs');
  279. if ($options->getMaxResults() == 0) {
  280. $this->assertEquals(0, strlen($ret->getNextMarker()), 'When MaxResults is 0, expect getNextMarker (' . strlen($ret->getNextMarker()) . ')to be ');
  281. if (!is_null($options->getPrefix()) && $options->getPrefix() == (BlobServiceFunctionalTestData::$nonExistBlobPrefix)) {
  282. $this->assertEquals(0, count($ret->getContainers()), 'when MaxResults=0 and Prefix=(\'' . $options->getPrefix() . '\'), then Blobs length');
  283. } else if (!is_null($options->getPrefix()) && $options->getPrefix() == (BlobServiceFunctionalTestData::$testUniqueId)) {
  284. $this->assertEquals(count(BlobServiceFunctionalTestData::$testContainerNames), count($ret->getContainers()), 'when MaxResults=0 and Prefix=(\'' . $options->getPrefix() . '\'), then Blobs length');
  285. } else {
  286. // Do not know how many there should be
  287. }
  288. } else if (strlen($ret->getNextMarker()) == 0) {
  289. $this->assertTrue(count($ret->getContainers()) <= $options->getMaxResults(), 'when NextMarker (\'' . $ret->getNextMarker() . '\')==\'\', Blobs length (' . count($ret->getContainers()) . ') should be <= MaxResults (' . $options->getMaxResults() . ')');
  290. if (BlobServiceFunctionalTestData::$nonExistBlobPrefix == $options->getPrefix()) {
  291. $this->assertEquals(0, count($ret->getContainers()), 'when no next marker and Prefix=(\'' . $options->getPrefix() . '\'), then Blobs length');
  292. } else if (BlobServiceFunctionalTestData::$testUniqueId ==$options->getPrefix()) {
  293. // Need to futz with the mod because you are allowed to get MaxResults items returned.
  294. $expectedCount = count(BlobServiceFunctionalTestData::$testContainerNames) % $options->getMaxResults();
  295. if (!$this->isEmulated()) {
  296. $expectedCount += 1;
  297. }
  298. $this->assertEquals(
  299. $expectedCount,
  300. count($ret->getContainers()),
  301. 'when no next marker and Prefix=(\'' . $options->getPrefix() . '\'), then Blobs length');
  302. } else {
  303. // Do not know how many there should be
  304. }
  305. } else {
  306. $this->assertEquals(
  307. count($ret->getContainers()),
  308. $options->getMaxResults(),
  309. 'when NextMarker (' . $ret->getNextMarker() . ')!=\'\', Blobs length (' . count($ret->getContainers()) . ') should be == MaxResults (' . $options->getMaxResults() . ')');
  310. if (!is_null($options->getPrefix()) && $options->getPrefix() == BlobServiceFunctionalTestData::$nonExistBlobPrefix) {
  311. $this->assertTrue(false, 'when a next marker and Prefix=(\'' . $options->getPrefix() . '\'), impossible');
  312. }
  313. }
  314. }
  315. /**
  316. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  317. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  318. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  319. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  320. */
  321. public function testCreateContainerNoOptions()
  322. {
  323. $this->createContainerWorker(null);
  324. }
  325. /**
  326. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  327. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  328. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  329. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  330. */
  331. public function testCreateContainer()
  332. {
  333. $interestingCreateContainerOptions = BlobServiceFunctionalTestData::getInterestingCreateContainerOptions();
  334. foreach($interestingCreateContainerOptions as $options) {
  335. $this->createContainerWorker($options);
  336. }
  337. }
  338. /**
  339. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  340. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  341. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  342. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  343. */
  344. private function createContainerWorker($options)
  345. {
  346. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  347. $created = false;
  348. try {
  349. if (is_null($options)) {
  350. $this->restProxy->createContainer($container);
  351. } else {
  352. $this->restProxy->createContainer($container, $options);
  353. }
  354. $created = true;
  355. if (is_null($options)) {
  356. $options = new CreateContainerOptions();
  357. }
  358. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  359. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  360. }
  361. // Now check that the $container was $created correctly.
  362. // Make sure that the list of all applicable containers is correctly updated.
  363. $opts = new ListContainersOptions();
  364. $opts->setPrefix(BlobServiceFunctionalTestData::$testUniqueId);
  365. $qs = $this->restProxy->listContainers($opts);
  366. $this->assertEquals(count($qs->getContainers()), count(BlobServiceFunctionalTestData::$testContainerNames) + 1, 'After adding one, with Prefix=(\'' . BlobServiceFunctionalTestData::$testUniqueId . '\'), then Containers length');
  367. // Check the metadata on the container
  368. $ret = $this->restProxy->getContainerMetadata($container);
  369. $this->verifyCreateContainerWorker($ret, $options);
  370. $this->restProxy->deleteContainer($container);
  371. } catch (ServiceException $e) {
  372. if (is_null($options)) {
  373. $options = new CreateContainerOptions();
  374. }
  375. if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) {
  376. throw $e;
  377. } else {
  378. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  379. }
  380. }
  381. if ($created) {
  382. try {
  383. $this->restProxy->deleteContainer($container);
  384. } catch (ServiceException $e) {
  385. // Ignore.
  386. }
  387. }
  388. }
  389. private function verifyCreateContainerWorker($ret, $options)
  390. {
  391. if (is_null($options->getMetadata())) {
  392. $this->assertNotNull($ret->getMetadata(), 'container Metadata');
  393. $this->assertEquals(0, count($ret->getMetadata()), 'count container Metadata');
  394. } else {
  395. $this->assertNotNull($ret->getMetadata(), 'container Metadata');
  396. $this->assertEquals(count($options->getMetadata()), count($ret->getMetadata()), 'Metadata');
  397. $retMetadata = $ret->getMetadata();
  398. foreach($options->getMetadata() as $key => $value) {
  399. $this->assertEquals($value, $retMetadata[$key], 'Metadata(' . $key . ')');
  400. }
  401. }
  402. }
  403. /**
  404. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  405. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  406. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  407. */
  408. public function testDeleteContainerNoOptions()
  409. {
  410. $this->deleteContainerWorker(null);
  411. }
  412. /**
  413. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  414. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  415. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  416. */
  417. public function testDeleteContainer()
  418. {
  419. $interestingDeleteContainerOptions = BlobServiceFunctionalTestData::getInterestingDeleteContainerOptions();
  420. foreach($interestingDeleteContainerOptions as $options) {
  421. $this->deleteContainerWorker($options);
  422. }
  423. }
  424. /**
  425. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  426. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  427. * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  428. */
  429. private function deleteContainerWorker($options)
  430. {
  431. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  432. // Make sure there is something to delete.
  433. $this->restProxy->createContainer($container);
  434. // Make sure that the list of all applicable containers is correctly updated.
  435. $opts = new ListContainersOptions();
  436. $opts->setPrefix(BlobServiceFunctionalTestData::$testUniqueId);
  437. $qs = $this->restProxy->listContainers($opts);
  438. $this->assertEquals(
  439. count($qs->getContainers()),
  440. count(BlobServiceFunctionalTestData::$testContainerNames) + 1,
  441. 'After adding one, with Prefix=(\'' . BlobServiceFunctionalTestData::$testUniqueId . '\'), then Containers length');
  442. $deleted = false;
  443. try {
  444. if (is_null($options)) {
  445. $this->restProxy->deleteContainer($container);
  446. } else {
  447. $this->restProxy->deleteContainer($container, $options);
  448. }
  449. $deleted = true;
  450. if (is_null($options)) {
  451. $options = new DeleteContainerOptions();
  452. }
  453. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  454. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  455. }
  456. if (!$this->isEmulated() &&
  457. !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
  458. $this->assertTrue(false, 'Failing access condition should throw');
  459. }
  460. // Make sure that the list of all applicable containers is correctly updated.
  461. $opts = new ListContainersOptions();
  462. $opts->setPrefix(BlobServiceFunctionalTestData::$testUniqueId);
  463. $qs = $this->restProxy->listContainers($opts);
  464. $this->assertEquals(
  465. count($qs->getContainers()),
  466. count(BlobServiceFunctionalTestData::$testContainerNames),
  467. 'After adding then deleting one, with Prefix=(\'' . BlobServiceFunctionalTestData::$testUniqueId . '\'), then Containers length');
  468. // Nothing else interesting to check for the $options.
  469. } catch (ServiceException $e) {
  470. if (is_null($options)) {
  471. $options = new DeleteContainerOptions();
  472. }
  473. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  474. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  475. } else if (!$this->isEmulated() && !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
  476. $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'getCode');
  477. } else {
  478. throw $e;
  479. }
  480. }
  481. if (!$deleted) {
  482. // Try again. If it does not work, not much else to try.
  483. $this->restProxy->deleteContainer($container);
  484. }
  485. }
  486. /**
  487. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  488. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  489. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  490. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  491. */
  492. public function testGetContainerMetadataNoOptions()
  493. {
  494. $metadata = BlobServiceFunctionalTestData::getNiceMetadata();
  495. $this->getContainerMetadataWorker(null, $metadata);
  496. }
  497. /**
  498. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  499. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  500. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  501. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  502. */
  503. public function testGetContainerMetadata()
  504. {
  505. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  506. $metadata = BlobServiceFunctionalTestData::getNiceMetadata();
  507. foreach($interestingTimeouts as $timeout) {
  508. $options = new BlobServiceOptions();
  509. $options->setTimeout($timeout);
  510. $this->getContainerMetadataWorker($options, $metadata);
  511. }
  512. }
  513. /**
  514. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  515. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  516. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  517. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  518. */
  519. private function getContainerMetadataWorker($options, $metadata)
  520. {
  521. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  522. // Make sure there is something to test
  523. $this->restProxy->createContainer($container);
  524. $this->restProxy->setContainerMetadata($container, $metadata);
  525. try {
  526. $res = (is_null($options) ? $this->restProxy->getContainerMetadata($container) : $this->restProxy->getContainerMetadata($container, $options));
  527. if (is_null($options)) {
  528. $options = new BlobServiceOptions();
  529. }
  530. if (!is_null($options->getTimeout()) && $options->getTimeout() <= 0) {
  531. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  532. }
  533. $this->verifyGetContainerMetadataWorker($res, $metadata);
  534. } catch (ServiceException $e) {
  535. if (is_null($options->getTimeout()) || $options->getTimeout() > 0) {
  536. throw $e;
  537. } else {
  538. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  539. }
  540. }
  541. // Clean up.
  542. $this->restProxy->deleteContainer($container);
  543. }
  544. private function verifyGetContainerMetadataWorker($ret, $metadata)
  545. {
  546. $this->assertNotNull($ret->getMetadata(), 'container Metadata');
  547. $this->assertNotNull($ret->getETag(), 'container getETag');
  548. $this->assertNotNull($ret->getLastModified(), 'container getLastModified');
  549. $this->assertEquals(count($metadata), count($ret->getMetadata()), 'Metadata');
  550. $md = $ret->getMetadata();
  551. foreach($metadata as $key => $value) {
  552. $this->assertEquals($value, $md[$key], 'Metadata(' . $key . ')');
  553. }
  554. // Make sure the last modified date is within 10 seconds
  555. $now = new \DateTime();
  556. $this->assertTrue(
  557. BlobServiceFunctionalTestData::diffInTotalSeconds($ret->getLastModified(), $now) < 10,
  558. 'Last modified date (' . $ret->getLastModified()->format(\DateTime::RFC1123) . ')'.
  559. ' should be within 10 seconds of $now (' . $now->format(\DateTime::RFC1123) . ')');
  560. }
  561. /**
  562. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  563. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  564. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  565. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  566. */
  567. public function testSetContainerMetadataNoOptions()
  568. {
  569. $interestingMetadata = BlobServiceFunctionalTestData::getInterestingMetadata();
  570. foreach($interestingMetadata as $metadata) {
  571. $this->setContainerMetadataWorker(null, $metadata);
  572. }
  573. }
  574. /**
  575. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  576. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  577. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  578. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  579. */
  580. public function testSetContainerMetadata()
  581. {
  582. $interestingSetContainerMetadataOptions = BlobServiceFunctionalTestData::getSetContainerMetadataOptions();
  583. $interestingMetadata = BlobServiceFunctionalTestData::getInterestingMetadata();
  584. foreach($interestingSetContainerMetadataOptions as $options) {
  585. foreach($interestingMetadata as $metadata) {
  586. $this->setContainerMetadataWorker($options, $metadata);
  587. }
  588. }
  589. }
  590. /**
  591. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  592. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  593. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerMetadata
  594. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  595. */
  596. private function setContainerMetadataWorker($options, $metadata)
  597. {
  598. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  599. // Make sure there is something to test
  600. $this->restProxy->createContainer($container);
  601. $firstkey = '';
  602. if (!is_null($metadata) && count($metadata) > 0) {
  603. $firstkey = array_keys($metadata);
  604. $firstkey = $firstkey[0];
  605. }
  606. try {
  607. try {
  608. // And put in some metadata
  609. if (is_null($options)) {
  610. $this->restProxy->setContainerMetadata($container, $metadata);
  611. } else {
  612. $this->restProxy->setContainerMetadata($container, $metadata, $options);
  613. }
  614. if (is_null($options)) {
  615. $options = new SetContainerMetadataOptions();
  616. }
  617. $this->assertFalse(
  618. Utilities::startsWith($firstkey, '<'),
  619. 'Should get HTTP request error if the metadata is invalid');
  620. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  621. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  622. }
  623. // setMetadata only honors If-Modified-Since
  624. if (!$this->isEmulated() &&
  625. !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())
  626. && (!is_null($options->getAccessCondition())
  627. && $options->getAccessCondition()->getHeader() != Resources::IF_UNMODIFIED_SINCE)) {
  628. $this->assertTrue(false, 'Expect failing access condition to throw');
  629. }
  630. $res = $this->restProxy->getContainerMetadata($container);
  631. $this->verifyGetContainerMetadataWorker($res, $metadata);
  632. } catch (\HTTP_Request2_LogicException $e) {
  633. $this->assertTrue(
  634. Utilities::startsWith($firstkey, '<'),
  635. 'Should get HTTP request error only if the metadata is invalid');
  636. }
  637. } catch (ServiceException $e) {
  638. if (!$this->isEmulated() &&
  639. !BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition()) &&
  640. (!is_null($options->getAccessCondition()) &&
  641. $options->getAccessCondition()->getHeader() != Resources::IF_UNMODIFIED_SINCE)) {
  642. // setMetadata only honors If-Modified-Since
  643. $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'getCode');
  644. } else if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  645. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  646. } else {
  647. throw $e;
  648. }
  649. }
  650. // Clean up.
  651. $this->restProxy->deleteContainer($container);
  652. }
  653. /**
  654. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  655. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  656. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerProperties
  657. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  658. */
  659. public function testGetContainerPropertiesNoOptions()
  660. {
  661. $metadata = BlobServiceFunctionalTestData::getNiceMetadata();
  662. $this->getContainerPropertiesWorker(null, $metadata);
  663. }
  664. /**
  665. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  666. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  667. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerProperties
  668. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  669. */
  670. public function testGetContainerProperties()
  671. {
  672. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  673. $metadata = BlobServiceFunctionalTestData::getNiceMetadata();
  674. foreach($interestingTimeouts as $timeout) {
  675. $options = new BlobServiceOptions();
  676. $options->setTimeout($timeout);
  677. $this->getContainerPropertiesWorker($options, $metadata);
  678. }
  679. }
  680. /**
  681. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  682. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  683. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerProperties
  684. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerMetadata
  685. */
  686. private function getContainerPropertiesWorker($options, $metadata)
  687. {
  688. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  689. // Make sure there is something to test
  690. $this->restProxy->createContainer($container);
  691. $this->restProxy->setContainerMetadata($container, $metadata);
  692. try {
  693. $res = (is_null($options) ? $this->restProxy->getContainerProperties($container) : $this->restProxy->getContainerProperties($container, $options));
  694. if (is_null($options)) {
  695. $options = new BlobServiceOptions();
  696. }
  697. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  698. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  699. }
  700. $this->verifyGetContainerMetadataWorker($res, $metadata);
  701. } catch (ServiceException $e) {
  702. if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) {
  703. throw $e;
  704. } else {
  705. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  706. }
  707. }
  708. // Clean up.
  709. $this->restProxy->deleteContainer($container);
  710. }
  711. /**
  712. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  713. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  714. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  715. */
  716. public function testGetContainerACLNoOptions()
  717. {
  718. $this->getContainerACLWorker(null);
  719. }
  720. /**
  721. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  722. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  723. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  724. */
  725. public function testGetContainerACL()
  726. {
  727. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  728. foreach($interestingTimeouts as $timeout) {
  729. $options = new BlobServiceOptions();
  730. $options->setTimeout($timeout);
  731. $this->getContainerACLWorker($options);
  732. }
  733. }
  734. /**
  735. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  736. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  737. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  738. */
  739. private function getContainerACLWorker($options)
  740. {
  741. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  742. // Make sure there is something to test
  743. $this->restProxy->createContainer($container);
  744. try {
  745. $res = (is_null($options) ? $this->restProxy->getContainerACL($container) : $this->restProxy->getContainerACL($container, $options));
  746. if (is_null($options)) {
  747. $options = new BlobServiceOptions();
  748. }
  749. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  750. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  751. }
  752. $this->verifyGetContainerACLWorker($res);
  753. } catch (ServiceException $e) {
  754. if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) {
  755. throw $e;
  756. } else {
  757. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  758. }
  759. }
  760. // Clean up.
  761. $this->restProxy->deleteContainer($container);
  762. }
  763. private function verifyGetContainerACLWorker($ret)
  764. {
  765. $this->assertNotNull($ret->getContainerACL(), '$ret->getContainerACL');
  766. $this->assertNotNull($ret->getETag(), '$ret->getETag');
  767. $this->assertNotNull($ret->getLastModified(), '$ret->getLastModified');
  768. $this->assertNull($ret->getContainerACL()->getPublicAccess(), '$ret->getContainerACL->getPublicAccess');
  769. $this->assertNotNull($ret->getContainerACL()->getSignedIdentifiers(), '$ret->getContainerACL->getSignedIdentifiers');
  770. // Make sure the last modified date is within 10 seconds
  771. $now = new \DateTime();
  772. $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds(
  773. $ret->getLastModified(),
  774. $now) < 10000,
  775. 'Last modified date (' . $ret->getLastModified()->format(\DateTime::RFC1123) . ') ' .
  776. 'should be within 10 seconds of $now (' . $now->format(\DateTime::RFC1123) . ')');
  777. }
  778. /**
  779. * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  780. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  781. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  782. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  783. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerACL
  784. */
  785. public function testSetContainerACLNoOptions()
  786. {
  787. $interestingACL = BlobServiceFunctionalTestData::getInterestingACL();
  788. foreach($interestingACL as $acl) {
  789. $this->setContainerACLWorker(null, $acl);
  790. }
  791. }
  792. /**
  793. * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  794. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  795. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  796. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  797. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerACL
  798. */
  799. public function testSetContainerACL()
  800. {
  801. $interestingACL = BlobServiceFunctionalTestData::getInterestingACL();
  802. $interestingTimeouts = BlobServiceFunctionalTestData::getInterestingTimeoutValues();
  803. foreach($interestingTimeouts as $timeout) {
  804. foreach($interestingACL as $acl) {
  805. $options = new BlobServiceOptions();
  806. $options->setTimeout($timeout);
  807. $this->setContainerACLWorker($options, $acl);
  808. }
  809. }
  810. }
  811. /**
  812. * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  813. * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  814. * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  815. * @covers WindowsAzure\Blob\BlobRestProxy::getContainerACL
  816. * @covers WindowsAzure\Blob\BlobRestProxy::setContainerACL
  817. */
  818. private function setContainerACLWorker($options, $acl)
  819. {
  820. $container = BlobServiceFunctionalTestData::getInterestingContainerName();
  821. // Make sure there is something to test
  822. $this->restProxy->createContainer($container);
  823. $blobContent = uniqid();
  824. $this->restProxy->createBlockBlob($container, 'test', $blobContent);
  825. try {
  826. if (is_null($options)) {
  827. $this->restProxy->setContainerACL($container, $acl);
  828. $this->restProxy->setContainerACL($container, $acl);
  829. } else {
  830. $this->restProxy->setContainerACL($container, $acl, $options);
  831. $this->restProxy->setContainerACL($container, $acl, $options);
  832. }
  833. if (is_null($options)) {
  834. $options = new BlobServiceOptions();
  835. }
  836. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  837. $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
  838. }
  839. $res = $this->restProxy->getContainerACL($container);
  840. $this->verifySetContainerACLWorker($res, $container, $acl, $blobContent);
  841. } catch (ServiceException $e) {
  842. if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
  843. $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode');
  844. } else {
  845. throw $e;
  846. }
  847. }
  848. // Clean up.
  849. $this->restProxy->deleteContainer($container);
  850. }
  851. private function verifySetContainerACLWorker($ret, $container, $acl, $blobContent)
  852. {
  853. $this->assertNotNull($ret->getContainerACL(), '$ret->getContainerACL');
  854. $this->assertNotNull($ret->getETag(), '$ret->getContainerACL->getETag');
  855. $now = new \DateTime();
  856. $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds(
  857. $ret->getLastModified(),
  858. $now) < 10000,
  859. 'Last modified date (' . $ret->getLastModified()->format(\DateTime::RFC1123) . ') ' .
  860. 'should be within 10 seconds of $now (' . $now->format(\DateTime::RFC1123) . ')');
  861. $this->assertNotNull($ret->getContainerACL()->getSignedIdentifiers(), '$ret->getContainerACL->getSignedIdentifiers');
  862. $this->assertEquals((is_null($acl->getPublicAccess()) ? '' : $acl->getPublicAccess()), $ret->getContainerACL()->getPublicAccess(), '$ret->getContainerACL->getPublicAccess');
  863. $expIds = $acl->getSignedIdentifiers();
  864. $actIds = $ret->getContainerACL()->getSignedIdentifiers();
  865. $this->assertEquals(count($expIds), count($actIds), '$ret->getContainerACL->getSignedIdentifiers');
  866. for ($i = 0; $i < count($expIds); $i++) {
  867. $expId = $expIds[$i];
  868. $actId = $actIds[$i];
  869. $this->assertEquals($expId->getId(), $actId->getId(), 'SignedIdentifiers['+$i+']->getId');
  870. $this->assertEquals(
  871. $expId->getAccessPolicy()->getPermission(),
  872. $actId->getAccessPolicy()->getPermission(),
  873. 'SignedIdentifiers['+$i+']->getAccessPolicy->getPermission');
  874. $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds(
  875. $expId->getAccessPolicy()->getStart(),
  876. $actId->getAccessPolicy()->getStart()) < 1,
  877. 'SignedIdentifiers['+$i+']->getAccessPolicy->getStart should match within 1 second, ' .
  878. 'exp=' . $expId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123) . ', ' .
  879. 'act=' . $actId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123));
  880. $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds(
  881. $expId->getAccessPolicy()->getExpiry(),
  882. $actId->getAccessPolicy()->getExpiry()) < 1,
  883. 'SignedIdentifiers['+$i+']->getAccessPolicy->getExpiry should match within 1 second, ' .
  884. 'exp=' . $expId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123) . ', ' .
  885. 'act=' . $actId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123));
  886. }
  887. if (!$this->isEmulated()) {
  888. $settings = StorageServiceSettings::createFromConnectionString($this->connectionString);
  889. $containerAddress = $settings->getBlobEndpointUri() . '/' . $container;
  890. $blobListAddress = $containerAddress . '?restype=container&comp=list';
  891. $blobAddress = $containerAddress . '/test';
  892. $canDownloadBlobList = $this->canDownloadFromUrl($blobListAddress,
  893. "<?xml version=\"1.0\" encoding=\"utf-8\"?" . "><EnumerationResults");
  894. $canDownloadBlob = $this->canDownloadFromUrl($blobAddress, $blobContent);
  895. if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::CONTAINER_AND_BLOBS) {
  896. // Full public read access: Container and blob data can be read via anonymous request.
  897. // Clients can enumerate blobs within the $container via anonymous request,
  898. // but cannot enumerate containers within the storage account.
  899. $this->assertTrue($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
  900. $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
  901. } else if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::BLOBS_ONLY) {
  902. // Public read access for blobs only: Blob data within this container
  903. // can be read via anonymous request, but $container data is not available.
  904. // Clients cannot enumerate blobs within the $container via anonymous request.
  905. $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
  906. $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
  907. } else {
  908. // No public read access: Container and blob data can be read by the account owner only.
  909. $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
  910. $this->assertFalse($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
  911. }
  912. }
  913. }
  914. private function canDownloadFromUrl($blobAddress, $expectedStartingValue)
  915. {
  916. $url = parse_url($blobAddress);
  917. $host = $url['host'];
  918. $fp = fsockopen($host, '80');
  919. $request = 'GET ' . $blobAddress . ' HTTP/1.1' . "\r\n" . 'Host: ' . $host ."\r\n\r\n";
  920. fputs($fp, $request);
  921. $value = fread($fp, 1000);
  922. fclose($fp);
  923. return strpos($value, $expectedStartingValue) !== false;
  924. }
  925. /**
  926. * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  927. */
  928. public function testListBlobsNoOptions()
  929. {
  930. $container = BlobServiceFunctionalTestData::getContainerName();
  931. $this->listBlobsWorker($container, null);
  932. }
  933. // This fails because the service returns the container list
  934. // instead of the blob list. In principle, the service can
  935. // distinguish between the two, because this is of the
  936. // format:
  937. // /?restype=container&comp=list
  938. // whereas the container list has this format:
  939. // /?comp=list
  940. // /**
  941. // * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  942. // */
  943. // public function testListBlobsNoOptionsRoot()
  944. // {
  945. // $container = null;
  946. // $this->listBlobsWorker($container, null);
  947. // }
  948. /**
  949. * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  950. */
  951. public function testListBlobsNoOptionsExplicitRoot()
  952. {
  953. $container = '$root';
  954. $this->listBlobsWorker($container, null);
  955. }
  956. /**
  957. * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  958. */
  959. public function testListBlobs()
  960. {
  961. $interestingListBlobsOptions = BlobServiceFunctionalTestData::getInterestingListBlobsOptions();

Large files files are truncated, but you can click here to view the full file