Exemple #1
0
        public void BreakBlobLease()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                string    proposedId = Guid.NewGuid().ToString();
                CloudBlob blob       = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, proposedId), Utility.GenComparisonData("Acquire Blob Lease", true));

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

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease", true));

                        Test.Assert((CommandAgent as NodeJSAgent).ShowAzureStorageBlob(blobName, containerName), Utility.GenComparisonData("Show blob without lease ID", true));
                        Test.Assert(!(CommandAgent as NodeJSAgent).ShowAzureStorageBlob(blobName, containerName, lease), Utility.GenComparisonData("Show blob with lease ID", false));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #2
0
        public void BreakContainerLease()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            string             lease         = string.Empty;

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

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

                        Test.Assert((CommandAgent as NodeJSAgent).ShowAzureStorageContainer(containerName), Utility.GenComparisonData("Show container without lease ID", true));

                        Test.Assert(CommandAgent.BreakLease(containerName, string.Empty), Utility.GenComparisonData("Break Container Lease", true));
                        Test.Assert(!(CommandAgent as NodeJSAgent).ShowAzureStorageContainer(containerName, lease), Utility.GenComparisonData("Show container with lease ID", false));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #3
0
        public void BreakContainerLeaseWithInvalidDuration()
        {
            string             containerName  = Utility.GenNameString("container");
            string             containerLease = string.Empty;
            int                leaseDuration  = 15;
            int                breakDuration  = 61;
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: leaseDuration), 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.BreakLease(containerName, null, breakDuration), Utility.GenComparisonData("Break Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLease);
            }
        }
Exemple #4
0
        public void BreakLeaseOnNonExistingContainer()
        {
            string containerName = Utility.GenNameString("container");

            Test.Assert(!CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease", false));
            CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
        }
Exemple #5
0
        public void BreakContainerLeaseWithDurationShorterThanRemainingTime()
        {
            string             containerName = Utility.GenNameString("container");
            int                leaseDuration = 30;
            int                breakDuration = 5;
            int                remainingTime = breakDuration;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

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

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        Test.Assert(CommandAgent.BreakLease(containerName, null, breakDuration), Utility.GenComparisonData("Break Container Lease", true));

                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= breakDuration, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }

                Thread.Sleep((remainingTime + 1) * 1000);
                container.Delete();
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #6
0
        public void BreakInfiniteLease()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                string    proposedId = Guid.NewGuid().ToString();
                CloudBlob blob       = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, proposedId), Utility.GenComparisonData("Acquire Blob Lease", true));

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

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease", true));

                        int remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime == 0, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #7
0
        public void BreakNotLeasedContainer()
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                Test.Assert(!CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #8
0
        public void BreakBlobLeaseAndAcquireAgain()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            string             blobLease     = string.Empty;
            int                leaseDuration = 15;
            int                breakDuration = 30;
            int                remainingTime = breakDuration;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                CloudBlob blob = blobUtil.CreateRandomBlob(container, blobName);
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));

                if (lang == Language.NodeJS)
                {
                    try
                    {
                        Test.Assert(CommandAgent.BreakLease(containerName, blobName, breakDuration), Utility.GenComparisonData("Break Blob Lease", true));

                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= leaseDuration, Utility.GenComparisonData("Validate remaining time", true));

                        Test.Assert(!CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", false));
                        CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                        Thread.Sleep((remainingTime + 1) * 1000);
                        Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));
                        blobLease = (CommandAgent as NodeJSAgent).Output[0]["id"] as string;
                        Test.Assert(CommandAgent.RemoveAzureStorageBlob(blobName, containerName, leaseId: blobLease), Utility.GenComparisonData("Delete Blob With Lease", true));
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #9
0
        public void BreakBlobLeaseWithDuration()
        {
            string containerName = Utility.GenNameString("container");
            string blobName      = Utility.GenNameString("blob");

            int[]  durations = { 0, 0, 60 };
            Random random    = new Random();

            durations[1] = random.Next(0, 60);
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

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

                foreach (int duration in durations)
                {
                    Test.Assert(CommandAgent.AcquireLease(containerName, blobName), Utility.GenComparisonData("Acquire Blob Lease", true));

                    if (lang == Language.NodeJS)
                    {
                        try
                        {
                            Test.Assert(CommandAgent.BreakLease(containerName, blobName, duration), Utility.GenComparisonData("Break Blob Lease", true));

                            int remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                            Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                            Thread.Sleep((remainingTime + 1) * 1000);
                        }
                        catch (Exception e)
                        {
                            Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                        }
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #10
0
        public void BreakBlobLeaseWithInvalidDuration()
        {
            string             containerName = Utility.GenNameString("container");
            string             blobName      = Utility.GenNameString("blob");
            int                leaseDuration = 15;
            int                breakDuration = 61;
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);
            CloudBlob          blob          = blobUtil.CreateRandomBlob(container, blobName);

            try
            {
                Test.Assert(CommandAgent.AcquireLease(containerName, blobName, duration: leaseDuration), Utility.GenComparisonData("Acquire Blob Lease", true));

                Test.Assert(!CommandAgent.BreakLease(containerName, blobName, breakDuration), Utility.GenComparisonData("Break Blob Lease With Invalid Duration", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Exemple #11
0
        public void BreakLeaseWithoutEnoughPermission()
        {
            string             containerName    = Utility.GenNameString("container");
            string             blobName         = Utility.GenNameString("blob");
            string             containerLeaseId = string.Empty;
            string             blobLeaseId      = string.Empty;
            CloudBlobContainer container        = blobUtil.CreateContainer(containerName);

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

                Test.Assert(CommandAgent.AcquireLease(containerName, null, duration: 60), 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));
                    }
                }

                // Create a container SAS
                string containerSasToken = string.Empty;
                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)
                };

                string accountSasToken = Utility.GenerateAccountSAS(policy);

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

                Test.Assert(!CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease with SAS", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

                Test.Assert(!CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease with SAS", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);

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

                Test.Assert(!CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease with SAS", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
                Test.Assert(!CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease with SAS", false));
                CommandAgent.ValidateErrorMessage(MethodBase.GetCurrentMethod().Name);
            }
            finally
            {
                blobUtil.RemoveContainer(containerName, containerLeaseId);
            }
        }
Exemple #12
0
        public void BreakLeaseBySAS()
        {
            string             containerName  = Utility.GenNameString("container");
            string             blobName       = Utility.GenNameString("blob");
            CloudBlobContainer container      = blobUtil.CreateContainer(containerName);
            string             containerLease = string.Empty;

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

            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 Container Lease", true));

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

                        Test.Assert(CommandAgent.BreakLease(containerName, null), Utility.GenComparisonData("Break Container Lease", true));
                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                    }
                    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);

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

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

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

                        Test.Assert(CommandAgent.BreakLease(containerName, blobName), Utility.GenComparisonData("Break Blob Lease With Container SAS", true));
                        remainingTime = int.Parse((CommandAgent as NodeJSAgent).Output[0]["time"].ToString());
                        Test.Assert(remainingTime <= duration, Utility.GenComparisonData("Validate remaining time", true));
                        Thread.Sleep((remainingTime + 1) * 1000);
                    }
                    catch (Exception e)
                    {
                        Test.Error(string.Format("{0} error: {1}", MethodBase.GetCurrentMethod().Name, e.Message));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }