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 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"));
        }
Exemple #3
0
        public void Table_CreateResourceToken_WithProcessPermissions_IgnoresProcessPermissions()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

            // Act
            ResourceToken token = broker.CreateResourceToken(ConnectionString, new ResourceParameters {
                Name = "table", 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_ReturnsCorrectHostPath()
        {
            // Setup
            AzureTableBroker broker = new AzureTableBroker();

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

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);

            Assert.AreEqual("https://test.table.core.windows.net/table", parts.HostName);
        }
Exemple #5
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 #6
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"));
        }