Example #1
0
        public void FileSasBuilder_ToSasQueryParameters_NoVersionTest()
        {
            // Arrange
            var             constants      = TestConstants.Create(this);
            var             shareName      = GetNewShareName();
            var             filePath       = GetNewDirectoryName();
            ShareSasBuilder fileSasBuilder = BuildFileSasBuilder(includeVersion: false, includeFilePath: false, constants, shareName, filePath);
            var             signature      = BuildSignature(includeFilePath: false, includeVersion: false, constants, shareName, filePath);

            // Act
            var sasQueryParameters = fileSasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential);

            // Assert
            Assert.AreEqual(SasQueryParameters.DefaultSasVersion, sasQueryParameters.Version);
            Assert.IsNull(sasQueryParameters.Services);
            Assert.IsNull(sasQueryParameters.ResourceTypes);
            Assert.AreEqual(constants.Sas.Protocol, sasQueryParameters.Protocol);
            Assert.AreEqual(constants.Sas.StartTime, sasQueryParameters.StartsOn);
            Assert.AreEqual(constants.Sas.ExpiryTime, sasQueryParameters.ExpiresOn);
            Assert.AreEqual(constants.Sas.IPRange, sasQueryParameters.IPRange);
            Assert.AreEqual(constants.Sas.Identifier, sasQueryParameters.Identifier);
            Assert.AreEqual(Constants.Sas.Resource.Share, sasQueryParameters.Resource);
            Assert.AreEqual(Permissions, sasQueryParameters.Permissions);
            Assert.AreEqual(signature, sasQueryParameters.Signature);
            AssertResponseHeaders(constants, sasQueryParameters);
        }
Example #2
0
        private string BuildSignature(bool includeFilePath, bool includeVersion, TestConstants constants, string shareName, string filePath)
        {
            var canonicalName = "/file/" + constants.Sas.Account + "/" + shareName;

            if (includeFilePath)
            {
                canonicalName += "/" + filePath;
            }

            var stringToSign = string.Join("\n",
                                           Permissions,
                                           SasExtensions.FormatTimesForSasSigning(constants.Sas.StartTime),
                                           SasExtensions.FormatTimesForSasSigning(constants.Sas.ExpiryTime),
                                           canonicalName,
                                           constants.Sas.Identifier,
                                           constants.Sas.IPRange.ToString(),
                                           SasExtensions.ToProtocolString(constants.Sas.Protocol),
                                           includeVersion ? constants.Sas.Version : SasQueryParameters.DefaultSasVersion,
                                           constants.Sas.CacheControl,
                                           constants.Sas.ContentDisposition,
                                           constants.Sas.ContentEncoding,
                                           constants.Sas.ContentLanguage,
                                           constants.Sas.ContentType);

            return(StorageSharedKeyCredentialInternals.ComputeSasSignature(constants.Sas.SharedKeyCredential, stringToSign));
        }
        private ShareSasBuilder BuildFileSasBuilder(bool includeFilePath, TestConstants constants, string shareName, string filePath)
        {
            var fileSasBuilder = new ShareSasBuilder
            {
                Version            = null,
                Protocol           = constants.Sas.Protocol,
                StartsOn           = constants.Sas.StartTime,
                ExpiresOn          = constants.Sas.ExpiryTime,
                IPRange            = constants.Sas.IPRange,
                Identifier         = constants.Sas.Identifier,
                ShareName          = shareName,
                FilePath           = "",
                CacheControl       = constants.Sas.CacheControl,
                ContentDisposition = constants.Sas.ContentDisposition,
                ContentEncoding    = constants.Sas.ContentEncoding,
                ContentLanguage    = constants.Sas.ContentLanguage,
                ContentType        = constants.Sas.ContentType
            };

            fileSasBuilder.SetPermissions(ShareFileSasPermissions.All);

            if (includeFilePath)
            {
                fileSasBuilder.FilePath = filePath;
            }

            return(fileSasBuilder);
        }
Example #4
0
        public void QueueSasBuilder_NullSharedKeyCredentialTest()
        {
            // Arrange
            var             constants       = TestConstants.Create(this);
            var             queueName       = GetNewQueueName();
            QueueSasBuilder queueSasBuilder = BuildQueueSasBuilder(constants, queueName, includeVersion: true);

            // Act
            Assert.Throws <ArgumentNullException>(() => queueSasBuilder.ToSasQueryParameters(null), "sharedKeyCredential");
        }
Example #5
0
        public void FileSasBuilder_NullSharedKeyCredentialTest()
        {
            // Arrange
            var             constants      = TestConstants.Create(this);
            var             shareName      = GetNewShareName();
            var             filePath       = GetNewDirectoryName();
            ShareSasBuilder fileSasBuilder = BuildFileSasBuilder(includeVersion: true, includeFilePath: true, constants, shareName, filePath);

            // Act
            Assert.Throws <ArgumentNullException>(() => fileSasBuilder.ToSasQueryParameters(null), "sharedKeyCredential");
        }
