예제 #1
0
 public static BlobServiceClient GetServiceClient_BlobServiceSas_Container(
     string containerName,
     SharedKeyCredentials sharedKeyCredentials = default,
     SasQueryParameters sasCredentials         = default)
 => new BlobServiceClient(
     new Uri($"{TestConfigurations.DefaultTargetTenant.BlobServiceEndpoint}?{sasCredentials ?? GetNewBlobServiceSasCredentialsContainer(containerName: containerName, sharedKeyCredentials: sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
     GetOptions <BlobConnectionOptions>());
예제 #2
0
 public static BlobServiceClient GetServiceClient_BlobServiceIdentitySas_Container(
     string containerName,
     UserDelegationKey userDelegationKey,
     SasQueryParameters sasCredentials = default)
 => new BlobServiceClient(
     new Uri($"{TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint}?{sasCredentials ?? GetNewBlobServiceIdentitySasCredentialsContainer(containerName: containerName, userDelegationKey, TestConfigurations.DefaultTargetOAuthTenant.AccountName)}"),
     GetOptions <BlobConnectionOptions>());
        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,
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.StartTime),
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.ExpiryTime),
                                           canonicalName,
                                           constants.Sas.Identifier,
                                           constants.Sas.IPRange.ToString(),
                                           constants.Sas.Protocol.ToProtocolString(),
                                           includeVersion ? constants.Sas.Version : SasQueryParameters.DefaultSasVersion,
                                           constants.Sas.CacheControl,
                                           constants.Sas.ContentDisposition,
                                           constants.Sas.ContentEncoding,
                                           constants.Sas.ContentLanguage,
                                           constants.Sas.ContentType);

            return(constants.Sas.SharedKeyCredential.ComputeHMACSHA256(stringToSign));
        }
        /// <summary>
        /// Use an account's <see cref="StorageSharedKeyCredential"/> to sign this
        /// shared access signature values to produce the proper SAS query
        /// parameters for authenticating requests.
        /// </summary>
        /// <param name="sharedKeyCredential">
        /// The storage account's <see cref="StorageSharedKeyCredential"/>.
        /// </param>
        /// <returns>
        /// The <see cref="DataLakeSasQueryParameters"/> used for authenticating
        /// requests.
        /// </returns>
        public DataLakeSasQueryParameters ToSasQueryParameters(StorageSharedKeyCredential sharedKeyCredential)
        {
            sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential));

            EnsureState();

            var startTime  = SasQueryParameters.FormatTimesForSasSigning(StartsOn);
            var expiryTime = SasQueryParameters.FormatTimesForSasSigning(ExpiresOn);

            // See http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
            var stringToSign = String.Join("\n",
                                           Permissions,
                                           startTime,
                                           expiryTime,
                                           GetCanonicalName(sharedKeyCredential.AccountName, FileSystemName ?? String.Empty, Path ?? String.Empty),
                                           Identifier,
                                           IPRange.ToString(),
                                           Protocol.ToProtocolString(),
                                           Version,
                                           Resource,
                                           null, // snapshot
                                           CacheControl,
                                           ContentDisposition,
                                           ContentEncoding,
                                           ContentLanguage,
                                           ContentType);

            var signature = sharedKeyCredential.ComputeHMACSHA256(stringToSign);

            var p = new DataLakeSasQueryParameters(
                version: Version,
                services: default,
예제 #5
0
        private string BuildSignature(bool includeBlob, bool includeSnapshot, string containerName, string blobName, TestConstants constants)
        {
            var canonicalName = includeBlob ? $"/blob/{constants.Sas.Account}/{containerName}/{blobName}"
                : $"/blob/{constants.Sas.Account}/{containerName}";

            var resource = Constants.Sas.Resource.Container;

            if (includeBlob && includeSnapshot)
            {
                resource = Constants.Sas.Resource.BlobSnapshot;
            }
            else if (includeBlob)
            {
                resource = Constants.Sas.Resource.Blob;
            }

            var stringToSign = String.Join("\n",
                                           Permissions,
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.StartTime),
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.ExpiryTime),
                                           canonicalName,
                                           constants.Sas.Identifier,
                                           constants.Sas.IPRange.ToString(),
                                           constants.Sas.Protocol.ToString(),
                                           SasQueryParameters.DefaultSasVersion,
                                           resource,
                                           includeSnapshot ? Snapshot : null,
                                           constants.Sas.CacheControl,
                                           constants.Sas.ContentDisposition,
                                           constants.Sas.ContentEncoding,
                                           constants.Sas.ContentLanguage,
                                           constants.Sas.ContentType);

            return(constants.Sas.SharedKeyCredential.ComputeHMACSHA256(stringToSign));
        }
 public BlobServiceClient GetServiceClient_AccountSas(
     SharedKeyCredentials sharedKeyCredentials = default,
     SasQueryParameters sasCredentials         = default)
 => this.InstrumentClient(
     new BlobServiceClient(
         new Uri($"{TestConfigurations.DefaultTargetTenant.BlobServiceEndpoint}?{sasCredentials ?? this.GetNewAccountSasCredentials(sharedKeyCredentials ?? this.GetNewSharedKeyCredentials())}"),
         this.GetOptions()));
예제 #7
0
 internal void AssertResponseHeaders(TestConstants constants, SasQueryParameters sasQueryParameters)
 {
     Assert.AreEqual(constants.Sas.CacheControl, sasQueryParameters.CacheControl);
     Assert.AreEqual(constants.Sas.ContentDisposition, sasQueryParameters.ContentDisposition);
     Assert.AreEqual(constants.Sas.ContentEncoding, sasQueryParameters.ContentEncoding);
     Assert.AreEqual(constants.Sas.ContentLanguage, sasQueryParameters.ContentLanguage);
     Assert.AreEqual(constants.Sas.ContentType, sasQueryParameters.ContentType);
 }
 public BlobServiceClient GetServiceClient_BlobServiceSas_Blob(
     string containerName,
     string blobName,
     SharedKeyCredentials sharedKeyCredentials = default,
     SasQueryParameters sasCredentials         = default)
 => this.InstrumentClient(
     new BlobServiceClient(
         new Uri($"{TestConfigurations.DefaultTargetTenant.BlobServiceEndpoint}?{sasCredentials ?? this.GetNewBlobServiceSasCredentialsBlob(containerName: containerName, blobName: blobName, sharedKeyCredentials: sharedKeyCredentials ?? this.GetNewSharedKeyCredentials())}"),
         this.GetOptions()));
 public BlobServiceClient GetServiceClient_BlobServiceIdentitySas_Blob(
     string containerName,
     string blobName,
     UserDelegationKey userDelegationKey,
     SasQueryParameters sasCredentials = default)
 => this.InstrumentClient(
     new BlobServiceClient(
         new Uri($"{TestConfigurations.DefaultTargetOAuthTenant.BlobServiceEndpoint}?{sasCredentials ?? this.GetNewBlobServiceIdentitySasCredentialsBlob(containerName: containerName, blobName: blobName, userDelegationKey: userDelegationKey, accountName: TestConfigurations.DefaultTargetOAuthTenant.AccountName)}"),
         this.GetOptions()));
예제 #10
0
        /// <summary>
        /// Use an account's <see cref="UserDelegationKey"/> to sign this
        /// shared access signature values to produce the propery SAS query
        /// parameters for authenticating requests.
        /// </summary>
        /// <param name="userDelegationKey">
        /// A <see cref="UserDelegationKey"/> returned from
        /// <see cref="BlobServiceClient.GetUserDelegationKeyAsync"/>.
        /// </param>
        /// <param name="accountName">The name of the storage account.</param>
        /// <returns>
        /// The <see cref="SasQueryParameters"/> used for authenticating requests.
        /// </returns>
        public SasQueryParameters ToSasQueryParameters(UserDelegationKey userDelegationKey, string accountName)
        {
            userDelegationKey = userDelegationKey ?? throw new ArgumentNullException(nameof(userDelegationKey));

            this.EnsureState();

            var startTime    = SasQueryParameters.FormatTimesForSasSigning(this.StartTime);
            var expiryTime   = SasQueryParameters.FormatTimesForSasSigning(this.ExpiryTime);
            var signedStart  = SasQueryParameters.FormatTimesForSasSigning(userDelegationKey.SignedStart);
            var signedExpiry = SasQueryParameters.FormatTimesForSasSigning(userDelegationKey.SignedExpiry);

            // See http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
            var stringToSign = String.Join("\n",
                                           this.Permissions,
                                           startTime,
                                           expiryTime,
                                           GetCanonicalName(accountName, this.ContainerName ?? String.Empty, this.BlobName ?? String.Empty),
                                           userDelegationKey.SignedOid,
                                           userDelegationKey.SignedTid,
                                           signedStart,
                                           signedExpiry,
                                           userDelegationKey.SignedService,
                                           userDelegationKey.SignedVersion,
                                           this.IPRange.ToString(),
                                           this.Protocol.ToString(),
                                           this.Version,
                                           this.Resource,
                                           this.Snapshot,
                                           this.CacheControl,
                                           this.ContentDisposition,
                                           this.ContentEncoding,
                                           this.ContentLanguage,
                                           this.ContentType);

            var signature = ComputeHMACSHA256(userDelegationKey.Value, stringToSign);

            var p = new SasQueryParameters(
                version: this.Version,
                services: null,
                resourceTypes: null,
                protocol: this.Protocol,
                startTime: this.StartTime,
                expiryTime: this.ExpiryTime,
                ipRange: this.IPRange,
                identifier: null,
                resource: this.Resource,
                permissions: this.Permissions,
                keyOid: userDelegationKey.SignedOid,
                keyTid: userDelegationKey.SignedTid,
                keyStart: userDelegationKey.SignedStart,
                keyExpiry: userDelegationKey.SignedExpiry,
                keyService: userDelegationKey.SignedService,
                keyVersion: userDelegationKey.SignedVersion,
                signature: signature);

            return(p);
        }
