public void ToSasQueryParameters_ContainerTest()
        {
            // Arrange
            var            constants      = TestConstants.Create(this);
            var            containerName  = GetNewContainerName();
            var            blobName       = GetNewBlobName();
            BlobSasBuilder blobSasBuilder = BuildBlobSasBuilder(includeBlob: false, includeSnapshot: false, containerName, blobName, constants);
            var            signature      = BuildSignature(includeBlob: false, includeSnapshot: false, containerName, blobName, constants);

            // Act
            BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential);

            // Assert
            Assert.AreEqual(SasQueryParametersInternals.DefaultSasVersionInternal, 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.Container, sasQueryParameters.Resource);
            Assert.AreEqual(Permissions, sasQueryParameters.Permissions);
            Assert.AreEqual(signature, sasQueryParameters.Signature);
            AssertResponseHeaders(constants, sasQueryParameters);
        }
Пример #2
0
        public void GenerateAccountSas_Builder()
        {
            TestConstants           constants     = TestConstants.Create(this);
            Uri                     serviceUri    = new Uri($"https://{constants.Sas.Account}.queue.core.windows.net");
            AccountSasPermissions   permissions   = AccountSasPermissions.Read | AccountSasPermissions.Write;
            DateTimeOffset          expiresOn     = Recording.UtcNow.AddHours(+1);
            AccountSasServices      services      = AccountSasServices.Queues;
            AccountSasResourceTypes resourceTypes = AccountSasResourceTypes.All;
            QueueServiceClient      serviceClient = InstrumentClient(
                new QueueServiceClient(
                    serviceUri,
                    constants.Sas.SharedKeyCredential,
                    GetOptions()));

            AccountSasBuilder sasBuilder = new AccountSasBuilder(permissions, expiresOn, services, resourceTypes);

            // Add more properties on the builder
            sasBuilder.SetPermissions(permissions);

            // Act
            Uri sasUri = serviceClient.GenerateAccountSasUri(sasBuilder);

            // Assert
            AccountSasBuilder sasBuilder2 = new AccountSasBuilder(permissions, expiresOn, services, resourceTypes);
            UriBuilder        expectedUri = new UriBuilder(serviceUri);

            expectedUri.Query += sasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential).ToString();
            Assert.AreEqual(expectedUri.Uri, sasUri);
        }
        public void ToSasQueryParameters_ContainerIdentityTest()
        {
            // Arrange
            var            constants      = TestConstants.Create(this);
            var            containerName  = GetNewContainerName();
            var            blobName       = GetNewBlobName();
            BlobSasBuilder blobSasBuilder = BuildBlobSasBuilder(includeBlob: false, includeSnapshot: false, containerName, blobName, constants);
            var            signature      = BuildIdentitySignature(includeBlob: false, includeSnapshot: false, containerName, blobName, constants);

            // Act
            BlobSasQueryParameters sasQueryParameters = blobSasBuilder.ToSasQueryParameters(GetUserDelegationKey(constants), constants.Sas.Account);

            // Assert
            Assert.AreEqual(SasQueryParametersInternals.DefaultSasVersionInternal, 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(String.Empty, sasQueryParameters.Identifier);
            Assert.AreEqual(constants.Sas.KeyObjectId, sasQueryParameters.KeyObjectId);
            Assert.AreEqual(constants.Sas.KeyTenantId, sasQueryParameters.KeyTenantId);
            Assert.AreEqual(constants.Sas.KeyStart, sasQueryParameters.KeyStartsOn);
            Assert.AreEqual(constants.Sas.KeyExpiry, sasQueryParameters.KeyExpiresOn);
            Assert.AreEqual(constants.Sas.KeyService, sasQueryParameters.KeyService);
            Assert.AreEqual(constants.Sas.KeyVersion, sasQueryParameters.KeyVersion);
            Assert.AreEqual(Constants.Sas.Resource.Container, sasQueryParameters.Resource);
            Assert.AreEqual(Permissions, sasQueryParameters.Permissions);
            Assert.AreEqual(signature, sasQueryParameters.Signature);
            AssertResponseHeaders(constants, sasQueryParameters);
        }
        public void CanGenerateSas_GetFileSystemClient()
        {
            // Arrange
            var constants               = TestConstants.Create(this);
            var uriEndpoint             = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var blobSecondaryEndpoint   = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (uriEndpoint, blobSecondaryEndpoint));

            // Act - DataLakeServiceClient(Uri blobContainerUri, BlobClientOptions options = default)
            DataLakeServiceClient serviceClient = InstrumentClient(new DataLakeServiceClient(
                                                                       uriEndpoint,
                                                                       GetOptions()));
            DataLakeFileSystemClient fileSystemClient = serviceClient.GetFileSystemClient(GetNewFileSystemName());

            Assert.IsFalse(fileSystemClient.CanGenerateSasUri);

            // Act - DataLakeServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            DataLakeServiceClient serviceClient2 = InstrumentClient(new DataLakeServiceClient(
                                                                        uriEndpoint,
                                                                        constants.Sas.SharedKeyCredential,
                                                                        GetOptions()));
            DataLakeFileSystemClient fileSystemClient2 = serviceClient2.GetFileSystemClient(GetNewFileSystemName());

            Assert.IsTrue(fileSystemClient2.CanGenerateSasUri);

            // Act - DataLakeServiceClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default)
            var tokenCredentials = new DefaultAzureCredential();
            DataLakeServiceClient serviceClient3 = InstrumentClient(new DataLakeServiceClient(
                                                                        uriEndpoint,
                                                                        tokenCredentials,
                                                                        GetOptions()));
            DataLakeFileSystemClient fileSystemClient3 = serviceClient3.GetFileSystemClient(GetNewFileSystemName());

            Assert.IsFalse(fileSystemClient3.CanGenerateSasUri);
        }
        public void GenerateSas_RequiredParameters()
        {
            // Arrange
            var    constants                      = TestConstants.Create(this);
            var    blobEndpoint                   = new Uri("http://127.0.0.1/" + constants.Sas.Account);
            var    blobSecondaryEndpoint          = new Uri("http://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString        = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint));
            string connectionString               = storageConnectionString.ToString(true);
            AccountSasPermissions   permissions   = AccountSasPermissions.Read;
            DateTimeOffset          expiresOn     = Recording.UtcNow.AddHours(+1);
            AccountSasResourceTypes resourceTypes = AccountSasResourceTypes.All;
            DataLakeServiceClient   serviceClient = InstrumentClient(new DataLakeServiceClient(
                                                                         blobEndpoint,
                                                                         constants.Sas.SharedKeyCredential, GetOptions()));

            // Act
            Uri sasUri = serviceClient.GenerateAccountSasUri(
                permissions: permissions,
                expiresOn: expiresOn,
                resourceTypes: resourceTypes);

            // Assert
            AccountSasBuilder sasBuilder  = new AccountSasBuilder(permissions, expiresOn, AccountSasServices.Blobs, resourceTypes);
            UriBuilder        expectedUri = new UriBuilder(blobEndpoint)
            {
                Query = sasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential).ToString()
            };

            Assert.AreEqual(expectedUri.Uri.ToString(), sasUri.ToString());
        }
        public void GenerateSas_RequiredParameters()
        {
            // Arrange
            var    constants      = TestConstants.Create(this);
            string fileSystemName = GetNewFileSystemName();
            string path           = GetNewFileName();
            DataLakeSasPermissions permissions = DataLakeSasPermissions.Read;
            DateTimeOffset         expiresOn   = Recording.UtcNow.AddHours(+1);
            var blobEndpoint = new Uri("http://127.0.0.1/" + constants.Sas.Account + "/" + fileSystemName + "/" + path);
            DataLakePathClient pathClient = InstrumentClient(new DataLakePathClient(
                                                                 blobEndpoint,
                                                                 constants.Sas.SharedKeyCredential,
                                                                 GetOptions()));

            // Act
            Uri sasUri = pathClient.GenerateSasUri(permissions, expiresOn);

            // Assert
            DataLakeSasBuilder sasBuilder2 = new DataLakeSasBuilder(permissions, expiresOn)
            {
                FileSystemName = fileSystemName,
                Path           = path
            };
            DataLakeUriBuilder expectedUri = new DataLakeUriBuilder(blobEndpoint)
            {
                Sas = sasBuilder2.ToSasQueryParameters(constants.Sas.SharedKeyCredential)
            };

            Assert.AreEqual(expectedUri.ToUri().ToString(), sasUri.ToString());
        }
        public void GenerateSas_BuilderIsDirectoryError()
        {
            var                    constants      = TestConstants.Create(this);
            var                    blobEndpoint   = new Uri("http://127.0.0.1/");
            UriBuilder             blobUriBuilder = new UriBuilder(blobEndpoint);
            string                 fileSystemName = GetNewFileSystemName();
            string                 fileName       = GetNewFileName();
            DataLakeSasPermissions permissions    = DataLakeSasPermissions.Read;
            DateTimeOffset         expiresOn      = Recording.UtcNow.AddHours(+1);

            blobUriBuilder.Path += constants.Sas.Account + "/" + fileSystemName + "/" + fileName;
            DataLakePathClient containerClient = InstrumentClient(new DataLakePathClient(
                                                                      blobUriBuilder.Uri,
                                                                      constants.Sas.SharedKeyCredential,
                                                                      GetOptions()));

            DataLakeSasBuilder sasBuilder = new DataLakeSasBuilder(permissions, expiresOn)
            {
                FileSystemName = fileSystemName,
                Path           = fileName,
                IsDirectory    = true,
            };

            // Act
            try
            {
                containerClient.GenerateSasUri(sasBuilder);

                Assert.Fail("DataLakeFileClient.GenerateSasUri should have failed with an ArgumentException.");
            }
            catch (InvalidOperationException)
            {
                //the correct exception came back
            }
        }
        public void CanGenerateSas_ClientConstructors()
        {
            // Arrange
            var    constants               = TestConstants.Create(this);
            var    blobEndpoint            = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var    blobSecondaryEndpoint   = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint));
            string connectionString        = storageConnectionString.ToString(true);

            // Act - DataLakePathClient(Uri blobContainerUri, BlobClientOptions options = default)
            DataLakePathClient blob3 = InstrumentClient(new DataLakePathClient(
                                                            blobEndpoint,
                                                            GetOptions()));

            Assert.IsFalse(blob3.CanGenerateSasUri);

            // Act - DataLakePathClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            DataLakePathClient blob4 = InstrumentClient(new DataLakePathClient(
                                                            blobEndpoint,
                                                            constants.Sas.SharedKeyCredential,
                                                            GetOptions()));

            Assert.IsTrue(blob4.CanGenerateSasUri);

            // Act - DataLakePathClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default)
            var tokenCredentials     = new DefaultAzureCredential();
            DataLakePathClient blob5 = InstrumentClient(new DataLakePathClient(
                                                            blobEndpoint,
                                                            tokenCredentials,
                                                            GetOptions()));

            Assert.IsFalse(blob5.CanGenerateSasUri);
        }
        public void GenerateAccountSas_RequiredParameters()
        {
            // Arrange
            TestConstants           constants     = TestConstants.Create(this);
            Uri                     serviceUri    = new Uri($"https://{constants.Sas.Account}.blob.core.windows.net");
            DateTimeOffset          expiresOn     = Recording.UtcNow.AddHours(+1);
            AccountSasPermissions   permissions   = AccountSasPermissions.Read | AccountSasPermissions.Write;
            AccountSasResourceTypes resourceTypes = AccountSasResourceTypes.All;
            BlobServiceClient       serviceClient = InstrumentClient(
                new BlobServiceClient(
                    serviceUri,
                    constants.Sas.SharedKeyCredential,
                    GetOptions()));

            // Act
            Uri sasUri = serviceClient.GenerateAccountSasUri(
                permissions: permissions,
                expiresOn: expiresOn,
                resourceTypes: resourceTypes);

            // Assert
            AccountSasBuilder sasBuilder  = new AccountSasBuilder(permissions, expiresOn, AccountSasServices.Blobs, resourceTypes);
            UriBuilder        expectedUri = new UriBuilder(serviceUri);

            expectedUri.Query += sasBuilder.ToSasQueryParameters(constants.Sas.SharedKeyCredential).ToString();
            Assert.AreEqual(expectedUri.Uri, sasUri);
        }
