public void TableSasInvalidOperations()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable       table       = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));

            try
            {
                table.Create();
                // Prepare SAS authentication with full permissions
                string sasString = table.GetSharedAccessSignature(
                    new SharedAccessTablePolicy
                {
                    Permissions            = SharedAccessTablePermissions.Delete,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30)
                },
                    null,
                    null,
                    null,
                    null,
                    null);

                CloudTableClient sasClient = new CloudTableClient(tableClient.BaseUri, new StorageCredentials(sasString));

                // Construct a valid set of service properties to upload.
                ServiceProperties properties = new ServiceProperties();
                properties.Logging.Version       = "1.0";
                properties.Metrics.Version       = "1.0";
                properties.Logging.RetentionDays = 9;
                sasClient.GetServiceProperties();
                sasClient.SetServiceProperties(properties);

                // Test invalid client operations
                // BUGBUG: ListTables hides the exception. We should fix this
                // TestHelpers.ExpectedException(() => sasClient.ListTablesSegmented(), "List tables with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasClient.GetServiceProperties(), "Get service properties with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasClient.SetServiceProperties(properties), "Set service properties with SAS", HttpStatusCode.NotFound);

                CloudTable sasTable = sasClient.GetTableReference(table.Name);

                // Verify that creation fails with SAS
                TestHelper.ExpectedException(() => sasTable.Create(), "Create a table with SAS", HttpStatusCode.NotFound);

                // Create the table.
                table.Create();

                // Test invalid table operations
                TestHelper.ExpectedException(() => sasTable.Delete(), "Delete a table with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasTable.GetPermissions(), "Get ACL with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasTable.SetPermissions(new TablePermissions()), "Set ACL with SAS", HttpStatusCode.NotFound);
            }
            finally
            {
                table.DeleteIfExists();
            }
        }
Ejemplo n.º 2
0
        public void SetLoggingVersion()
        {
            //Blob service
            CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

            GenericSetLoggingVersion(ServiceType.Blob, () => blobClient.GetServiceProperties());

            //Queue service
            CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient();

            GenericSetLoggingVersion(ServiceType.Queue, () => queueClient.GetServiceProperties());

            //Table service
            CloudTableClient tableClient = StorageAccount.CreateCloudTableClient();

            GenericSetLoggingVersion(ServiceType.Table, () => tableClient.GetServiceProperties());
        }
Ejemplo n.º 3
0
        public void SetMetricsVersion()
        {
            //Blob service
            CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

            GenericSetMetricsVersion(ServiceType.Blob, () => blobClient.GetServiceProperties());

            //Queue service
            CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient();

            GenericSetMetricsVersion(ServiceType.Queue, () => queueClient.GetServiceProperties());

            //Table service
            CloudTableClient tableClient = StorageAccount.CreateCloudTableClient();

            GenericSetMetricsVersion(ServiceType.Table, () => tableClient.GetServiceProperties());

            //File service
            GenericSetMetricsVersion(ServiceType.File, () => Utility.GetServiceProperties(StorageAccount, ServiceType.File));
        }
        //https://msazure.visualstudio.com/One/_git/AzureStack-Services-Storage?path=%2Fsrc%2Fsdx%2Fbase%2Fwoss%2Ftest%2Ftests%2FWFE%2FHorizontalBVT%2FAccountKeyTests.cs&version=GBmaster&_a=contents
        /// <summary>
        /// Make a couple of requests to the blob, queue, and table services, expecting success.
        /// </summary>
        /// <param name="account">The account through which the services will be accessed.</param>
        internal void MakeServiceRequestsExpectSuccess(CloudStorageAccount account)
        {
            // Make blob service requests
            CloudBlobClient blobClient = account.CreateCloudBlobClient();

            //   blobClient.ListContainersSegmentedAsync();
            blobClient.ListContainers().Count();
            blobClient.GetServiceProperties();

            // Make queue service requests
            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            queueClient.ListQueues().Count();
            queueClient.GetServiceProperties();

            // Make table service requests
            CloudTableClient tableClient = account.CreateCloudTableClient();

            tableClient.ListTables().Count();
            tableClient.GetServiceProperties();
        }
        public void TableSasInvalidOperations()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("T" + Guid.NewGuid().ToString("N"));

            try
            {
                table.Create();
                // Prepare SAS authentication with full permissions
                string sasString = table.GetSharedAccessSignature(
                                        new SharedAccessTablePolicy
                                        {
                                            Permissions = SharedAccessTablePermissions.Delete,
                                            SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30)
                                        },
                                        null,
                                        null,
                                        null,
                                        null,
                                        null);

                CloudTableClient sasClient = new CloudTableClient(tableClient.BaseUri, new StorageCredentials(sasString));

                // Construct a valid set of service properties to upload.
                ServiceProperties properties = new ServiceProperties();
                properties.Logging.Version = Constants.AnalyticsConstants.LoggingVersionV1;
                properties.HourMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1;
                properties.Logging.RetentionDays = 9;
                sasClient.GetServiceProperties();
                sasClient.SetServiceProperties(properties);

                // Test invalid client operations
                // BUGBUG: ListTables hides the exception. We should fix this
                // TestHelpers.ExpectedException(() => sasClient.ListTablesSegmented(), "List tables with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasClient.GetServiceProperties(), "Get service properties with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasClient.SetServiceProperties(properties), "Set service properties with SAS", HttpStatusCode.NotFound);

                CloudTable sasTable = sasClient.GetTableReference(table.Name);

                // Verify that creation fails with SAS
                TestHelper.ExpectedException(() => sasTable.Create(), "Create a table with SAS", HttpStatusCode.NotFound);

                // Create the table.
                table.Create();

                // Test invalid table operations
                TestHelper.ExpectedException(() => sasTable.Delete(), "Delete a table with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasTable.GetPermissions(), "Get ACL with SAS", HttpStatusCode.NotFound);
                TestHelper.ExpectedException(() => sasTable.SetPermissions(new TablePermissions()), "Set ACL with SAS", HttpStatusCode.NotFound);
            }
            finally
            {
                table.DeleteIfExists();
            }
        }