예제 #11
0
        public async Task Ctor_Uri()
        {
            // Arrange
            SasQueryParameters sasQueryParameters = GetNewAccountSasCredentials();
            Uri uri = new Uri($"{TestConfigHierarchicalNamespace.BlobServiceEndpoint}?{sasQueryParameters}");
            DataLakeServiceClient serviceClient = InstrumentClient(new DataLakeServiceClient(uri, GetOptions()));

            // Act
            await serviceClient.GetFileSystemsAsync().ToListAsync();

            // Assert
            Assert.AreEqual(uri, serviceClient.Uri);
        }
        private string BuildSignature(TestConstants constants, string queueName, bool includeVersion)
        {
            var stringToSign = string.Join("\n",
                                           Permissions,
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.StartTime),
                                           SasQueryParameters.FormatTimesForSasSigning(constants.Sas.ExpiryTime),
                                           "/queue/" + constants.Sas.Account + "/" + queueName,
                                           constants.Sas.Identifier,
                                           constants.Sas.IPRange.ToString(),
                                           SasProtocol.Https.ToString(),
                                           includeVersion ? constants.Sas.Version : SasQueryParameters.DefaultSasVersion);

            return(constants.Sas.SharedKeyCredential.ComputeHMACSHA256(stringToSign));
        }
예제 #13
0
        public void SasQueryParameters_RoundTrip()
        {
            var version = "2018-03-28";
            AccountSasServices      service      = AccountSasServices.Blobs;
            AccountSasResourceTypes resourceType = AccountSasResourceTypes.Container;
            SasProtocol             protocol     = SasProtocol.Https;
            DateTimeOffset          startTime    = DateTimeOffset.Now;
            DateTimeOffset          expiryTime   = startTime.AddDays(1);
            var ipRange            = new SasIPRange();
            var identifier         = "foo";
            var resource           = "bar";
            var permissions        = "rw";
            var signature          = "a+b=";
            var cacheControl       = "no-store";
            var contentDisposition = "inline";
            var contentEncoding    = "identity";
            var contentLanguage    = "en-US";
            var contentType        = "text/html";

            var sasQueryParameters = new SasQueryParameters(
                version,
                service,
                resourceType,
                protocol,
                startTime,
                expiryTime,
                ipRange,
                identifier,
                resource,
                permissions,
                signature,
                cacheControl: cacheControl,
                contentDisposition: contentDisposition,
                contentEncoding: contentEncoding,
                contentLanguage: contentLanguage,
                contentType: contentType
                );

            Assert.AreEqual(signature, sasQueryParameters.Signature);

            var sasString = sasQueryParameters.ToString();

            var roundTripSas = new SasQueryParameters(new UriQueryParamsCollection(sasString));

            Assert.AreEqual(sasQueryParameters.ToString(), roundTripSas.ToString());
        }
