/** * @covers MicrosoftAzure\Storage\Blob\Models\GetBlobPropertiesOptions::setAccessCondition */ public function testSetAccessCondition() { // Setup $expected = AccessCondition::none(); $result = new GetBlobPropertiesOptions(); // Test $result->setAccessCondition($expected); // Assert $this->assertEquals($expected, $result->getAccessCondition()); }
/** * @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); }
/** * 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); }