Added support for Blob E&R introduced in version 2015-12-11

This commit is contained in:
Xiaoning Liu 2017-08-10 18:58:07 +08:00 коммит произвёл Vincent Jiang (LEI)
Родитель 386cb3da3d
Коммит 6252474b3a
23 изменённых файлов: 455 добавлений и 164 удалений

Просмотреть файл

@ -1,5 +1,12 @@
All
* Fixed wrong PHPUnit `@covers` tags in unit and functional test.
Blob
* Following methods of `MicrosoftAzure\Storage\Blob\BlobRestProxy` now return the x-ms-request-server-encrypted response header. This header is set to true if the contents of the request have been successfully encrypted.
- `createBlockBlob`, `createPageBlob`, `createAppendBlob`, `createBlobPages`, `createBlobBlock`, `appendBlock`, `commitBlobBlocks` and `setBlobMetadata`.
* Following methods of `MicrosoftAzure\Storage\Blob\BlobRestProxy` now return the x-ms-server-encrypted response header. This header is set to true if the blob data and application metadata are completely encrypted. If the blob is not encrypted, or if only parts of the blob/application metadata are encrypted, this header is set to false.
- `getBlob` and `getBlobProperties`.
2017.07 - version 0.17.0
All

Просмотреть файл

@ -1398,7 +1398,6 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$postParams = array();
$queryParams = array();
$path = $this->createPath($container, $blob);
$statusCode = Resources::STATUS_CREATED;
if (is_null($options)) {
$options = new CreateBlobOptions();
@ -1569,7 +1568,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
* @param string|resource|StreamInterface $content The content of the blob.
* @param Models\CreateBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx
*/
@ -1582,7 +1581,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$body = Psr7\stream_for($content);
//If the size of the stream is not seekable or larger than the single
//upload threashold then call concurrent upload. Otherwise call putBlob.
//upload threshold then call concurrent upload. Otherwise call putBlob.
$promise = null;
if (!Utilities::isStreamLargerThanSizeOrNotSeekable(
$body,

Просмотреть файл

@ -519,7 +519,7 @@ interface IBlob
* @param string|resource|StreamInterface $content The content of the blob.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
*
* @return BlobModels\PutBlobResult
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx
*/

Просмотреть файл

@ -21,7 +21,7 @@
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
namespace MicrosoftAzure\Storage\Blob\Models;
use MicrosoftAzure\Storage\Common\Internal\Resources;
@ -39,11 +39,12 @@ use MicrosoftAzure\Storage\Common\Internal\Utilities;
*/
class AppendBlockResult
{
private $_etag;
private $_lastModified;
private $_contentMD5;
private $_appendOffset;
private $_committedBlockCount;
private $appendOffset;
private $committedBlockCount;
private $contentMD5;
private $etag;
private $lastModified;
private $requestServerEncrypted;
/**
* Creates AppendBlockResult object from the response of the put block request.
@ -57,54 +58,54 @@ class AppendBlockResult
public static function create(array $headers)
{
$result = new AppendBlockResult();
if (Utilities::arrayKeyExistsInsensitive(
Resources::ETAG,
$headers
)) {
$result->setEtag(
Utilities::tryGetValueInsensitive(Resources::ETAG, $headers)
);
}
$result->setAppendOffset(
intval(
Utilities::tryGetValueInsensitive(
Resources::X_MS_BLOB_APPEND_OFFSET, $headers
)
)
);
$result->setCommittedBlockCount(
intval(
Utilities::tryGetValueInsensitive(
Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT, $headers
)
)
);
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
$result->setEtag(
Utilities::tryGetValueInsensitive(Resources::ETAG, $headers)
);
if (Utilities::arrayKeyExistsInsensitive(
Resources::LAST_MODIFIED,
$headers
)) {
$lastModified = Utilities::tryGetValueInsensitive(Resources::LAST_MODIFIED, $headers);
$lastModified = Utilities::tryGetValueInsensitive(
Resources::LAST_MODIFIED,
$headers
);
$lastModified = Utilities::rfc1123ToDateTime($lastModified);
$result->setLastModified($lastModified);
}
if (Utilities::arrayKeyExistsInsensitive(
Resources::CONTENT_MD5,
$headers
)) {
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
}
$result->setRequestServerEncrypted(
Utilities::toBoolean(
Utilities::tryGetValueInsensitive(
Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
$headers
),
true
)
);
if (Utilities::arrayKeyExistsInsensitive(
Resources::X_MS_BLOB_APPEND_OFFSET,
$headers
)) {
$result->setAppendOffset(
intval(Utilities::tryGetValueInsensitive(Resources::X_MS_BLOB_APPEND_OFFSET, $headers))
);
}
if (Utilities::arrayKeyExistsInsensitive(
Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT,
$headers
)) {
$committedBlockCount = Utilities::tryGetValueInsensitive(
Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT,
$headers
);
$result->setCommittedBlockCount(intval($committedBlockCount));
}
return $result;
}
@ -116,7 +117,7 @@ class AppendBlockResult
*/
public function getEtag()
{
return $this->_etag;
return $this->etag;
}
/**
@ -128,7 +129,7 @@ class AppendBlockResult
*/
protected function setEtag($etag)
{
$this->_etag = $etag;
$this->etag = $etag;
}
/**
@ -138,7 +139,7 @@ class AppendBlockResult
*/
public function getLastModified()
{
return $this->_lastModified;
return $this->lastModified;
}
/**
@ -150,7 +151,7 @@ class AppendBlockResult
*/
protected function setLastModified($lastModified)
{
$this->_lastModified = $lastModified;
$this->lastModified = $lastModified;
}
/**
@ -160,7 +161,7 @@ class AppendBlockResult
*/
public function getContentMD5()
{
return $this->_contentMD5;
return $this->contentMD5;
}
/**
@ -172,7 +173,7 @@ class AppendBlockResult
*/
protected function setContentMD5($contentMD5)
{
$this->_contentMD5 = $contentMD5;
$this->contentMD5 = $contentMD5;
}
/**
@ -182,7 +183,7 @@ class AppendBlockResult
*/
public function getAppendOffset()
{
return $this->_appendOffset;
return $this->appendOffset;
}
/**
@ -194,7 +195,7 @@ class AppendBlockResult
*/
protected function setAppendOffset($appendOffset)
{
$this->_appendOffset = $appendOffset;
$this->appendOffset = $appendOffset;
}
/**
@ -204,7 +205,7 @@ class AppendBlockResult
*/
public function getCommittedBlockCount()
{
return $this->_committedBlockCount;
return $this->committedBlockCount;
}
/**
@ -216,6 +217,28 @@ class AppendBlockResult
*/
protected function setCommittedBlockCount($committedBlockCount)
{
$this->_committedBlockCount = $committedBlockCount;
$this->committedBlockCount = $committedBlockCount;
}
/**
* Gets the whether the contents of the request are successfully encrypted.
*
* @return boolean
*/
public function getRequestServerEncrypted()
{
return $this->requestServerEncrypted;
}
/**
* Sets the request server encryption value.
*
* @param boolean $requestServerEncrypted
*
* @return void
*/
public function setRequestServerEncrypted($requestServerEncrypted)
{
$this->requestServerEncrypted = $requestServerEncrypted;
}
}

Просмотреть файл

@ -55,6 +55,7 @@ class BlobProperties
private $_leaseState;
private $_leaseDuration;
private $_sequenceNumber;
private $_serverEncrypted;
private $_committedBlockCount;
private $_copyState;
@ -101,6 +102,9 @@ class BlobProperties
$result->setLeaseStatus(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_STATUS));
$result->setLeaseState(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_STATE));
$result->setLeaseDuration(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_DURATION));
$result->setServerEncrypted(
Utilities::toBoolean(Utilities::trygetvalue($clean, Resources::X_MS_SERVER_ENCRYPTED), true)
);
$result->setCommittedBlockCount(
intval(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT))
);
@ -442,6 +446,28 @@ class BlobProperties
$this->_sequenceNumber = $sequenceNumber;
}
/**
* Gets the server encryption status of the blob.
*
* @return boolean
*/
public function getServerEncrypted()
{
return $this->_serverEncrypted;
}
/**
* Sets the server encryption status of the blob.
*
* @param boolean $serverEncrypted
*
* @return void
*/
public function setServerEncrypted($serverEncrypted)
{
$this->_serverEncrypted = $serverEncrypted;
}
/**
* Gets the number of committed blocks present in the blob.
*

Просмотреть файл

@ -43,7 +43,7 @@ class CommitBlobBlocksOptions extends BlobServiceOptions
private $_cacheControl;
private $_contentDisposition;
private $_metadata;
/**
* Gets ContentType.
*

Просмотреть файл

@ -40,11 +40,12 @@ use MicrosoftAzure\Storage\Common\Internal\Utilities;
*/
class CreateBlobPagesResult
{
private $_lastModified;
private $_etag;
private $_sequenceNumber;
private $_contentMD5;
private $contentMD5;
private $etag;
private $lastModified;
private $requestServerEncrypted;
private $sequenceNumber;
/**
* Creates CreateBlobPagesResult object from $parsed response in array
* representation
@ -64,12 +65,27 @@ class CreateBlobPagesResult
$date = Utilities::rfc1123ToDateTime($date);
$result->setETag($clean[Resources::ETAG]);
$result->setLastModified($date);
$result->setContentMD5(
Utilities::tryGetValue($clean, Resources::CONTENT_MD5)
);
$result->setRequestServerEncrypted(
Utilities::toBoolean(
Utilities::tryGetValueInsensitive(
Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
$headers
),
true
)
);
$result->setSequenceNumber(
intval(
Utilities::tryGetValue($clean, Resources::X_MS_BLOB_SEQUENCE_NUMBER)
Utilities::tryGetValue(
$clean,
Resources::X_MS_BLOB_SEQUENCE_NUMBER
)
)
);
@ -83,7 +99,7 @@ class CreateBlobPagesResult
*/
public function getLastModified()
{
return $this->_lastModified;
return $this->lastModified;
}
/**
@ -96,7 +112,7 @@ class CreateBlobPagesResult
protected function setLastModified($lastModified)
{
Validate::isDate($lastModified);
$this->_lastModified = $lastModified;
$this->lastModified = $lastModified;
}
/**
@ -106,7 +122,7 @@ class CreateBlobPagesResult
*/
public function getETag()
{
return $this->_etag;
return $this->etag;
}
/**
@ -119,7 +135,7 @@ class CreateBlobPagesResult
protected function setETag($etag)
{
Validate::canCastAsString($etag, 'etag');
$this->_etag = $etag;
$this->etag = $etag;
}
/**
@ -129,7 +145,7 @@ class CreateBlobPagesResult
*/
public function getContentMD5()
{
return $this->_contentMD5;
return $this->contentMD5;
}
/**
@ -141,9 +157,31 @@ class CreateBlobPagesResult
*/
protected function setContentMD5($contentMD5)
{
$this->_contentMD5 = $contentMD5;
$this->contentMD5 = $contentMD5;
}
/**
* Gets the whether the contents of the request are successfully encrypted.
*
* @return boolean
*/
public function getRequestServerEncrypted()
{
return $this->requestServerEncrypted;
}
/**
* Sets the request server encryption value.
*
* @param boolean $requestServerEncrypted
*
* @return void
*/
public function setRequestServerEncrypted($requestServerEncrypted)
{
$this->requestServerEncrypted = $requestServerEncrypted;
}
/**
* Gets blob sequenceNumber.
*
@ -151,7 +189,7 @@ class CreateBlobPagesResult
*/
public function getSequenceNumber()
{
return $this->_sequenceNumber;
return $this->sequenceNumber;
}
/**
@ -164,6 +202,6 @@ class CreateBlobPagesResult
protected function setSequenceNumber($sequenceNumber)
{
Validate::isInteger($sequenceNumber, 'sequenceNumber');
$this->_sequenceNumber = $sequenceNumber;
$this->sequenceNumber = $sequenceNumber;
}
}

Просмотреть файл

@ -21,7 +21,7 @@
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
namespace MicrosoftAzure\Storage\Blob\Models;
use MicrosoftAzure\Storage\Common\Internal\Resources;
@ -39,9 +39,10 @@ use MicrosoftAzure\Storage\Common\Internal\Utilities;
*/
class PutBlobResult
{
private $_etag;
private $_lastModified;
private $_contentMD5;
private $contentMD5;
private $etag;
private $lastModified;
private $requestServerEncrypted;
/**
* Creates PutBlobResult object from the response of the put blob request.
@ -55,12 +56,14 @@ class PutBlobResult
public static function create(array $headers)
{
$result = new PutBlobResult();
$result->setETag(
Utilities::tryGetValueInsensitive(
Resources::ETAG,
$headers
)
);
if (Utilities::arrayKeyExistsInsensitive(
Resources::LAST_MODIFIED,
$headers
@ -71,16 +74,21 @@ class PutBlobResult
);
$result->setLastModified(Utilities::rfc1123ToDateTime($lastModified));
}
if (Utilities::arrayKeyExistsInsensitive(
Resources::CONTENT_MD5,
$headers
)) {
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
}
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
$result->setRequestServerEncrypted(
Utilities::toBoolean(
Utilities::tryGetValueInsensitive(
Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
$headers
),
true
)
);
return $result;
}
@ -91,7 +99,7 @@ class PutBlobResult
*/
public function getETag()
{
return $this->_etag;
return $this->etag;
}
/**
@ -103,9 +111,9 @@ class PutBlobResult
*/
protected function setETag($etag)
{
$this->_etag = $etag;
$this->etag = $etag;
}
/**
* Gets blob lastModified.
*
@ -113,7 +121,7 @@ class PutBlobResult
*/
public function getLastModified()
{
return $this->_lastModified;
return $this->lastModified;
}
/**
@ -125,7 +133,7 @@ class PutBlobResult
*/
protected function setLastModified(\DateTime $lastModified)
{
$this->_lastModified = $lastModified;
$this->lastModified = $lastModified;
}
/**
@ -135,7 +143,7 @@ class PutBlobResult
*/
public function getContentMD5()
{
return $this->_contentMD5;
return $this->contentMD5;
}
/**
@ -147,6 +155,28 @@ class PutBlobResult
*/
protected function setContentMD5($contentMD5)
{
$this->_contentMD5 = $contentMD5;
$this->contentMD5 = $contentMD5;
}
/**
* Gets the whether the contents of the request are successfully encrypted.
*
* @return boolean
*/
public function getRequestServerEncrypted()
{
return $this->requestServerEncrypted;
}
/**
* Sets the request server encryption value.
*
* @param boolean $requestServerEncrypted
*
* @return void
*/
public function setRequestServerEncrypted($requestServerEncrypted)
{
$this->requestServerEncrypted = $requestServerEncrypted;
}
}

Просмотреть файл

@ -39,7 +39,8 @@ use MicrosoftAzure\Storage\Common\Internal\Utilities;
*/
class PutBlockResult
{
private $_contentMD5;
private $contentMD5;
private $requestServerEncrypted;
/**
* Creates PutBlockResult object from the response of the put block request.
@ -53,14 +54,20 @@ class PutBlockResult
public static function create(array $headers)
{
$result = new PutBlockResult();
if (Utilities::arrayKeyExistsInsensitive(
Resources::CONTENT_MD5,
$headers
)) {
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
}
$result->setContentMD5(
Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers)
);
$result->setRequestServerEncrypted(
Utilities::toBoolean(
Utilities::tryGetValueInsensitive(
Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
$headers
),
true
)
);
return $result;
}
@ -72,7 +79,7 @@ class PutBlockResult
*/
public function getContentMD5()
{
return $this->_contentMD5;
return $this->contentMD5;
}
/**
@ -84,6 +91,28 @@ class PutBlockResult
*/
protected function setContentMD5($contentMD5)
{
$this->_contentMD5 = $contentMD5;
$this->contentMD5 = $contentMD5;
}
/**
* Gets the whether the contents of the request are successfully encrypted.
*
* @return boolean
*/
public function getRequestServerEncrypted()
{
return $this->requestServerEncrypted;
}
/**
* Sets the request server encryption value.
*
* @param boolean $requestServerEncrypted
*
* @return void
*/
public function setRequestServerEncrypted($requestServerEncrypted)
{
$this->requestServerEncrypted = $requestServerEncrypted;
}
}

Просмотреть файл

@ -40,9 +40,10 @@ use MicrosoftAzure\Storage\Common\Internal\Utilities;
*/
class SetBlobMetadataResult
{
private $_lastModified;
private $_etag;
private $etag;
private $lastModified;
private $requestServerEncrypted;
/**
* Creates SetBlobMetadataResult from response headers.
*
@ -55,16 +56,28 @@ class SetBlobMetadataResult
public static function create(array $headers)
{
$result = new SetBlobMetadataResult();
$result->setETag(Utilities::tryGetValueInsensitive(
Resources::ETAG,
$headers
));
$date = Utilities::tryGetValueInsensitive(
Resources::LAST_MODIFIED,
$headers
);
$result->setLastModified(Utilities::rfc1123ToDateTime($date));
$result->setETag(Utilities::tryGetValueInsensitive(
Resources::ETAG,
$headers
));
$result->setRequestServerEncrypted(
Utilities::toBoolean(
Utilities::tryGetValueInsensitive(
Resources::X_MS_REQUEST_SERVER_ENCRYPTED,
$headers
),
true
)
);
return $result;
}
@ -75,7 +88,7 @@ class SetBlobMetadataResult
*/
public function getLastModified()
{
return $this->_lastModified;
return $this->lastModified;
}
/**
@ -88,7 +101,7 @@ class SetBlobMetadataResult
protected function setLastModified(\DateTime $lastModified)
{
Validate::isDate($lastModified);
$this->_lastModified = $lastModified;
$this->lastModified = $lastModified;
}
/**
@ -98,7 +111,7 @@ class SetBlobMetadataResult
*/
public function getETag()
{
return $this->_etag;
return $this->etag;
}
/**
@ -111,6 +124,28 @@ class SetBlobMetadataResult
protected function setETag($etag)
{
Validate::canCastAsString($etag, 'etag');
$this->_etag = $etag;
$this->etag = $etag;
}
/**
* Gets the whether the contents of the request are successfully encrypted.
*
* @return boolean
*/
public function getRequestServerEncrypted()
{
return $this->requestServerEncrypted;
}
/**
* Sets the request server encryption value.
*
* @param boolean $requestServerEncrypted
*
* @return void
*/
public function setRequestServerEncrypted($requestServerEncrypted)
{
$this->requestServerEncrypted = $requestServerEncrypted;
}
}

Просмотреть файл

@ -187,6 +187,8 @@ class Resources
const X_MS_LEASE_BREAK_PERIOD = 'x-ms-lease-break-period';
const X_MS_DELETE_SNAPSHOTS = 'x-ms-delete-snapshots';
const X_MS_PAGE_WRITE = 'x-ms-page-write';
const X_MS_REQUEST_SERVER_ENCRYPTED = 'x-ms-request-server-encrypted';
const X_MS_SERVER_ENCRYPTED = 'x-ms-server-encrypted';
const X_MS_SNAPSHOT = 'x-ms-snapshot';
const X_MS_SOURCE_IF_MODIFIED_SINCE = 'x-ms-source-if-modified-since';
const X_MS_SOURCE_IF_UNMODIFIED_SINCE = 'x-ms-source-if-unmodified-since';

Просмотреть файл

@ -184,12 +184,12 @@ class ServiceRestProxy extends RestProxy
* by inserting a new key/value pair with the key 'number_of_concurrency'
* into the $requestOptions of $serviceOptions. Return only the promise.
*
* @param callable $generator the generator function to generate
* request upon fullfilment
* @param int $statusCode The expected status code for each of the
* request generated by generator.
* @param array $requestOptions The service options for the concurrent
* requests.
* @param callable $generator the generator function to generate
* request upon fulfillment
* @param int $statusCode The expected status code for each of the
* request generated by generator.
* @param ServiceOptions $options The service options for the concurrent
* requests.
*
* @return array
*/
@ -328,7 +328,7 @@ class ServiceRestProxy extends RestProxy
* @param string $path URL path
* @param array|int $expected Expected Status Codes.
* @param string $body Request body
* @param ServiceOptions $options Service options
* @param ServiceOptions $serviceOptions Service options
*
* @return \GuzzleHttp\Promise\PromiseInterface
*/
@ -469,7 +469,7 @@ class ServiceRestProxy extends RestProxy
}
/**
* Throws ServiceException if the recieved status code is not expected.
* Throws ServiceException if the received status code is not expected.
*
* @param ResponseInterface $response The response received
* @param array|int $expected The expected status codes.

Просмотреть файл

@ -195,7 +195,7 @@ trait ServiceRestTrait
}
/**
* Retieves statistics related to replication for the service. The operation
* Retrieves statistics related to replication for the service. The operation
* will only be sent to secondary location endpoint.
*
* @param ServiceOptions|null $options The options this operation sends with.

Просмотреть файл

@ -323,12 +323,18 @@ class Utilities
/**
* Converts string into boolean value.
*
* @param string $obj boolean value in string format.
* @param string $obj boolean value in string format.
* @param bool $skipNull If $skipNull is set, will return NULL directly
* when $obj is NULL.
*
* @return bool
*/
public static function toBoolean($obj)
public static function toBoolean($obj, $skipNull = false)
{
if ($skipNull && is_null($obj)) {
return null;
}
return filter_var($obj, FILTER_VALIDATE_BOOLEAN);
}
@ -347,7 +353,7 @@ class Utilities
/**
* Converts a given date string into \DateTime object
*
* @param string $date windows azure date ins string represntation.
* @param string $date windows azure date ins string representation.
*
* @return \DateTime
*/