예제 #14
0
        /// <summary>
        /// Use an account's <see cref="SharedKeyCredentials"/> to sign this
        /// shared access signature values to produce the proper SAS query
        /// parameters for authenticating requests.
        /// </summary>
        /// <param name="sharedKeyCredential">
        /// The storage account's <see cref="SharedKeyCredentials"/>.
        /// </param>
        /// <returns>
        /// The <see cref="SasQueryParameters"/> used for authenticating requests.
        /// </returns>
        public SasQueryParameters ToSasQueryParameters(SharedKeyCredentials sharedKeyCredential)
        {
            sharedKeyCredential = sharedKeyCredential ?? throw new ArgumentNullException(nameof(sharedKeyCredential));

            this.EnsureState();

            var startTime  = SasQueryParameters.FormatTimesForSasSigning(this.StartTime);
            var expiryTime = SasQueryParameters.FormatTimesForSasSigning(this.ExpiryTime);

            // See http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
            var stringToSign = String.Join("\n",
                                           this.Permissions,
                                           startTime,
                                           expiryTime,
                                           GetCanonicalName(sharedKeyCredential.AccountName, this.ContainerName ?? String.Empty, this.BlobName ?? String.Empty),
                                           this.Identifier,
                                           this.IPRange.ToString(),
                                           this.Protocol.ToString(),
                                           this.Version,
                                           this.Resource,
                                           this.Snapshot,
                                           this.CacheControl,
                                           this.ContentDisposition,
                                           this.ContentEncoding,
                                           this.ContentLanguage,
                                           this.ContentType);

            var signature = sharedKeyCredential.ComputeHMACSHA256(stringToSign);

            var p = new SasQueryParameters(
                version: this.Version,
                services: null,
                resourceTypes: null,
                protocol: this.Protocol,
                startTime: this.StartTime,
                expiryTime: this.ExpiryTime,
                ipRange: this.IPRange,
                identifier: this.Identifier,
                resource: this.Resource,
                permissions: this.Permissions,
                signature: signature);

            return(p);
        }
예제 #15
0
        public async Task FindBlobsByTagAsync_AccountSas(AccountSasPermissions accountSasPermissions)
        {
            // Arrange
            BlobServiceClient service = GetServiceClient_SharedKey();

            await using DisposingContainer test = await GetTestContainerAsync();

            string                      blobName   = GetNewBlobName();
            AppendBlobClient            appendBlob = InstrumentClient(test.Container.GetAppendBlobClient(blobName));
            string                      tagKey     = "myTagKey";
            string                      tagValue   = "myTagValue";
            Dictionary <string, string> tags       = new Dictionary <string, string>
            {
                { tagKey, tagValue }
            };
            AppendBlobCreateOptions options = new AppendBlobCreateOptions
            {
                Tags = tags
            };
            await appendBlob.CreateAsync(options);

            string expression = $"\"{tagKey}\"='{tagValue}'";

            // It takes a few seconds for Filter Blobs to pick up new changes
            await Delay(2000);

            // Act
            SasQueryParameters    sasQueryParameters = GetNewAccountSas(permissions: accountSasPermissions);
            BlobServiceClient     sasServiceClient   = new BlobServiceClient(new Uri($"{service.Uri}?{sasQueryParameters}"), GetOptions());
            List <TaggedBlobItem> blobs = new List <TaggedBlobItem>();

            await foreach (Page <TaggedBlobItem> page in sasServiceClient.FindBlobsByTagsAsync(expression).AsPages())
            {
                blobs.AddRange(page.Values);
            }

            // Assert
            TaggedBlobItem filterBlob = blobs.Where(r => r.BlobName == blobName).FirstOrDefault();

            Assert.IsNotNull(filterBlob);
        }
        public async Task Ctor_Uri()
        {
            string fileSystemName = GetNewFileSystemName();

            await using DisposingFileSystem test = await GetNewFileSystem(fileSystemName : fileSystemName);

            // Arrange
            string directoryName = GetNewDirectoryName();
            await test.FileSystem.CreateDirectoryAsync(directoryName);

            SasQueryParameters sasQueryParameters = GetNewAccountSasCredentials();
            Uri uri = new Uri($"{TestConfigHierarchicalNamespace.BlobServiceEndpoint}/{fileSystemName}/{directoryName}?{sasQueryParameters}");
            DataLakePathClient pathClient = InstrumentClient(new DataLakePathClient(uri, GetOptions()));

            // Act
            await pathClient.GetPropertiesAsync();

            // Assert
            Assert.AreEqual(fileSystemName, pathClient.FileSystemName);
            Assert.AreEqual(uri, pathClient.Uri);
        }
        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);
        }
