Ejemplo n.º 1
0
        public void AnonymousContextWithEndPoint()
        {
            PowerShellAgent    psAgent       = (PowerShellAgent)CommandAgent;
            string             containerName = Utility.GenNameString(ContainerPrefix);
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName, BlobContainerPublicAccessType.Blob);
            bool savedParamValue             = psAgent.UseContextParam;

            try
            {
                string    pageBlobName   = Utility.GenNameString("pageblob");
                string    blockBlobName  = Utility.GenNameString("blockblob");
                string    appendBlobName = Utility.GenNameString("appendblob");
                CloudBlob blockBlob      = blobUtil.CreateBlockBlob(container, blockBlobName);
                CloudBlob pageBlob       = blobUtil.CreatePageBlob(container, pageBlobName);
                CloudBlob appendBlob     = blobUtil.CreateAppendBlob(container, appendBlobName);

                string protocol = useHttps ? "https" : "http";

                psAgent.UseContextParam = false;
                string cmd = string.Format("New-AzureStorageContext -StorageAccountName {0} -Anonymous -Protocol {1} -EndPoint {2}",
                                           StorageAccountName, protocol, StorageEndPoint);
                psAgent.AddPipelineScript(cmd);
                Test.Assert(CommandAgent.GetAzureStorageBlob(blockBlobName, containerName), Utility.GenComparisonData("Get-AzureStorageBlob", true));
                CommandAgent.OutputValidation(new List <CloudBlob> {
                    blockBlob
                });
                psAgent.AddPipelineScript(cmd);
                Test.Assert(CommandAgent.GetAzureStorageBlob(pageBlobName, containerName), Utility.GenComparisonData("Get-AzureStorageBlob", true));
                CommandAgent.OutputValidation(new List <CloudBlob> {
                    pageBlob
                });
                psAgent.AddPipelineScript(cmd);
                Test.Assert(CommandAgent.GetAzureStorageBlob(appendBlobName, containerName), Utility.GenComparisonData("Get-AzureStorageBlob", true));
                CommandAgent.OutputValidation(new List <CloudBlob> {
                    appendBlob
                });
            }
            finally
            {
                psAgent.UseContextParam = savedParamValue;
                blobUtil.RemoveContainer(containerName);
            }
        }
Ejemplo n.º 2
0
        public void GetContainerFromMultipleStorageContext()
        {
            PowerShellAgent     psAgent  = (PowerShellAgent)CommandAgent;
            CloudStorageAccount account1 = TestBase.GetCloudStorageAccountFromConfig();
            CloudStorageAccount account2 = TestBase.GetCloudStorageAccountFromConfig("Secondary");
            string connectionString1     = account1.ToString(true);
            string connectionString2     = account2.ToString(true);

            Test.Assert(connectionString1 != connectionString2, "Use two different connection string {0} != {1}", connectionString1, connectionString2);

            CloudBlobUtil blobUtil1       = new CloudBlobUtil(account1);
            CloudBlobUtil blobUtil2       = new CloudBlobUtil(account2);
            string        containerName   = Utility.GenNameString("container");
            bool          savedParamValue = psAgent.UseContextParam;

            try
            {
                CloudBlobContainer container1 = blobUtil1.CreateContainer(containerName);
                CloudBlobContainer container2 = blobUtil2.CreateContainer(containerName);
                int containerCount            = 2;

                string cmd = String.Format("$context1 = new-azurestoragecontext -connectionstring '{0}';$context2 = new-azurestoragecontext -connectionstring '{1}';($context1, $context2)", connectionString1, connectionString2);
                psAgent.UseContextParam = false;
                psAgent.AddPipelineScript(cmd);

                Test.Assert(CommandAgent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("Get-AzureStorageContainer using multiple storage contexts", true));
                Test.Assert(CommandAgent.Output.Count == containerCount, String.Format("Want to retrieve {0} page blob, but retrieved {1} page blobs", containerCount, CommandAgent.Output.Count));

                CommandAgent.OutputValidation(new List <CloudBlobContainer>()
                {
                    container1, container2
                });
            }
            finally
            {
                psAgent.UseContextParam = savedParamValue;
                blobUtil1.RemoveContainer(containerName);
                blobUtil2.RemoveContainer(containerName);
            }
        }
Ejemplo n.º 3
0
        public void GetContainerWithInvalidEndPoint()
        {
            PowerShellAgent psAgent         = (PowerShellAgent)CommandAgent;
            bool            savedParamValue = psAgent.UseContextParam;

            try
            {
                string accountName = Utility.GenNameString("account");
                string accountKey  = Utility.GenBase64String("key");
                string endPoint    = Utility.GenNameString("core.abc.def");

                string cmd = String.Format("new-azurestoragecontext -StorageAccountName {0} " +
                                           "-StorageAccountKey {1} -Endpoint {2}", accountName, accountKey, endPoint);
                psAgent.AddPipelineScript(cmd);
                psAgent.UseContextParam = false;
                Test.Assert(!CommandAgent.GetAzureStorageContainer(string.Empty),
                            "Get containers with invalid endpoint should fail");
                ExpectedContainErrorMessage(ExpectedErrorMsgs);
            }
            finally
            {
                psAgent.UseContextParam = savedParamValue;
            }
        }
Ejemplo n.º 4
0
        public void GetContainerFromValidAndInvalidStorageContext()
        {
            PowerShellAgent     psAgent  = (PowerShellAgent)CommandAgent;
            CloudStorageAccount account1 = TestBase.GetCloudStorageAccountFromConfig();
            string connectionString1     = account1.ToString(true);
            string randomAccountName     = Utility.GenNameString("account");
            string randomAccountKey      = Utility.GenNameString("key");

            randomAccountKey = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(randomAccountKey));

            string containerName   = Utility.GenNameString("container");
            bool   savedParamValue = psAgent.UseContextParam;

            try
            {
                CloudBlobContainer container1 = blobUtil.CreateContainer(containerName);
                string             cmd        = String.Format("$context1 = new-azurestoragecontext -connectionstring '{0}';$context2 = new-azurestoragecontext -StorageAccountName '{1}' -StorageAccountKey '{2}';($context1, $context2)",
                                                              connectionString1, randomAccountName, randomAccountKey);
                psAgent.UseContextParam = false;
                psAgent.AddPipelineScript(cmd);

                Test.Assert(!CommandAgent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("Get-AzureStorageContainer using valid and invalid storage contexts", false));
                Test.Assert(CommandAgent.ErrorMessages.Count == 1, "invalid storage context should return error");

                //the same error may output different error messages in different environments
                bool expectedError = CommandAgent.ErrorMessages[0].Contains("The remote server returned an error: (502) Bad Gateway") ||
                                     CommandAgent.ErrorMessages[0].Contains("The remote name could not be resolved") || CommandAgent.ErrorMessages[0].Contains("The operation has timed out");
                Test.Assert(expectedError, "use invalid storage account should return 502 or could not be resolved exception or The operation has timed out, actually {0}", CommandAgent.ErrorMessages[0]);
            }
            finally
            {
                psAgent.UseContextParam = savedParamValue;
                //TODO test the invalid storage account in subscription
                blobUtil.RemoveContainer(containerName);
            }
        }