/**
  * @covers WindowsAzure\Blob\BlobRestProxy::createContainer
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteContainer
  * @covers WindowsAzure\Blob\BlobRestProxy::listContainers
  */
 public function setUp()
 {
     parent::setUp();
     $settings = StorageServiceSettings::createFromConnectionString($this->connectionString);
     $accountName = $settings->getBlobEndpointUri();
     $firstSlash = strpos($accountName, '/');
     $accountName = substr($accountName, $firstSlash + 2);
     $firstDot = strpos($accountName, '.');
     $accountName = substr($accountName, 0, $firstDot);
     BlobServiceFunctionalTestData::setupData($accountName);
     $hasRoot = false;
     foreach ($this->restProxy->listContainers()->getContainers() as $container) {
         if ($container->getName() == '$root') {
             $hasRoot = true;
             $this->safeDeleteContainerContents('$root');
         } else {
             $this->safeDeleteContainer($container->getName());
         }
     }
     foreach (BlobServiceFunctionalTestData::$testContainerNames as $name) {
         $this->safeCreateContainer($name);
     }
     if (!$hasRoot) {
         $this->safeCreateContainer('$root');
     }
     if (!self::$isOneTimeSetup) {
         self::$isOneTimeSetup = true;
     }
 }
 public function setUp()
 {
     parent::setUp();
     $settings = StorageServiceSettings::createFromConnectionString($this->connectionString);
     $this->accountName = $settings->getName();
     if (!self::$isOneTimeSetup) {
         $this->doOneTimeSetup();
         self::$isOneTimeSetup = true;
     }
 }
 /**
  * Builds a table object.
  *
  * @param string $connectionString The configuration connection string.
  *
  * @return WindowsAzure\Table\Internal\ITable
  */
 public function createTableService($connectionString)
 {
     $settings = StorageServiceSettings::createFromConnectionString($connectionString);
     $httpClient = $this->httpClient();
     $atomSerializer = $this->atomSerializer();
     $mimeSerializer = $this->mimeSerializer();
     $serializer = $this->serializer();
     $uri = Utilities::tryAddUrlScheme($settings->getTableEndpointUri());
     $tableWrapper = new TableRestProxy($httpClient, $uri, $atomSerializer, $mimeSerializer, $serializer);
     // Adding headers filter
     $headers = array();
     $latestServicesVersion = Resources::STORAGE_API_LATEST_VERSION;
     $currentVersion = Resources::DATA_SERVICE_VERSION_VALUE;
     $maxVersion = Resources::MAX_DATA_SERVICE_VERSION_VALUE;
     $accept = Resources::ACCEPT_HEADER_VALUE;
     $acceptCharset = Resources::ACCEPT_CHARSET_VALUE;
     $userAgent = Resources::SDK_USER_AGENT;
     $headers[Resources::X_MS_VERSION] = $latestServicesVersion;
     $headers[Resources::DATA_SERVICE_VERSION] = $currentVersion;
     $headers[Resources::MAX_DATA_SERVICE_VERSION] = $maxVersion;
     $headers[Resources::MAX_DATA_SERVICE_VERSION] = $maxVersion;
     $headers[Resources::ACCEPT_HEADER] = $accept;
     $headers[Resources::ACCEPT_CHARSET] = $acceptCharset;
     $headers[Resources::USER_AGENT] = $userAgent;
     $headersFilter = new HeadersFilter($headers);
     $tableWrapper = $tableWrapper->withFilter($headersFilter);
     // Adding date filter
     $dateFilter = new DateFilter();
     $tableWrapper = $tableWrapper->withFilter($dateFilter);
     // Adding authentication filter
     $authFilter = new AuthenticationFilter($this->tableAuthenticationScheme($settings->getName(), $settings->getKey()));
     $tableWrapper = $tableWrapper->withFilter($authFilter);
     return $tableWrapper;
 }
 /**
  * @covers WindowsAzure\Common\Internal\StorageServiceSettings::createFromConnectionString
  * @covers WindowsAzure\Common\Internal\StorageServiceSettings::init
  * @covers WindowsAzure\Common\Internal\StorageServiceSettings::__construct
  * @covers WindowsAzure\Common\Internal\StorageServiceSettings::_getDefaultServiceEndpoint
  * @covers WindowsAzure\Common\Internal\ServiceSettings::getValidator
  * @covers WindowsAzure\Common\Internal\ServiceSettings::optional
  * @covers WindowsAzure\Common\Internal\ServiceSettings::allRequired
  * @covers WindowsAzure\Common\Internal\ServiceSettings::setting
  * @covers WindowsAzure\Common\Internal\ServiceSettings::settingWithFunc
  * @covers WindowsAzure\Common\Internal\ServiceSettings::matchedSpecification
  * @covers WindowsAzure\Common\Internal\ServiceSettings::parseAndValidateKeys
  * @covers WindowsAzure\Common\Internal\ServiceSettings::noMatch
  * @covers WindowsAzure\Common\Internal\StorageServiceSettings::_createStorageServiceSettings
  */
 public function testCreateFromConnectionStringWithCaseInsensitive()
 {
     // Setup
     $protocol = 'https';
     $expectedName = $this->_accountName;
     $expectedKey = TestResources::KEY4;
     $connectionString = "defaultendpointsprotocol={$protocol};accountname={$expectedName};accountkey={$expectedKey}";
     $expectedBlobEndpoint = sprintf(Resources::SERVICE_URI_FORMAT, $protocol, $expectedName, Resources::BLOB_BASE_DNS_NAME);
     $expectedQueueEndpoint = sprintf(Resources::SERVICE_URI_FORMAT, $protocol, $expectedName, Resources::QUEUE_BASE_DNS_NAME);
     $expectedTableEndpoint = sprintf(Resources::SERVICE_URI_FORMAT, $protocol, $expectedName, Resources::TABLE_BASE_DNS_NAME);
     // Test
     $actual = StorageServiceSettings::createFromConnectionString($connectionString);
     // Assert
     $this->assertEquals($expectedName, $actual->getName());
     $this->assertEquals($expectedKey, $actual->getKey());
     $this->assertEquals($expectedBlobEndpoint, $actual->getBlobEndpointUri());
     $this->assertEquals($expectedQueueEndpoint, $actual->getQueueEndpointUri());
     $this->assertEquals($expectedTableEndpoint, $actual->getTableEndpointUri());
 }
 protected function hasSecureEndpoint()
 {
     $settings = StorageServiceSettings::createFromConnectionString($this->connectionString);
     $uri = $settings->getBlobEndpointUri();
     return Utilities::startsWith($uri, 'https://');
 }
 private function verifySetContainerACLWorker($ret, $container, $acl, $blobContent)
 {
     $this->assertNotNull($ret->getContainerACL(), '$ret->getContainerACL');
     $this->assertNotNull($ret->getETag(), '$ret->getContainerACL->getETag');
     $now = new \DateTime();
     $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($ret->getLastModified(), $now) < 10000, 'Last modified date (' . $ret->getLastModified()->format(\DateTime::RFC1123) . ') ' . 'should be within 10 seconds of $now (' . $now->format(\DateTime::RFC1123) . ')');
     $this->assertNotNull($ret->getContainerACL()->getSignedIdentifiers(), '$ret->getContainerACL->getSignedIdentifiers');
     $this->assertEquals(is_null($acl->getPublicAccess()) ? '' : $acl->getPublicAccess(), $ret->getContainerACL()->getPublicAccess(), '$ret->getContainerACL->getPublicAccess');
     $expIds = $acl->getSignedIdentifiers();
     $actIds = $ret->getContainerACL()->getSignedIdentifiers();
     $this->assertEquals(count($expIds), count($actIds), '$ret->getContainerACL->getSignedIdentifiers');
     for ($i = 0; $i < count($expIds); $i++) {
         $expId = $expIds[$i];
         $actId = $actIds[$i];
         $this->assertEquals($expId->getId(), $actId->getId(), 'SignedIdentifiers[' + $i + ']->getId');
         $this->assertEquals($expId->getAccessPolicy()->getPermission(), $actId->getAccessPolicy()->getPermission(), 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getPermission');
         $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($expId->getAccessPolicy()->getStart(), $actId->getAccessPolicy()->getStart()) < 1, 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getStart should match within 1 second, ' . 'exp=' . $expId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123) . ', ' . 'act=' . $actId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123));
         $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($expId->getAccessPolicy()->getExpiry(), $actId->getAccessPolicy()->getExpiry()) < 1, 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getExpiry should match within 1 second, ' . 'exp=' . $expId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123) . ', ' . 'act=' . $actId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123));
     }
     if (!$this->isEmulated()) {
         $settings = StorageServiceSettings::createFromConnectionString($this->connectionString);
         $containerAddress = $settings->getBlobEndpointUri() . '/' . $container;
         $blobListAddress = $containerAddress . '?restype=container&comp=list';
         $blobAddress = $containerAddress . '/test';
         $canDownloadBlobList = $this->canDownloadFromUrl($blobListAddress, "<?xml version=\"1.0\" encoding=\"utf-8\"?" . "><EnumerationResults");
         $canDownloadBlob = $this->canDownloadFromUrl($blobAddress, $blobContent);
         if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::CONTAINER_AND_BLOBS) {
             // Full public read access: Container and blob data can be read via anonymous request.
             // Clients can enumerate blobs within the $container via anonymous request,
             // but cannot enumerate containers within the storage account.
             $this->assertTrue($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
             $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
         } else {
             if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::BLOBS_ONLY) {
                 // Public read access for blobs only: Blob data within this container
                 // can be read via anonymous request, but $container data is not available.
                 // Clients cannot enumerate blobs within the $container via anonymous request.
                 $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
                 $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
             } else {
                 // No public read access: Container and blob data can be read by the account owner only.
                 $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
                 $this->assertFalse($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
             }
         }
     }
 }