예제 #18
0
        private string BuildIdentitySignature(bool includeBlob, bool includeSnapshot)
        {
            var canonicalName = includeBlob ? $"/blob/{TestConstants.Sas.Account}/{ContainerName}/{BlobName}"
                : $"/blob/{TestConstants.Sas.Account}/{ContainerName}";

            var resource = Constants.Sas.Resource.Container;

            if (includeBlob && includeSnapshot)
            {
                resource = Constants.Sas.Resource.BlobSnapshot;
            }
            else if (includeBlob)
            {
                resource = Constants.Sas.Resource.Blob;
            }

            var stringToSign = String.Join("\n",
                                           Permissions,
                                           SasQueryParameters.FormatTimesForSasSigning(TestConstants.Sas.StartTime),
                                           SasQueryParameters.FormatTimesForSasSigning(TestConstants.Sas.ExpiryTime),
                                           canonicalName,
                                           TestConstants.Sas.KeyOid,
                                           TestConstants.Sas.KeyTid,
                                           SasQueryParameters.FormatTimesForSasSigning(TestConstants.Sas.KeyStart),
                                           SasQueryParameters.FormatTimesForSasSigning(TestConstants.Sas.KeyExpiry),
                                           TestConstants.Sas.KeyService,
                                           TestConstants.Sas.KeyVersion,
                                           TestConstants.Sas.IPRange.ToString(),
                                           TestConstants.Sas.Protocol.ToString(),
                                           SasQueryParameters.SasVersion,
                                           resource,
                                           includeSnapshot ? Snapshot : null,
                                           TestConstants.Sas.CacheControl,
                                           TestConstants.Sas.ContentDisposition,
                                           TestConstants.Sas.ContentEncoding,
                                           TestConstants.Sas.ContentLanguage,
                                           TestConstants.Sas.ContentType);

            return(this.ComputeHMACSHA256(TestConstants.Sas.KeyValue, stringToSign));
        }
예제 #19
0
        /// <summary>
        /// ToSasQueryParameters uses an account's shared key credential to sign this signature values to produce
        /// the proper SAS query parameters.
        /// </summary>
        /// <param name="sharedKeyCredential">
        /// <see cref="SharedKeyCredentials"/>
        /// </param>
        /// <returns>
        /// <see cref="SasQueryParameters"/>
        /// </returns>
        public SasQueryParameters ToSasQueryParameters(SharedKeyCredentials sharedKeyCredential)
        {
            sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential));

            this.Permissions = QueueAccountSasPermissions.Parse(this.Permissions).ToString();
            if (String.IsNullOrEmpty(this.Version))
            {
                this.Version = SasQueryParameters.SasVersion;
            }

            var startTime  = SasQueryParameters.FormatTimesForSasSigning(this.StartTime);
            var expiryTime = SasQueryParameters.FormatTimesForSasSigning(this.ExpiryTime);

            // String to sign: http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
            var stringToSign = String.Join("\n",
                                           this.Permissions,
                                           startTime,
                                           expiryTime,
                                           GetCanonicalName(sharedKeyCredential.AccountName, this.QueueName ?? String.Empty),
                                           this.Identifier,
                                           this.IPRange.ToString(),
                                           this.Protocol.ToString(),
                                           this.Version);
            var signature = sharedKeyCredential.ComputeHMACSHA256(stringToSign);
            var p         = new SasQueryParameters(
                version: this.Version,
                services: null,
                resourceTypes: null,
                protocol: this.Protocol,
                startTime: this.StartTime,
                expiryTime: this.ExpiryTime,
                ipRange: this.IPRange,
                identifier: this.Identifier,
                resource: null,
                permissions: this.Permissions,
                signature: signature);

            return(p);
        }
        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);
        }