Просмотреть файл

@ -24,6 +24,7 @@
namespace MicrosoftAzure\Storage\Tests\framework;
use MicrosoftAzure\Storage\Blob\Models\Container;
use MicrosoftAzure\Storage\Tests\Framework\ServiceRestProxyTestBase;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\ListContainersOptions;
@ -106,6 +107,21 @@ class BlobServiceRestProxyTestBase extends ServiceRestProxyTestBase
}
}
public function deleteAllStorageContainers()
{
$this->deleteContainers($this->listContainers());
}
public function existInContainerArray($containerName, $containers)
{
foreach ($containers as $container) {
if ($container->getName() === $containerName) {
return true;
}
}
return false;
}
public function deleteContainer($containerName)
{
if (($key = array_search($containerName, $this->_createdContainers)) !== false) {
@ -118,7 +134,7 @@ class BlobServiceRestProxyTestBase extends ServiceRestProxyTestBase
{
$containers = $this->listContainers($containerPrefix);
foreach ($containerList as $container) {
if ((array_search($container, $containers) === true)) {
if (in_array($container, $containers)) {
$this->deleteContainer($container);
}
}

Просмотреть файл

@ -417,7 +417,7 @@ class TestResources
$connectionString = getenv('AZURE_STORAGE_CONNECTION_STRING');
if (empty($connectionString)) {
throw new \Exception('AZURE_STORAGE_CONNECTION_STRING envionment variable is missing');
throw new \Exception('AZURE_STORAGE_CONNECTION_STRING environment variable is missing');
}
return $connectionString;
@ -1228,7 +1228,9 @@ class TestResources
'Cache-Control' => 'cachecontrol',
'x-ms-blob-sequence-number' => '0',
'x-ms-blob-type' => 'BlockBlob',
'x-ms-lease-status' => 'locked'
'x-ms-lease-status' => 'locked',
'x-ms-server-encrypted' => 'false',
'x-ms-request-server-encrypted' => 'true'
)
)
);

Просмотреть файл

@ -74,6 +74,11 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
{
return sprintf('-%04x', mt_rand(0, 65535));
}
private function createPrefix()
{
return sprintf('blob-%d', time());
}
/**
* @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getServiceProperties
@ -119,9 +124,9 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$containers = $result->getContainers();
$this->assertNotNull($result->getAccountName());
$this->assertEquals($container1, $containers[0]->getName());
$this->assertEquals($container2, $containers[1]->getName());
$this->assertEquals($container3, $containers[2]->getName());
$this->assertTrue($this->existInContainerArray($container1, $containers));
$this->assertTrue($this->existInContainerArray($container2, $containers));
$this->assertTrue($this->existInContainerArray($container3, $containers));
}
/**
@ -133,9 +138,10 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
public function testListContainersWithOptions()
{
// Setup
$container1 = 'listcontainerwithoptions1' . $this->createSuffix();
$container2 = 'listcontainerwithoptions2' . $this->createSuffix();
$container3 = 'mlistcontainerwithoptions3' . $this->createSuffix();
$prefix = $this->createPrefix();
$container1 = $prefix . 'listcontainerwithoptions1' . $this->createSuffix();
$container2 = $prefix . 'listcontainerwithoptions2' . $this->createSuffix();
$container3 = 'm' . $prefix . 'mlistcontainerwithoptions3' . $this->createSuffix();
$metadataName = 'Mymetadataname';
$metadataValue = 'MetadataValue';
$options = new CreateContainerOptions();
@ -144,7 +150,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
parent::createContainer($container2, $options);
parent::createContainer($container3);
$options = new ListContainersOptions();
$options->setPrefix('list');
$options->setPrefix($prefix);
$options->setIncludeMetadata(true);
// Test
@ -154,8 +160,8 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$containers = $result->getContainers();
$metadata = $containers[1]->getMetadata();
$this->assertEquals(2, count($containers));
$this->assertEquals($container1, $containers[0]->getName());
$this->assertEquals($container2, $containers[1]->getName());
$this->assertTrue($this->existInContainerArray($container1, $containers));
$this->assertTrue($this->existInContainerArray($container2, $containers));
$this->assertEquals($metadataValue, $metadata[$metadataName]);
}
@ -168,9 +174,10 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
public function testListContainersWithNextMarker()
{
// Setup
$container1 = 'listcontainerswithnextmarker1' . $this->createSuffix();
$container2 = 'listcontainerswithnextmarker2' . $this->createSuffix();
$container3 = 'listcontainerswithnextmarker3' . $this->createSuffix();
$prefix = $this->createPrefix();
$container1 = $prefix . 'listcontainerswithnextmarker1' . $this->createSuffix();
$container2 = $prefix . 'listcontainerswithnextmarker2' . $this->createSuffix();
$container3 = $prefix . 'listcontainerswithnextmarker3' . $this->createSuffix();
parent::createContainer($container1);
parent::createContainer($container2);
parent::createContainer($container3);
@ -230,6 +237,9 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
*/
public function testListContainersWithNoContainers()
{
// Setup
$this->deleteAllStorageContainers();
// Test
$result = $this->restProxy->listContainers();
@ -713,6 +723,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$result = $this->restProxy->listBlobs($name);
$this->assertNotNull($createResult->getETag());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
$this->assertInstanceOf('\DateTime', $createResult->getLastModified());
$this->assertCount(1, $result->getBlobs());
}
@ -735,10 +746,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertNotNull($createResult->getETag());
$this->assertInstanceOf('\DateTime', $createResult->getLastModified());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
$appendBlob = $this->restProxy->getBlobProperties($name, 'myblob');
$this->assertEquals('AppendBlob', $appendBlob->getProperties()->getBlobType());
$this->assertEquals(0, $appendBlob->getProperties()->getCommittedBlockCount());
$this->assertTrue(is_bool($appendBlob->getProperties()->getServerEncrypted()));
}
/**
@ -759,7 +772,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$textToBeAppended = 'text to be appended';
// Test
$this->restProxy->createAppendBlob($name, 'myblob');
$createResult = $this->restProxy->createAppendBlob($name, 'myblob');
$appendResult = $this->restProxy->appendBlock($name, 'myblob', $textToBeAppended);
// Assert
@ -767,13 +780,14 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$this->assertInstanceOf('\DateTime', $appendResult->getLastModified());
$this->assertEquals(0, $appendResult->getAppendOffset());
$this->assertEquals(1, $appendResult->getCommittedBlockCount());
$this->assertTrue(is_bool($appendResult->getRequestServerEncrypted()));
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
// List blobs
$listBlobs = $this->restProxy->listBlobs($name, null)->getBlobs();
$this->assertCount(1, $listBlobs);
$this->assertEquals('AppendBlob', $listBlobs[0]->getProperties()->getBlobType());
// Get append blob properties
$appendBlob = $this->restProxy->getBlobProperties($name, 'myblob');
$this->assertEquals('AppendBlob', $appendBlob->getProperties()->getBlobType());
@ -816,6 +830,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$appendBlockOption->setAppendPosition(strlen($textToBeAppended));
$appendResult = $this->restProxy->appendBlock($name, 'myblob', $textToBeAppended, $appendBlockOption);
$this->assertNotNull($appendResult->getETag());
$this->assertTrue(is_bool($appendResult->getRequestServerEncrypted()));
}
/**
@ -900,11 +915,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$options->setContentType($contentType);
// Test
$this->restProxy->createPageBlob($name, 'myblob', 512, $options);
$createResult = $this->restProxy->createPageBlob($name, 'myblob', 512, $options);
// Assert
$result = $this->restProxy->listBlobs($name);
$this->assertCount(1, $result->getBlobs());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
}
/**
@ -929,6 +945,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$this->assertInstanceOf('\DateTime', $createResult->getLastModified());
$this->assertCount(1, $result->getBlobs());
$this->assertEquals(Resources::BINARY_FILE_TYPE, $blob->getProperties()->getContentType());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
}
/**
@ -946,7 +963,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$options->setContentType($contentType);
// Test
$this->restProxy->createBlockBlob($name, 'myblob', 'Hello world', $options);
$createResult = $this->restProxy->createBlockBlob($name, 'myblob', 'Hello world', $options);
// Assert
$result = $this->restProxy->listBlobs($name);
@ -954,6 +971,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$blob = $blobs[0];
$this->assertCount(1, $result->getBlobs());
$this->assertEquals($contentType, $blob->getProperties()->getContentType());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
}
/**
@ -973,7 +991,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$stream = fopen(VirtualFileSystem::newFile($fileContents), 'r');
// Test
$this->restProxy->createBlockBlob($name, 'myblob', $stream, $options);
$createResult = $this->restProxy->createBlockBlob($name, 'myblob', $stream, $options);
// Assert
$result = $this->restProxy->listBlobs($name);
@ -981,6 +999,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$blob = $blobs[0];
$this->assertCount(1, $result->getBlobs());
$this->assertEquals($contentType, $blob->getProperties()->getContentType());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
}
/**
@ -1001,6 +1020,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertEquals($contentLength, $result->getProperties()->getContentLength());
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
}
/**
@ -1089,11 +1109,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$this->restProxy->createPageBlob($name, $blob, 512);
// Test
$this->restProxy->setBlobMetadata($name, $blob, $metadata);
$setResult = $this->restProxy->setBlobMetadata($name, $blob, $metadata);
// Assert
$result = $this->restProxy->getBlobMetadata($name, $blob);
$this->assertEquals($metadata, $result->getMetadata());
$this->assertTrue(is_bool($setResult->getRequestServerEncrypted()));
}
/**
@ -1122,6 +1143,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertEquals(BlobType::BLOCK_BLOB, $result->getProperties()->getBlobType());
$this->assertEquals($metadata, $result->getMetadata());
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
$this->assertEquals(
$contentStream,
stream_get_contents($result->getContentStream())
@ -1183,6 +1205,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertEquals(BlobType::PAGE_BLOB, $result->getProperties()->getBlobType());
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
$this->assertEquals(
$contentStream,
stream_get_contents($result->getContentStream())
@ -1218,6 +1241,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertEquals(BlobType::PAGE_BLOB, $result->getProperties()->getBlobType());
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
$this->assertEquals(
$contentStream,
stream_get_contents($result->getContentStream())
@ -1520,6 +1544,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertNotNull($actual->getETag());
$this->assertTrue(is_bool($actual->getRequestServerEncrypted()));
}
/**
@ -1548,6 +1573,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
// Assert
$this->assertNotNull($actual->getETag());
$this->assertNull($actual->getRequestServerEncrypted());
}
/**
@ -1613,11 +1639,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$options->setIncludeUncommittedBlobs(true);
// Test
$this->restProxy->createBlobBlock($name, 'myblob', 'AAAAAA==', 'Hello world');
$createResult = $this->restProxy->createBlobBlock($name, 'myblob', 'AAAAAA==', 'Hello world');
// Assert
$result = $this->restProxy->listBlobs($name, $options);
$this->assertCount(1, $result->getBlobs());
$this->assertTrue(is_bool($createResult->getRequestServerEncrypted()));
}
/**
@ -1641,11 +1668,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$blockList->addEntry($id2, BlobBlockType::LATEST_TYPE);
// Test
$this->restProxy->commitBlobBlocks($name, $blob, $blockList);
$commitResult = $this->restProxy->commitBlobBlocks($name, $blob, $blockList);
// Assert
$result = $this->restProxy->listBlobs($name);
$this->assertCount(1, $result->getBlobs());
$this->assertTrue(is_bool($commitResult->getRequestServerEncrypted()));
}
/**
@ -1672,11 +1700,12 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$this->restProxy->createBlobBlock($name, $blob, $id2, 'Hello world');
// Test
$this->restProxy->commitBlobBlocks($name, $blob, $blockList);
$commitResult = $this->restProxy->commitBlobBlocks($name, $blob, $blockList);
// Assert
$result = $this->restProxy->listBlobs($name);
$this->assertCount(1, $result->getBlobs());
$this->assertTrue(is_bool($commitResult->getRequestServerEncrypted()));
}
/**
@ -1980,7 +2009,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$options->setContentType($contentType);
$this->restProxy->createBlockBlob($name, $blob, $content, $options);
// Now see if we can pick thje file back up.
// Now see if we can pick the file back up.
$result = $this->restProxy->getBlob($name, $blob);
// Assert
@ -2022,7 +2051,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
**/
public function testCreateBlobLargerThanSingleBlock()
{
// First step, lets set the value for automagic splitting to somethign very small
// First step, lets set the value for automatic splitting to something very small
$max_size = 50;
$this->restProxy->setSingleBlobUploadThresholdInBytes($max_size);
$this->assertEquals($this->restProxy->getSingleBlobUploadThresholdInBytes(), $max_size);
@ -2098,6 +2127,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
$this->assertEquals(BlobType::BLOCK_BLOB, $result->getProperties()->getBlobType());
$this->assertEquals($metadata, $result->getMetadata());
$this->assertEquals($contentStream, $contents);
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
// Delete file after assertion.
unlink($path);
@ -2136,6 +2166,7 @@ class BlobRestProxyTest extends BlobServiceRestProxyTestBase
BlobType::PAGE_BLOB,
$result->getProperties()->getBlobType()
);
$this->assertTrue(is_bool($result->getProperties()->getServerEncrypted()));
$this->assertEquals($content, $contents);
unlink($path);
}

