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 Blob_CreateResourceToken_ReturnsCorrectHostPath()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

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

            // Assert.
            Assert.IsNotNull(token);

            SASParts parts = new SASParts(token.Uri);
            Assert.AreEqual("https://test.blob.core.windows.net/container/blob", parts.HostName);
        }
        public void Blob_CreateResourceToken_WithReadUpdateDeletePermissions_ThrowsBadRequest()
        {
            // Setup
            AzureBlobBroker broker = new AzureBlobBroker();

            // Act
            this.ExpectHttpResponseException(HttpStatusCode.BadRequest, () => broker.CreateResourceToken(ConnectionString, new BlobParameters { Name = "blob", Container = "container", Permissions = ResourcePermissions.Read | ResourcePermissions.Update | ResourcePermissions.Delete, Expiration = DateTime.Now + TimeSpan.FromDays(1) }));
        }
        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 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_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_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"));
        }