예제 #21
0
        // NewSASQueryParameters uses an account's shared key credential to sign this signature values to produce
        // the proper SAS query parameters.
        public SasQueryParameters ToSasQueryParameters(SharedKeyCredentials sharedKeyCredential)
        {
            // https://docs.microsoft.com/en-us/rest/api/storageservices/Constructing-an-Account-SAS
            sharedKeyCredential = sharedKeyCredential ?? throw Errors.ArgumentNull(nameof(sharedKeyCredential));

            if (this.ExpiryTime == default || String.IsNullOrEmpty(this.Permissions) || String.IsNullOrEmpty(this.ResourceTypes) || String.IsNullOrEmpty(this.Services))
            {
                throw Errors.AccountSasMissingData();
            }
            if (String.IsNullOrEmpty(this.Version))
            {
                this.Version = SasQueryParameters.SasVersion;
            }
            // Make sure the permission characters are in the correct order
            this.Permissions = AccountSasPermissions.Parse(this.Permissions).ToString();
            var startTime  = SasQueryParameters.FormatTimesForSasSigning(this.StartTime);
            var expiryTime = SasQueryParameters.FormatTimesForSasSigning(this.ExpiryTime);

            // String to sign: http://msdn.microsoft.com/en-us/library/azure/dn140255.aspx
            var stringToSign = String.Join("\n",
                                           sharedKeyCredential.AccountName,
                                           this.Permissions,
                                           this.Services,
                                           this.ResourceTypes,
                                           startTime,
                                           expiryTime,
                                           this.IPRange.ToString(),
                                           this.Protocol.ToString(),
                                           this.Version,
                                           ""); // That's right, the account SAS requires a terminating extra newline

            var signature = sharedKeyCredential.ComputeHMACSHA256(stringToSign);
            var p         = new SasQueryParameters(this.Version, this.Services, this.ResourceTypes, this.Protocol, this.StartTime, this.ExpiryTime, this.IPRange, null, null, this.Permissions, signature);

            return(p);
        }
        public async Task RenameBlobContainerAsync_AccountSas()
        {
            // Arrange
            BlobServiceClient   service          = GetServiceClient_SharedKey();
            string              oldContainerName = GetNewContainerName();
            string              newContainerName = GetNewContainerName();
            BlobContainerClient container        = InstrumentClient(service.GetBlobContainerClient(oldContainerName));
            await container.CreateAsync();

            SasQueryParameters sasQueryParameters = GetNewAccountSas();

            service = InstrumentClient(new BlobServiceClient(new Uri($"{service.Uri}?{sasQueryParameters}"), GetOptions()));

            // Act
            BlobContainerClient newContainer = await service.RenameBlobContainerAsync(
                sourceContainerName : oldContainerName,
                destinationContainerName : newContainerName);

            // Assert
            await newContainer.GetPropertiesAsync();

            // Cleanup
            await newContainer.DeleteAsync();
        }