Просмотреть файл

@ -64,6 +64,7 @@ class BlobPropertiesTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(intval($expected['x-ms-blob-sequence-number']), $actual->getSequenceNumber());
$this->assertEquals($expected['x-ms-blob-type'], $actual->getBlobType());
$this->assertEquals($expected['x-ms-lease-status'], $actual->getLeaseStatus());
$this->assertEquals(Utilities::toBoolean($expected['x-ms-server-encrypted']), $actual->getServerEncrypted());
}
/**
@ -299,4 +300,30 @@ class BlobPropertiesTest extends \PHPUnit_Framework_TestCase
// Assert
$this->assertEquals($expected, $properties->getSequenceNumber());
}
/**
* @covers MicrosoftAzure\Storage\Blob\Models\BlobProperties::setServerEncrypted
* @covers MicrosoftAzure\Storage\Blob\Models\BlobProperties::getServerEncrypted
*/
public function tesSetServerEncrypted()
{
// Setup
$expectedTrue = true;
$expectedFalse = false;
$expectedNull = NULL;
$propertiesTrue = new BlobProperties();
$propertiesFalse = new BlobProperties();
$propertiesNull = new BlobProperties();
// Test
$propertiesTrue->setServerEncrypted($expectedTrue);
$propertiesFalse->setServerEncrypted($expectedFalse);
$propertiesNull->setServerEncrypted($expectedNull);
// Assert
$this->assertEquals($expectedTrue, $propertiesTrue->getServerEncrypted());
$this->assertEquals($propertiesFalse, $propertiesFalse->getServerEncrypted());
$this->assertEquals($propertiesNull, $propertiesNull->getServerEncrypted());
}
}