Пример #10
0
        public void PathClient_CanGenerateSas_GetParentDataLakeFileSystemClient()
        {
            // Arrange
            var    constants               = TestConstants.Create(this);
            var    endpoint                = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var    secondaryEndpoint       = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (endpoint, secondaryEndpoint));
            string connectionString        = storageConnectionString.ToString(true);

            // Act - BlobBaseClient(string connectionString, string blobContainerName, string blobName)
            DataLakeFileClient file = InstrumentClient(new DataLakeFileClient(
                                                           connectionString,
                                                           GetNewFileSystemName(),
                                                           $"{GetNewDirectoryName()}/{GetNewFileName()}"));
            DataLakeFileSystemClient fileSystem = file.GetParentFileSystemClient();

            Assert.IsTrue(fileSystem.CanGenerateSasUri);

            // Act - BlobBaseClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options)
            DataLakeFileClient file2 = InstrumentClient(new DataLakeFileClient(
                                                            connectionString,
                                                            GetNewFileSystemName(),
                                                            $"{GetNewDirectoryName()}/{GetNewFileName()}",
                                                            GetOptions()));
            DataLakeFileSystemClient fileSystem2 = file2.GetParentFileSystemClient();

            Assert.IsTrue(fileSystem2.CanGenerateSasUri);

            // Act - BlobBaseClient(Uri blobContainerUri, BlobClientOptions options = default)
            DataLakeFileClient file3 = InstrumentClient(new DataLakeFileClient(
                                                            endpoint,
                                                            GetOptions()));
            DataLakeFileSystemClient container3 = file3.GetParentFileSystemClient();

            Assert.IsFalse(container3.CanGenerateSasUri);

            // Act - BlobBaseClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            DataLakeFileClient file4 = InstrumentClient(new DataLakeFileClient(
                                                            endpoint,
                                                            constants.Sas.SharedKeyCredential,
                                                            GetOptions()));
            DataLakeFileSystemClient container4 = file4.GetParentFileSystemClient();

            Assert.IsTrue(container4.CanGenerateSasUri);

            // Act - BlobBaseClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default)
            var tokenCredentials     = new DefaultAzureCredential();
            DataLakeFileClient file5 = InstrumentClient(new DataLakeFileClient(
                                                            endpoint,
                                                            tokenCredentials,
                                                            GetOptions()));
            DataLakeFileSystemClient container5 = file5.GetParentFileSystemClient();

            Assert.IsFalse(container5.CanGenerateSasUri);
        }
        public void ToSasQueryParameters_NullSharedKeyCredentialTest()
        {
            // Arrange
            var            constants      = TestConstants.Create(this);
            var            containerName  = GetNewContainerName();
            var            blobName       = GetNewBlobName();
            BlobSasBuilder blobSasBuilder = BuildBlobSasBuilder(includeBlob: true, includeSnapshot: true, containerName, blobName, constants);

            // Act
            Assert.Throws <ArgumentNullException>(() => blobSasBuilder.ToSasQueryParameters(null), "sharedKeyCredential");
        }
        public void CanGenerateSas_GetContainerClient()
        {
            // Arrange
            var    constants               = TestConstants.Create(this);
            var    blobEndpoint            = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var    blobSecondaryEndpoint   = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint));
            string connectionString        = storageConnectionString.ToString(true);

            // Check if we're passing the SharedKeyCredential correctly to the containerClient
            // Act - BlobServiceClient(string connectionString)
            BlobServiceClient serviceClient = InstrumentClient(new BlobServiceClient(
                                                                   connectionString));
            BlobContainerClient containerClient = serviceClient.GetBlobContainerClient(GetNewContainerName());

            Assert.IsTrue(containerClient.CanGenerateSasUri);

            // Act - BlobServiceClient(string connectionString, string blobContainerName, BlobClientOptions options)
            BlobServiceClient serviceClient2 = InstrumentClient(new BlobServiceClient(
                                                                    connectionString,
                                                                    GetOptions()));
            BlobContainerClient containerClient2 = serviceClient2.GetBlobContainerClient(GetNewContainerName());

            Assert.IsTrue(containerClient2.CanGenerateSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, BlobClientOptions options = default)
            BlobServiceClient serviceClient3 = InstrumentClient(new BlobServiceClient(
                                                                    blobEndpoint,
                                                                    GetOptions()));
            BlobContainerClient containerClient3 = serviceClient3.GetBlobContainerClient(GetNewContainerName());

            Assert.IsFalse(containerClient3.CanGenerateSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            BlobServiceClient serviceClient4 = InstrumentClient(new BlobServiceClient(
                                                                    blobEndpoint,
                                                                    constants.Sas.SharedKeyCredential,
                                                                    GetOptions()));
            BlobContainerClient containerClient4 = serviceClient4.GetBlobContainerClient(GetNewContainerName());

            Assert.IsTrue(containerClient4.CanGenerateSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default)
            var tokenCredentials             = new DefaultAzureCredential();
            BlobServiceClient serviceClient5 = InstrumentClient(new BlobServiceClient(
                                                                    blobEndpoint,
                                                                    tokenCredentials,
                                                                    GetOptions()));
            BlobContainerClient containerClient5 = serviceClient5.GetBlobContainerClient(GetNewContainerName());

            Assert.IsFalse(containerClient5.CanGenerateSasUri);
        }
        public void CanGenerateSas_ClientConstructors()
        {
            // Arrange
            var    constants               = TestConstants.Create(this);
            var    blobEndpoint            = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var    blobSecondaryEndpoint   = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint));
            string connectionString        = storageConnectionString.ToString(true);

            // Act - BlobServiceClient(string connectionString)
            BlobServiceClient container = InstrumentClient(new BlobServiceClient(
                                                               connectionString));

            Assert.IsTrue(container.CanGenerateAccountSasUri);

            // Act - BlobServiceClient(string connectionString, string blobContainerName, BlobClientOptions options)
            BlobServiceClient container2 = InstrumentClient(new BlobServiceClient(
                                                                connectionString,
                                                                GetOptions()));

            Assert.IsTrue(container2.CanGenerateAccountSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, BlobClientOptions options = default)
            BlobServiceClient container3 = InstrumentClient(new BlobServiceClient(
                                                                blobEndpoint,
                                                                GetOptions()));

            Assert.IsFalse(container3.CanGenerateAccountSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            BlobServiceClient container4 = InstrumentClient(new BlobServiceClient(
                                                                blobEndpoint,
                                                                constants.Sas.SharedKeyCredential,
                                                                GetOptions()));

            Assert.IsTrue(container4.CanGenerateAccountSasUri);

            // Act - BlobServiceClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default)
            var tokenCredentials         = new DefaultAzureCredential();
            BlobServiceClient container5 = InstrumentClient(new BlobServiceClient(
                                                                blobEndpoint,
                                                                tokenCredentials,
                                                                GetOptions()));

            Assert.IsFalse(container5.CanGenerateAccountSasUri);
        }