Example #6
0
        private string BuildSignature(TestConstants constants, string queueName, bool includeVersion)
        {
            var stringToSign = string.Join("\n",
                                           Permissions,
                                           SasExtensions.FormatTimesForSasSigning(constants.Sas.StartTime),
                                           SasExtensions.FormatTimesForSasSigning(constants.Sas.ExpiryTime),
                                           "/queue/" + constants.Sas.Account + "/" + queueName,
                                           constants.Sas.Identifier,
                                           constants.Sas.IPRange.ToString(),
                                           SasExtensions.ToProtocolString(SasProtocol.Https),
                                           includeVersion ? constants.Sas.Version : SasQueryParameters.DefaultSasVersion);

            return(StorageSharedKeyCredentialInternals.ComputeSasSignature(constants.Sas.SharedKeyCredential, stringToSign));
        }
        private QueueSasBuilder BuildQueueSasBuilder(TestConstants constants, string queueName)
        {
            var queueSasBuilder = new QueueSasBuilder
            {
                Version    = null,
                Protocol   = constants.Sas.Protocol,
                StartsOn   = constants.Sas.StartTime,
                ExpiresOn  = constants.Sas.ExpiryTime,
                IPRange    = constants.Sas.IPRange,
                Identifier = constants.Sas.Identifier,
                QueueName  = queueName,
            };

            queueSasBuilder.SetPermissions(Permissions);

            return(queueSasBuilder);
        }
        public void ToSasQueryParameters_IdentifierTest()
        {
            // Arrange
            var constants = TestConstants.Create(this);
            var queueName = GetNewQueueName();

            QueueSasBuilder sasBuilder = new QueueSasBuilder
            {
                Identifier = constants.Sas.Identifier,
                QueueName  = queueName,
                Protocol   = SasProtocol.Https,
            };

            // Act
            SasQueryParameters sasQueryParameters = sasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential);

            // Assert
            Assert.AreEqual(constants.Sas.Identifier, sasQueryParameters.Identifier);
            Assert.AreEqual(SasProtocol.Https, sasQueryParameters.Protocol);
            Assert.AreEqual(SasQueryParametersInternals.DefaultSasVersionInternal, sasQueryParameters.Version);
        }
        public void FileSasBuilder_IdentifierTest()
        {
            // Arrange
            TestConstants   constants  = TestConstants.Create(this);
            string          shareName  = GetNewShareName();
            string          resource   = "s";
            ShareSasBuilder sasBuilder = new ShareSasBuilder
            {
                Identifier = constants.Sas.Identifier,
                ShareName  = shareName,
                Resource   = resource,
                Protocol   = SasProtocol.Https,
            };

            // Act
            SasQueryParameters sasQueryParameters = sasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential);

            // Assert
            Assert.AreEqual(constants.Sas.Identifier, sasQueryParameters.Identifier);
            Assert.AreEqual(resource, sasQueryParameters.Resource);
            Assert.AreEqual(SasProtocol.Https, sasQueryParameters.Protocol);
            Assert.AreEqual(SasQueryParametersInternals.DefaultSasVersionInternal, sasQueryParameters.Version);
        }
Example #10
0
        public void QueueSasBuilder_ToSasQueryParameters_NoVersionTest()
        {
            // Arrange
            var             constants       = TestConstants.Create(this);
            var             queueName       = GetNewQueueName();
            QueueSasBuilder queueSasBuilder = BuildQueueSasBuilder(constants, queueName, includeVersion: false);
            var             signature       = BuildSignature(constants, queueName, includeVersion: false);

            // Act
            var sasQueryParameters = queueSasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential);

            // Assert
            Assert.AreEqual(SasQueryParameters.DefaultSasVersion, sasQueryParameters.Version);
            Assert.IsNull(sasQueryParameters.Services);
            Assert.IsNull(sasQueryParameters.ResourceTypes);
            Assert.AreEqual(SasProtocol.Https, sasQueryParameters.Protocol);
            Assert.AreEqual(constants.Sas.StartTime, sasQueryParameters.StartsOn);
            Assert.AreEqual(constants.Sas.ExpiryTime, sasQueryParameters.ExpiresOn);
            Assert.AreEqual(constants.Sas.IPRange, sasQueryParameters.IPRange);
            Assert.AreEqual(constants.Sas.Identifier, sasQueryParameters.Identifier);
            Assert.AreEqual(string.Empty, sasQueryParameters.Resource);
            Assert.AreEqual(Permissions, sasQueryParameters.Permissions);
            Assert.AreEqual(signature, sasQueryParameters.Signature);
        }