PageRenderTime 68ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/functional/WindowsAzure/Blob/BlobServiceFunctionalTest.php

http://github.com/WindowsAzure/azure-sdk-for-php
PHP | 1493 lines | 1001 code | 169 blank | 323 comment | 201 complexity | 372f914ae631f6d11f46c29755926314 MD5 | raw file

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

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