Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Storage Client CanGenerateSasUri properties mockable #18277

Merged
merged 3 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.9.0-beta.1 (Unreleased)

- Fixed bug where BlobBaseClient.CanGenerateSasUri, BlobContainerClient.CanGenerateSasUri, BlobServiceClient.CanGenerateSasUri was not mockable

## 12.8.0 (2021-01-12)
- Includes all features from 12.8.0-beta.1
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctor
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public string AccountName
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateAccountSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateAccountSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Azure.Storage.Blobs.Models
{
/// <summary>
/// Propeties of a Blob
/// Properties of a Blob
/// </summary>
public partial class BlobProperties
{
Expand Down
32 changes: 32 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6051,6 +6051,38 @@ public void CanGenerateSas_WithVersion_False()
Assert.IsFalse(versionBlob.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account);

// Act
var blob = new Mock<BlobBaseClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(blob.Object.CanGenerateSasUri);
amnguye marked this conversation as resolved.
Show resolved Hide resolved

// Arrange
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
var blob2 = new Mock<BlobBaseClient>(connectionString,
GetNewContainerName(),
GetNewBlobName())
{
CallBase = true
};

// Assert
Assert.IsTrue(blob2.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
31 changes: 31 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,37 @@ public void CanGenerateSas_ClientConstructors()
Assert.IsFalse(container5.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account);

// Act
var container = new Mock<BlobContainerClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(container.Object.CanGenerateSasUri);

// Arrange
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
var container2 = new Mock<BlobContainerClient>(connectionString,
GetNewContainerName())
{
CallBase = true
};

// Assert
Assert.IsTrue(container2.Object.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_GetBlobClient()
{
Expand Down
30 changes: 30 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,36 @@ public void CanGenerateSas_GetContainerClient()
Assert.IsFalse(containerClient5.CanGenerateSasUri);
}

[Test]
public void CanGenerateAccountSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account);

// Act
var service = new Mock<BlobServiceClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(service.Object.CanGenerateAccountSasUri);

// Arrange
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
var service2 = new Mock<BlobServiceClient>(connectionString)
{
CallBase = true
};

// Assert
Assert.IsTrue(service2.Object.CanGenerateAccountSasUri);
}

[Test]
public void GenerateAccountSas_RequiredParameters()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.7.0-beta.1 (Unreleased)

- Fixed bug where DataLakeFileSystemClient.CanGenerateSasUri, DataLakeDirectoryClient.CanGenerateSasUri, DataLakeFileClient.CanGenerateSasUri, DataLakePathClient.CanGenerateSasUri, DataLakeServiceClient.CanGenerateSasUri was not mockable

## 12.6.0 (2021-01-12)
- Includes all features from 12.6.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Azure.Storage.Files.DataLake
public class DataLakeFileClient : DataLakePathClient
{
/// <summary>
/// Gets the maximum number of bytes that can be sent in a call
/// Gets the maximum number of bytes that can be sent in each append call in
/// to <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// Supported value is now larger than <see cref="int.MaxValue"/>; please use
/// <see cref="MaxUploadLongBytes"/>.
Expand All @@ -37,8 +37,8 @@ public class DataLakeFileClient : DataLakePathClient
: int.MaxValue; // value is larger than can be represented by an int

/// <summary>
/// Gets the maximum number of bytes that can be sent in a call
/// to <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// Gets the maximum number of bytes that can be sent in each append call in
/// <see cref="UploadAsync(Stream, PathHttpHeaders, DataLakeRequestConditions, IProgress{long}, StorageTransferOptions, CancellationToken)"/>.
/// </summary>
public virtual long MaxUploadLongBytes => Version < DataLakeClientOptions.ServiceVersion.V2019_12_12
? Constants.DataLake.Pre_2019_12_12_MaxAppendBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public virtual string Name
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public virtual string AccountName
/// Determines whether the client is able to generate a SAS.
/// If the client is authenticated with a <see cref="StorageSharedKeyCredential"/>.
/// </summary>
public bool CanGenerateAccountSasUri => SharedKeyCredential != null;
public virtual bool CanGenerateAccountSasUri => SharedKeyCredential != null;

#region ctors
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5087,6 +5087,35 @@ public void CanGenerateSas_GetSubDirectoryClient()
Assert.IsFalse(subdirectory3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
string fileSystemName = GetNewFileSystemName();
string path = GetNewDirectoryName();
var blobEndpoint = new Uri("http://127.0.0.1/" + constants.Sas.Account + "/" + fileSystemName + "/" + path);

// Act
var directory = new Mock<DataLakeDirectoryClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(directory.Object.CanGenerateSasUri);

// Act
var directory2 = new Mock<DataLakeDirectoryClient>(blobEndpoint,
constants.Sas.SharedKeyCredential,
GetOptions())
{
CallBase = true
};

// Assert
Assert.IsTrue(directory2.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
29 changes: 29 additions & 0 deletions sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,35 @@ public void CanGenerateSas_ClientConstructors()
Assert.IsFalse(file3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
string fileSystemName = GetNewFileSystemName();
string path = GetNewFileName();
var blobEndpoint = new Uri("http://127.0.0.1/" + constants.Sas.Account + "/" + fileSystemName + "/" + path);

// Act
var file = new Mock<DataLakeFileClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(file.Object.CanGenerateSasUri);

// Act
var file2 = new Mock<DataLakeFileClient>(blobEndpoint,
constants.Sas.SharedKeyCredential,
GetOptions())
{
CallBase = true
};

// Assert
Assert.IsTrue(file2.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,33 @@ public void CanGenerateSas_GetDirectoryClient()
Assert.IsFalse(directory3.CanGenerateSasUri);
}

[Test]
public void CanGenerateSas_Mockable()
{
// Arrange
var constants = new TestConstants(this);
var blobEndpoint = new Uri("http://127.0.0.1/" + constants.Sas.Account);

// Act
var filesystem = new Mock<DataLakeFileSystemClient>(blobEndpoint, GetOptions())
{
CallBase = true
};
// Assert
Assert.IsFalse(filesystem.Object.CanGenerateSasUri);

// Act
var filesystem2 = new Mock<DataLakeFileSystemClient>(blobEndpoint,
constants.Sas.SharedKeyCredential,
GetOptions())
{
CallBase = true
};

// Assert
Assert.IsTrue(filesystem2.Object.CanGenerateSasUri);
}

[Test]
public void GenerateSas_RequiredParameters()
{
Expand Down
Loading