/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobMetadata */ private function getBlobPropertiesWorker($container, $options) { $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container); // Make sure there is something to test $createPageBlobResult = $this->restProxy->createPageBlob($container, $blob, 512); $metadata = BlobServiceFunctionalTestData::getNiceMetadata(); $this->restProxy->setBlobMetadata($container, $blob, $metadata); // Do not set the properties, there should be default properties. if (!is_null($options)) { BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $createPageBlobResult->getETag()); } try { $res = is_null($options) ? $this->restProxy->getBlobProperties($container, $blob) : $this->restProxy->getBlobProperties($container, $blob, $options); if (is_null($options)) { $options = new GetBlobPropertiesOptions(); } if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertTrue(false, 'Expect negative timeouts in $options to throw'); } if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertTrue(false, 'Failing temporal access condition should throw'); } $this->verifyGetBlobPropertiesWorker($res, $metadata, null); } catch (ServiceException $e) { if (!is_null($options->getAccessCondition()) && !$this->hasSecureEndpoint() && $e->getCode() == TestResources::STATUS_FORBIDDEN) { // Proxies can eat the access condition headers of // unsecured (http) requests, which causes the authentication // to fail, with a 403:Forbidden. There is nothing much that // can be done about this, other than ignore it. } else { if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: getCode'); } else { if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { if ($options->getAccessCondition()->getHeader() == Resources::IF_MODIFIED_SINCE) { $this->assertEquals(TestResources::STATUS_NOT_MODIFIED, $e->getCode(), 'bad temporal access condition IF_MODIFIED_SINCE: getCode'); } else { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition: getCode'); } } else { throw $e; } } } } // Clean up. $this->restProxy->deleteBlob($container, $blob); }
public static function getGetBlobPropertiesOptions() { $ret = array(); $options = new GetBlobPropertiesOptions(); array_push($ret, $options); $options = new GetBlobPropertiesOptions(); $options->setTimeout(10); array_push($ret, $options); $options = new GetBlobPropertiesOptions(); $options->setTimeout(-10); array_push($ret, $options); // Get Blob Properties only supports the temporal access conditions. foreach (self::getTemporalAccessConditions() as $ac) { $options = new GetBlobPropertiesOptions(); $options->setAccessCondition($ac); array_push($ret, $options); } return $ret; }
/** * Returns all properties and metadata on the blob. * * @param string $container name of the container * @param string $blob name of the blob * @param Models\GetBlobPropertiesOptions $options optional parameters * * @return Models\GetBlobPropertiesResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179394.aspx */ public function getBlobProperties($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); $method = Resources::HTTP_HEAD; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = Resources::STATUS_OK; if (is_null($options)) { $options = new GetBlobPropertiesOptions(); } $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition()); $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot()); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $headers = $response->getHeaders(); $formattedHeaders = HttpFormatter::formatHeaders($headers); return $this->_getBlobPropertiesResultFromResponse($formattedHeaders); }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobSnapshot * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlockBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties */ public function testCreateBlobSnapshotWithOptionsWorks() { // Act $container = self::$_test_container_for_blobs; $blob = 'test3'; $this->restProxy->createBlockBlob($container, $blob, 'some content'); $opts = new CreateBlobSnapshotOptions(); $metadata = array('test' => 'bar', 'blah' => 'bleah'); $opts->setMetadata($metadata); $snapshot = $this->restProxy->createBlobSnapshot($container, $blob, $opts); $opts = new GetBlobPropertiesOptions(); $opts->setSnapshot($snapshot->getSnapshot()); $result = $this->restProxy->getBlobProperties($container, $blob, $opts); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals($snapshot->getETag(), $result->getProperties()->getETag(), '$result->getProperties()->getETag()'); $this->assertEquals($snapshot->getLastModified(), $result->getProperties()->getLastModified(), '$result->getProperties()->getLastModified()'); // The capitalizaion gets changed. $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $result->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $result->getMetadata())'); $this->assertTrue(!(array_search('bar', $result->getMetadata()) === FALSE), '!(array_search(\'bar\', $result->getMetadata()) === FALSE)'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $result->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $result->getMetadata())'); $this->assertTrue(!(array_search('bleah', $result->getMetadata()) === FALSE), '!(array_search(\'bleah\', $result->getMetadata()) === FALSE)'); }
/** * @covers MicrosoftAzure\Storage\Blob\Models\GetBlobPropertiesOptions::getSnapshot */ public function testGetSnapshot() { // Setup $blob = new GetBlobPropertiesOptions(); $expected = TestResources::QUEUE_URI; $blob->setSnapshot($expected); // Test $actual = $blob->getSnapshot(); // Assert $this->assertEquals($expected, $actual); }