Ejemplo n.º 6
0
        // The Azure Functions runtime uses this storage account connection string for all functions
        // except for HTTP triggered functions.
        // The storage account must be a general-purpose one that supports blobs, queues, and tables.
        // See Storage account and Storage account requirements.

        // AzureWebJobsDashboard
        // Optional storage account connection string for storing logs and displaying them in the Monitor tab in the portal.
        // The storage account must be a general-purpose one that supports blobs, queues, and tables.
        // See Storage account and Storage account requirements.

        //Functions uses Storage for operations such as managing triggers and logging function executions.
        internal StorageAccountsValidation MakeServiceRequestsExpectSuccess(string connectionKey, string connectionString)
        {
            string storageSymptoms  = String.Empty;
            int    status           = 0;
            string postfixStatement = "Please make sure this is a general-purpose storage account.";

            //if (connectionKey.Equals("AzureWebJobsStorage", StringComparison.OrdinalIgnoreCase))
            //{

            //}

            try
            {
                if (string.IsNullOrWhiteSpace(connectionString))
                {
                    //  return Task.FromResult<StorageAccountsValidation> (new StorageAccountsValidation { });
                    return(new StorageAccountsValidation {
                    });
                }


                CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);

                // Make blob service requests
                try
                {
                    CloudBlobClient blobClient = account.CreateCloudBlobClient();
                    //   blobClient.ListContainersSegmentedAsync();
                    // blobClient.ListContainers().Count();
                    blobClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Blob endpoint is not reachable. Make sure the firewall on this storage account is not misconfigured.";
                    throw ex;
                }

                try
                {
                    // Make queue service requests
                    CloudQueueClient queueClient = account.CreateCloudQueueClient();
                    queueClient.ListQueues().Count();
                    queueClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Queue is not enabled. ";
                    throw ex;
                }

                try
                {
                    // Make table service requests
                    CloudTableClient tableClient = account.CreateCloudTableClient();
                    tableClient.ListTables().Count();
                    tableClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Table is not enabled.";
                    throw ex;
                }

                try
                {
                    // Not sure if this is only required for consumption
                    //  When using a Consumption plan function definitions are stored in File Storage.
                    CloudFileClient fileClient = account.CreateCloudFileClient();
                    fileClient.ListShares().Count();
                    fileClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "File is not enabled.";
                    throw ex;
                }

                storageSymptoms = "Storage connection string validation passed!";
            }
            catch (Exception ex)
            {
                storageSymptoms += "\n";
                storageSymptoms += postfixStatement;
                status           = 1;
            }


            StorageAccountsValidation result = new StorageAccountsValidation
            {
                AppSettingsKey = connectionKey,
                Mandatory      = false,
                AccountName    = connectionString.Split(new string[] { "AccountName=", ";AccountKey=" }, StringSplitOptions.RemoveEmptyEntries)[1],
                Message        = storageSymptoms,
                Status         = status
            };

            //return Task.FromResult(result);
            return(result);
        }
Ejemplo n.º 7
0
 public ServiceProperties GetServiceProperties(TableRequestOptions requestOptions = null,
                                               OperationContext operationContext  = null)
 {
     return(_cloudTableClient.GetServiceProperties(requestOptions, operationContext));
 }