Пример #14
0
        public void CanGenerateSas_GetQueueClient()
        {
            // Arrange
            var    constants               = TestConstants.Create(this);
            var    blobEndpoint            = new Uri("https://127.0.0.1/" + constants.Sas.Account);
            var    blobSecondaryEndpoint   = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary");
            var    storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, queueStorageUri: (blobEndpoint, blobSecondaryEndpoint));
            string connectionString        = storageConnectionString.ToString(true);

            // Act - QueueServiceClient(string connectionString)
            QueueServiceClient serviceClient = InstrumentClient(new QueueServiceClient(
                                                                    connectionString));
            QueueClient queueClient = serviceClient.GetQueueClient(GetNewQueueName());

            Assert.IsTrue(queueClient.CanGenerateSasUri);

            // Act - QueueServiceClient(string connectionString, string blobContainerName, BlobClientOptions options)
            QueueServiceClient serviceClient2 = InstrumentClient(new QueueServiceClient(
                                                                     connectionString,
                                                                     GetOptions()));
            QueueClient queueClient2 = serviceClient2.GetQueueClient(GetNewQueueName());

            Assert.IsTrue(queueClient2.CanGenerateSasUri);

            // Act - QueueServiceClient(Uri blobContainerUri, BlobClientOptions options = default)
            QueueServiceClient serviceClient3 = InstrumentClient(new QueueServiceClient(
                                                                     blobEndpoint,
                                                                     GetOptions()));
            QueueClient queueClient3 = serviceClient3.GetQueueClient(GetNewQueueName());

            Assert.IsFalse(queueClient3.CanGenerateSasUri);

            // Act - QueueServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default)
            QueueServiceClient serviceClient4 = InstrumentClient(new QueueServiceClient(
                                                                     blobEndpoint,
                                                                     constants.Sas.SharedKeyCredential,
                                                                     GetOptions()));
            QueueClient queueClient4 = serviceClient4.GetQueueClient(GetNewQueueName());

            Assert.IsTrue(queueClient4.CanGenerateSasUri);
        }