Просмотреть файл

@ -49,6 +49,8 @@ class CreateBlobPagesResultTest extends \PHPUnit_Framework_TestCase
* @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult::getContentMD5
* @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult::setSequenceNumber
* @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult::getSequenceNumber
* @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult::setRequestServerEncrypted
* @covers MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult::getRequestServerEncrypted
*/
public function testCreate()
{
@ -65,5 +67,6 @@ class CreateBlobPagesResultTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected['Etag'], $actual->getETag());
$this->assertEquals($expected['Content-MD5'], $actual->getContentMD5());
$this->assertEquals(intval($expected['x-ms-blob-sequence-number']), $actual->getSequenceNumber());
$this->assertEquals(Utilities::toBoolean($expected['x-ms-request-server-encrypted']), $actual->getRequestServerEncrypted());
}
}

Просмотреть файл

@ -47,6 +47,8 @@ class PutBlobResultTest extends \PHPUnit_Framework_TestCase
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlobResult::getETag
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlobResult::setContentMD5
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlobResult::getContentMD5
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlobResult::setRequestServerEncrypted
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlobResult::getRequestServerEncrypted
*/
public function testCreate()
{
@ -62,5 +64,6 @@ class PutBlobResultTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedDate, $actual->getLastModified());
$this->assertEquals($expected['Etag'], $actual->getETag());
$this->assertEquals($expected['Content-MD5'], $actual->getContentMD5());
$this->assertEquals(Utilities::toBoolean($expected['x-ms-request-server-encrypted']), $actual->getRequestServerEncrypted());
}
}

