Пример #1
0
        public void ChangeContainerLease()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             leaseId       = string.Empty;
            string             porposedId    = Guid.NewGuid().ToString();

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.ChangeLease(containerName, string.Empty, leaseId, porposedId), Utility.GenComparisonData("Change Container Lease", true));

                        Test.Assert(!CommandAgent.RemoveAzureStorageContainer(containerName, leaseId), Utility.GenComparisonData("Remove container", false));
                        Test.Assert(CommandAgent.RemoveAzureStorageContainer(containerName, porposedId), Utility.GenComparisonData("Remove container", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, porposedId);
            }
        }
Пример #2
0
        public void ChangeLeaseOnNonExistingContainer()
        {
            string containerName = Utility.GenNameString("container");
            string leaseId       = Guid.NewGuid().ToString();
            string proposedId    = Guid.NewGuid().ToString();

            Test.Assert(!CommandAgent.ChangeLease(containerName, null, leaseId, proposedId), Utility.GenComparisonData("Change Container Lease", false));
            CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
        }
Пример #3
0
        public void ChangeLeaseWithSameID()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             leaseId       = string.Empty;
            string             porposedId    = leaseId;

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire blob Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId    = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                        porposedId = leaseId;

                        Test.Assert(CommandAgent.ChangeLease(containerName, blobName, leaseId, porposedId), Utility.GenComparisonData("Change blob Lease", true));
                        Test.Assert(CommandAgent.SnapshotAzureStorageBlob(containerName, blobName, porposedId), Utility.GenComparisonData("Snapshot blob", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        leaseId    = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                        porposedId = leaseId;

                        Test.Assert(CommandAgent.ChangeLease(containerName, string.Empty, leaseId, porposedId), Utility.GenComparisonData("Change Lease", true));
                        Test.Assert(CommandAgent.RemoveAzureStorageContainer(containerName, porposedId), Utility.GenComparisonData("Remove container", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, porposedId);
            }
        }
Пример #4
0
        public void ChangeWithUnmatchLeaseID()
        {
            string             containerName         = Utility.GenNameString("container");
            string             blobName              = Utility.GenNameString("blob");
            string             containerLeaseId      = string.Empty;
            string             blobLeaseId           = string.Empty;
            string             proposedId            = Guid.NewGuid().ToString();
            string             wrongContainerLeaseId = Guid.NewGuid().ToString();
            string             wrongBlobLeaseId      = Guid.NewGuid().ToString();
            CloudBlobContainer container             = blobUtil.CreateContainer(containerName);
            CloudBlob          blob = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: 30), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: 30), Utility.GenComparisonData("Acquire Container Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(!CommandAgent.ChangeLease(containerName, null, wrongContainerLeaseId, proposedId), Utility.GenComparisonData("Change Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, wrongBlobLeaseId, proposedId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLeaseId);
            }
        }
Пример #5
0
        public void ChangeWithInvalidProposedLeaseID()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            string             containerLease = string.Empty;
            string             blobLease      = string.Empty;
            string             invalidLeaseId = "1234567890poiuyytrewq";
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            CloudBlob          blob           = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, string.Empty), Utility.GenComparisonData("Acquire container Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
                Test.Assert(!CommandAgent.ChangeLease(containerName, null, containerLease, invalidLeaseId), Utility.GenComparisonData("Change Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseId);

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire blob Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, blobLease, invalidLeaseId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name, invalidLeaseId);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Пример #6
0
        public void ChangeLeaseOnNonExistingBlob()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            string             leaseId       = Guid.NewGuid().ToString();
            string             proposedId    = Guid.NewGuid().ToString();
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, leaseId, proposedId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Пример #7
0
        public void ChangeWithoutEnoughPermission()
        {
            string             containerName    = Utility.GenNameString("container");
            string             blobName         = Utility.GenNameString("blob");
            string             containerLeaseId = string.Empty;
            string             blobLeaseId      = string.Empty;
            string             proposedId       = Guid.NewGuid().ToString();
            CloudBlobContainer container        = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: 30), Utility.GenComparisonData("Acquire Container Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: 30), Utility.GenComparisonData("Acquire blob Lease", true));
                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLeaseId = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string containerSasToken = string.Empty;
                string accountSasToken   = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "rl", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Create an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Read,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);
                Test.Assert(!CommandAgent.ChangeLease(containerName, null, containerLeaseId, proposedId), Utility.GenComparisonData("Change Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);
                Test.Assert(!CommandAgent.ChangeLease(containerName, blobName, blobLeaseId, proposedId), Utility.GenComparisonData("Change Blob Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLeaseId);
            }
        }
Пример #8
0
        public void ChangeLeaseBySAS()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;
            string             porposedId     = Guid.NewGuid().ToString();

            Random random   = new Random();
            int    duration = random.Next(15, 60);

            try
            {
                string containerSasToken = string.Empty;
                string accountSasToken   = string.Empty;

                // Create a container SAS
                Test.Assert(CommandAgent.NewAzureStorageContainerSAS(containerName, string.Empty, "w", DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromMinutes(5)),
                            Utility.GenComparisonData("container sas create", true));
                if (lang == Language.NodeJS)
                {
                    containerSasToken = (CommandAgent as NodeJSAgent).Output[0]["sas"] as string;
                }

                // Use an account SAS
                SharedAccessAccountPolicy policy = new SharedAccessAccountPolicy()
                {
                    Permissions            = SharedAccessAccountPermissions.Write,
                    ResourceTypes          = SharedAccessAccountResourceTypes.Container | SharedAccessAccountResourceTypes.Object,
                    Services               = SharedAccessAccountServices.Blob,
                    SharedAccessStartTime  = DateTimeOffset.UtcNow,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5)
                };

                accountSasToken = Utility.GenerateAccountSAS(policy);

                CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, accountSasToken);

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        containerLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        Test.Assert(CommandAgent.ChangeLease(containerName, null, containerLease, porposedId), Utility.GenComparisonData("Change Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = porposedId
                        };
                        container.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                string    blobLease = string.Empty;
                CloudBlob blob      = blobUtil.CreateRandomBlob(container, blobName);
                blob.Metadata["test1"] = "m1";
                blob.Metadata["test2"] = "m2";

                // Acquire with account SAS
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: duration), Utility.GenComparisonData("Acquire Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;

                        // Change with container SAS
                        CommandAgent.SetStorageContextWithSASToken(StorageAccount.Credentials.AccountName, containerSasToken);

                        Test.Assert(CommandAgent.ChangeLease(containerName, blobName, blobLease, porposedId), Utility.GenComparisonData("Change Lease", true));

                        AccessCondition condition = new AccessCondition()
                        {
                            LeaseId = porposedId
                        };
                        blob.SetMetadata(condition);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, porposedId);
            }
        }