Пример #15
0
        public void GenerateAccountSas_WrongService_Service()
        {
            TestConstants           constants     = TestConstants.Create(this);
            Uri                     serviceUri    = new Uri($"https://{constants.Sas.Account}.queue.core.windows.net");
            AccountSasPermissions   permissions   = AccountSasPermissions.Read | AccountSasPermissions.Write;
            DateTimeOffset          expiresOn     = Recording.UtcNow.AddHours(+1);
            AccountSasServices      services      = AccountSasServices.Blobs; // Wrong Service
            AccountSasResourceTypes resourceTypes = AccountSasResourceTypes.All;
            QueueServiceClient      serviceClient = InstrumentClient(
                new QueueServiceClient(
                    serviceUri,
                    constants.Sas.SharedKeyCredential,
                    GetOptions()));

            AccountSasBuilder sasBuilder = new AccountSasBuilder(permissions, expiresOn, services, resourceTypes);

            // Act
            TestHelper.AssertExpectedException(
                () => serviceClient.GenerateAccountSasUri(sasBuilder),
                new InvalidOperationException("SAS Uri cannot be generated. builder.Services does specify Queues. builder.Services must either specify Queues or specify all Services are accessible in the value."));
        }
        public void ToSasQueryParameters_IdentifierTest()
        {
            // Arrange
            TestConstants  constants     = TestConstants.Create(this);
            string         containerName = GetNewContainerName();
            string         resource      = "c";
            BlobSasBuilder sasBuilder    = new BlobSasBuilder()
            {
                Identifier        = constants.Sas.Identifier,
                BlobContainerName = containerName,
                Protocol          = SasProtocol.Https,
                Resource          = resource,
            };

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

            // Assert
            Assert.AreEqual(constants.Sas.Identifier, sasQueryParameters.Identifier);
            Assert.AreEqual(SasProtocol.Https, sasQueryParameters.Protocol);
            Assert.AreEqual(resource, sasQueryParameters.Resource);
        }