Просмотреть файл

@ -23,6 +23,7 @@
*/
namespace MicrosoftAzure\Storage\Tests\unit\Blob\Models;
use MicrosoftAzure\Storage\Common\Internal\Utilities;
use MicrosoftAzure\Storage\Tests\Framework\TestResources;
use MicrosoftAzure\Storage\Blob\Models\PutBlockResult;
@ -42,6 +43,8 @@ class PutBlockResultTest extends \PHPUnit_Framework_TestCase
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlockResult::create
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlockResult::setContentMD5
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlockResult::getContentMD5
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlockResult::setRequestServerEncrypted
* @covers MicrosoftAzure\Storage\Blob\Models\PutBlockResult::getRequestServerEncrypted
*/
public function testCreate()
{
@ -54,5 +57,6 @@ class PutBlockResultTest extends \PHPUnit_Framework_TestCase
// Assert
$this->assertEquals($expected['Content-MD5'], $actual->getContentMD5());
$this->assertEquals(Utilities::toBoolean($expected['x-ms-request-server-encrypted']), $actual->getRequestServerEncrypted());
}
}

Просмотреть файл

@ -40,11 +40,13 @@ use MicrosoftAzure\Storage\Tests\Framework\TestResources;
class SetBlobMetadataResultTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::create
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::setLastModified
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::getLastModified
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::setETag
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::getETag
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::create
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::setRequestServerEncrypted
* @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult::getRequestServerEncrypted
*/
public function testCreate()
{
@ -58,5 +60,6 @@ class SetBlobMetadataResultTest extends \PHPUnit_Framework_TestCase
// Assert
$this->assertEquals($expectedDate, $result->getLastModified());
$this->assertEquals($sample['Etag'], $result->getETag());
$this->assertEquals(Utilities::toBoolean($sample['x-ms-request-server-encrypted']), $result->getRequestServerEncrypted());
}
}

Просмотреть файл

@ -291,16 +291,23 @@ class UtilitiesTest extends \PHPUnit_Framework_TestCase
*/
public function testToBoolean()
{
// Setup
$value = 'true';
$expected = true;
$this->assertTrue(is_bool(Utilities::toBoolean('true')));
$this->assertEquals(true, Utilities::toBoolean('true'));
// Test
$actual = Utilities::toBoolean($value);
$this->assertTrue(is_bool(Utilities::toBoolean('false')));
$this->assertEquals(false, Utilities::toBoolean('false'));
// Assert
$this->assertTrue(is_bool($actual));
$this->assertEquals($expected, $actual);
$this->assertTrue(is_bool(Utilities::toBoolean(null)));
$this->assertEquals(false, Utilities::toBoolean(null));
$this->assertTrue(is_bool(Utilities::toBoolean('true', true)));
$this->assertEquals(true, Utilities::toBoolean('true', true));
$this->assertTrue(is_bool(Utilities::toBoolean('false', true)));
$this->assertEquals(false, Utilities::toBoolean('false', true));
$this->assertTrue(is_null(Utilities::toBoolean(null, true)));
$this->assertEquals(null, Utilities::toBoolean(null, true));
}
/**