예제 #23
0
        public void SasQueryParameters_RoundTrip()
        {
            var            version      = "2018-03-28";
            var            service      = "b";
            var            resourceType = "c";
            SasProtocol    protocol     = SasProtocol.Https;
            DateTimeOffset startTime    = DateTimeOffset.Now;
            DateTimeOffset expiryTime   = startTime.AddDays(1);
            var            ipRange      = new IPRange();
            var            identifier   = "foo";
            var            resource     = "bar";
            var            permissions  = "rw";
            var            signature    = "a+b=";

            var sasQueryParameters = new SasQueryParameters(
                version,
                service,
                resourceType,
                protocol,
                startTime,
                expiryTime,
                ipRange,
                identifier,
                resource,
                permissions,
                signature
                );

            Assert.AreEqual(signature, sasQueryParameters.Signature);

            var sasString = sasQueryParameters.ToString();

            var roundTripSas = new SasQueryParameters(new UriQueryParamsCollection(sasString));

            Assert.AreEqual(sasQueryParameters.ToString(), roundTripSas.ToString());
        }
 public QueueServiceClient GetServiceClient_QueueServiceSas(string queueName, StorageSharedKeyCredential sharedKeyCredentials = default, SasQueryParameters sasCredentials = default)
 => InstrumentClient(
     new QueueServiceClient(
         new Uri($"{TestConfigDefault.QueueServiceEndpoint}?{sasCredentials ?? GetNewQueueServiceSasCredentials(queueName, sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
         GetOptions()));
예제 #25
0
 public ShareServiceClient GetServiceClient_FileServiceSasFile(string shareName, string filePath, StorageSharedKeyCredential sharedKeyCredentials = default, SasQueryParameters sasCredentials = default)
 => InstrumentClient(
     new ShareServiceClient(
         new Uri($"{TestConfigDefault.FileServiceEndpoint}?{sasCredentials ?? GetNewFileServiceSasCredentialsFile(shareName, filePath, sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
         GetOptions()));
예제 #26
0
 public ShareServiceClient GetServiceClient_AccountSas(StorageSharedKeyCredential sharedKeyCredentials = default, SasQueryParameters sasCredentials = default)
 => InstrumentClient(
     new ShareServiceClient(
         new Uri($"{TestConfigDefault.FileServiceEndpoint}?{sasCredentials ?? GetNewAccountSasCredentials(sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
         GetOptions()));
예제 #27
0
 public QueueServiceClient GetServiceClient_AccountSas(StorageSharedKeyCredential sharedKeyCredentials = default, SasQueryParameters sasCredentials = default)
 => this.InstrumentClient(
     new QueueServiceClient(
         new Uri($"{this.TestConfigDefault.QueueServiceEndpoint}?{sasCredentials ?? this.GetNewAccountSasCredentials(sharedKeyCredentials ?? this.GetNewSharedKeyCredentials())}"),
         this.GetOptions()));
예제 #28
0
 public static QueueServiceClient GetServiceClient_QueueServiceSas(string queueName, SharedKeyCredentials sharedKeyCredentials = default, SasQueryParameters sasCredentials = default)
 => new QueueServiceClient(
     new Uri($"{TestConfigurations.DefaultTargetTenant.QueueServiceEndpoint}?{sasCredentials ?? GetNewQueueServiceSasCredentials(queueName, sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
     GetOptions <QueueConnectionOptions>());
예제 #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlobUriBuilder"/>
        /// class with the specified <see cref="Uri"/>.
        /// </summary>
        /// <param name="uri">
        /// The <see cref="Uri"/> to a storage resource.
        /// </param>
        public BlobUriBuilder(Uri uri)
        {
            this.Scheme      = uri.Scheme;
            this.Host        = uri.Host;
            this.Port        = uri.Port;
            this.AccountName = "";

            this.ContainerName = "";
            this.BlobName      = "";

            this.Snapshot = "";
            //this.VersionId = "";
            this.Sas = null;

            // Find the account, container, & blob names (if any)
            if (!String.IsNullOrEmpty(uri.AbsolutePath))
            {
                // If path starts with a slash, remove it
                var path =
                    (uri.AbsolutePath[0] == '/')
                    ? uri.AbsolutePath.Substring(1)
                    : uri.AbsolutePath;

                var startIndex = 0;

                if (IsHostIPEndPointStyle(uri.Host))
                {
                    var accountEndIndex = path.IndexOf("/", StringComparison.InvariantCulture);

                    // Slash not found; path has account name & no container name
                    if (accountEndIndex == -1)
                    {
                        this.AccountName = path;
                        startIndex       = path.Length;
                    }
                    else
                    {
                        this.AccountName = path.Substring(0, accountEndIndex);
                        startIndex       = accountEndIndex + 1;
                    }
                }

                // Find the next slash (if it exists)
                var containerEndIndex = path.IndexOf("/", startIndex, StringComparison.InvariantCulture);
                if (containerEndIndex == -1)
                {
                    this.ContainerName = path.Substring(startIndex); // Slash not found; path has container name & no blob name
                }
                else
                {
                    this.ContainerName = path.Substring(startIndex, containerEndIndex - startIndex); // The container name is the part between the slashes
                    this.BlobName      = path.Substring(containerEndIndex + 1);                      // The blob name is after the container slash
                }
            }

            // Convert the query parameters to a case-sensitive map & trim whitespace
            var paramsMap = new UriQueryParamsCollection(uri.Query);

            if (paramsMap.TryGetValue(SnapshotParameterName, out var snapshotTime))
            {
                this.Snapshot = snapshotTime;

                // If we recognized the query parameter, remove it from the map
                paramsMap.Remove(SnapshotParameterName);
            }

            //if(paramsMap.TryGetValue(VersionIdParameterName, out var versionId))
            //{
            //    this.VersionId = versionId;

            //    // If we recognized the query parameter, remove it from the map
            //    paramsMap.Remove(VersionIdParameterName);
            //}

            if (paramsMap.ContainsKey(SasVersionKey))
            {
                this.Sas = new SasQueryParameters(paramsMap);
            }

            this.UnparsedParams = paramsMap.ToString();
        }
예제 #30
0
 public static BlobServiceClient GetServiceClient_AccountSas(
     SharedKeyCredentials sharedKeyCredentials = default,
     SasQueryParameters sasCredentials         = default)
 => new BlobServiceClient(
     new Uri($"{TestConfigurations.DefaultTargetTenant.BlobServiceEndpoint}?{sasCredentials ?? GetNewAccountSasCredentials(sharedKeyCredentials ?? GetNewSharedKeyCredentials())}"),
     GetOptions <BlobConnectionOptions>());