Exemple #1
0
        public void Table_CreateResourceToken_ReturnsExpectedStartDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            // Calculate the expected start time give or take 4 seconds.
            DateTime startRangeBegin = DateTime.UtcNow - TimeSpan.FromMinutes(5) - TimeSpan.FromSeconds(2);
            DateTime startRangeEnd   = startRangeBegin + TimeSpan.FromSeconds(2);

            // Now convert these into strings using the SAS format.
            string startRangeBeginString = this.DateTimeToSASDateString(startRangeBegin);
            string startRangeEndString   = this.DateTimeToSASDateString(startRangeEnd);

            // Get the actual begin time from the SAS token.
            SASParts parts     = new SASParts(token.Uri);
            string   beginning = parts.Value("st");

            // Make sure it is within the range.
            Assert.IsTrue(string.CompareOrdinal(beginning, startRangeBeginString) >= 0 && string.CompareOrdinal(beginning, startRangeEndString) <= 0);
        }
Exemple #2
0
        public void Blob_CreateResourceToken_WithReadAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("rw", parts.Value("sp"));
        }
Exemple #3
0
        public void Blob_CreateResourceToken_WithProcessPermissions_IgnoresProcessPermissions()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("r", parts.Value("sp"));
        }
Exemple #4
0
        public void Table_CreateResourceToken_WithAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("aud", parts.Value("sp"));
        }
        public void Queue_CreateResourceToken_WithReadAndProcessPermissions_ReturnsCorrectAccess()
        {
            AzureQueueBroker broker = new AzureQueueBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "queue", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1)
            });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("rp", parts.Value("sp"));
        }
Exemple #6
0
        public void Table_CreateResourceToken_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual(null, parts.Value("se"));
        }
Exemple #7
0
        public void Blob_CreateResourceAsync_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters {
                Name = "blob", Container = "container", Permissions = ResourcePermissions.Read
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual(null, parts.Value("se"));
        }
Exemple #8
0
        public void Table_CreateResourceToken_WithExpirationDate_ReturnsCorrectExpirationDate()
        {
            // Setup
            DateTime         expiration = new DateTime(2199, 3, 12, 1, 2, 3, DateTimeKind.Utc);
            AzureTableBroker broker     = new AzureTableBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", Permissions = ResourcePermissions.Read, Expiration = expiration
            });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("2199-03-12T01%3A02%3A03Z", parts.Value("se"));
        }
        public void Queue_CreateResourceToken_WithAddUpdateProcessPermissions_ReturnsCorrectAccess()
        {
            AzureQueueBroker broker = new AzureQueueBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters { Name = "queue", Permissions = ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1) });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("aup", parts.Value("sp"));
        }
        public void Blob_CreateResourceToken_WithAddUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Add | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1) });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("w", parts.Value("sp"));
        }
        public void Queue_CreateResourceToken_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureQueueBroker broker = new AzureQueueBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters { Name = "queue", Permissions = ResourcePermissions.Read });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual(null, parts.Value("se"));
        }
        public void Queue_CreateResourceToken_WithDeletePermissions_IgnoresProcessPermissions()
        {
            // Setup
            AzureQueueBroker broker = new AzureQueueBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters { Name = "queue", Permissions = ResourcePermissions.Read | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1) });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("r", parts.Value("sp"));
        }
        public void Blob_CreateResourceAsync_WithExpirationDate_ReturnsCorrectExpirationDate()
        {
            // Setup
            DateTime expiration = new DateTime(2199, 3, 12, 1, 2, 3, DateTimeKind.Utc);
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Read, Expiration = expiration });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("2199-03-12T01%3A02%3A03Z", parts.Value("se"));
        }
        public void Blob_CreateResourceAsync_WithNoExpirationDate_ReturnsNoExpirationDate()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Read });

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual(null, parts.Value("se"));
        }
        public void Blob_CreateResourceAsync_ReturnsExpectedStartDate()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act.
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Read });

            // Assert.
            Assert.IsNotNull(token);

            // Calculate the expected start time give or take 4 seconds.
            DateTime startRangeBegin = DateTime.UtcNow - TimeSpan.FromMinutes(5) - TimeSpan.FromSeconds(2);
            DateTime startRangeEnd = startRangeBegin + TimeSpan.FromSeconds(2);

            // Now convert these into strings using the SAS format.
            string startRangeBeginString = this.DateTimeToSASDateString(startRangeBegin);
            string startRangeEndString = this.DateTimeToSASDateString(startRangeEnd);

            // Get the actual begin time from the SAS token.
            SASParts parts = new SASParts(token.Uri);
            string beginning = parts.Value("st");

            // Make sure it is within the range.
            Assert.IsTrue(string.CompareOrdinal(beginning, startRangeBeginString) >= 0 && string.CompareOrdinal(beginning, startRangeEndString) <= 0);
        }
        public void Blob_CreateResourceToken_WithProcessPermissions_IgnoresProcessPermissions()
        {
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Process, Expiration = DateTime.Now + TimeSpan.FromDays(1) });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("r", parts.Value("sp"));
        }
        public void Table_CreateResourceToken_WithReadUpdateDeletePermissions_ReturnsCorrectAccess()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters { Name = "table", Permissions = ResourcePermissions.Read | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1) });

            // Assert.
            Assert.IsNotNull(token);
            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("rud", parts.Value("sp"));
        }