Skip to content

Commit

Permalink
Removed Entra App Secrets from Storage tests (#44427)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcc-msft authored Jul 12, 2024
1 parent c44f2c2 commit dd1b7fc
Show file tree
Hide file tree
Showing 73 changed files with 602 additions and 654 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs.Batch/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.Blobs.Batch",
"Tag": "net/storage/Azure.Storage.Blobs.Batch_34b0b578dc"
"Tag": "net/storage/Azure.Storage.Blobs.Batch_91b5e838a2"
}
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs.ChangeFeed/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.Blobs.ChangeFeed",
"Tag": "net/storage/Azure.Storage.Blobs.ChangeFeed_198f5277c7"
"Tag": "net/storage/Azure.Storage.Blobs.ChangeFeed_83537f1c55"
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<DisposingContainer> GetTestContainerAsync(

if (publicAccessType == default)
{
publicAccessType = premium ? PublicAccessType.None : PublicAccessType.BlobContainer;
publicAccessType = PublicAccessType.None;
}

BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(containerName));
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/storage/Azure.Storage.Blobs",
"Tag": "net/storage/Azure.Storage.Blobs_62a8c8fa29"
"Tag": "net/storage/Azure.Storage.Blobs_b8e4c4ca1e"
}
68 changes: 27 additions & 41 deletions sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Ctor_TokenAuth_Http()

// Act
TestHelper.AssertExpectedException(
() => new AppendBlobClient(httpUri, Tenants.GetOAuthCredential()),
() => new AppendBlobClient(httpUri, TestEnvironment.Credential),
new ArgumentException("Cannot use TokenCredential without HTTPS."));
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public async Task Ctor_DefaultAudience()

AppendBlobClient aadBlob = InstrumentClient(new AppendBlobClient(
uriBuilder.ToUri(),
Tenants.GetOAuthCredential(),
TestEnvironment.Credential,
options));

// Assert
Expand All @@ -185,6 +185,7 @@ public async Task Ctor_DefaultAudience()
}

[RecordedTest]
[PlaybackOnly("https://github.com/Azure/azure-sdk-for-net/issues/44967")]
public async Task Ctor_CustomAudience()
{
// Arrange
Expand All @@ -204,7 +205,7 @@ public async Task Ctor_CustomAudience()

AppendBlobClient aadBlob = InstrumentClient(new AppendBlobClient(
uriBuilder.ToUri(),
Tenants.GetOAuthCredential(),
TestEnvironment.Credential,
options));

// Assert
Expand All @@ -213,6 +214,7 @@ public async Task Ctor_CustomAudience()
}

[RecordedTest]
[PlaybackOnly("https://github.com/Azure/azure-sdk-for-net/issues/44967")]
public async Task Ctor_StorageAccountAudience()
{
// Arrange
Expand All @@ -232,7 +234,7 @@ public async Task Ctor_StorageAccountAudience()

AppendBlobClient aadBlob = InstrumentClient(new AppendBlobClient(
uriBuilder.ToUri(),
Tenants.GetOAuthCredential(),
TestEnvironment.Credential,
options));

// Assert
Expand Down Expand Up @@ -575,7 +577,7 @@ public async Task CreateAsync_EncryptionScopeAccountSAS()
public async Task CreateAsync_EncryptionScopeIdentitySAS()
{
// Arrange
BlobServiceClient oauthService = BlobsClientBuilder.GetServiceClient_OAuth();
BlobServiceClient oauthService = BlobsClientBuilder.GetServiceClient_OAuth(TestEnvironment.Credential);
await using DisposingContainer test = await GetTestContainerAsync(oauthService);

Response<UserDelegationKey> userDelegationKey = await oauthService.GetUserDelegationKeyAsync(
Expand Down Expand Up @@ -1291,8 +1293,6 @@ public async Task AppendBlockFromUriAsync_Min()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1310,7 +1310,9 @@ public async Task AppendBlockFromUriAsync_Min()
};

// Act
Response<BlobAppendInfo> response = await destBlob.AppendBlockFromUriAsync(sourceBlob.Uri, options);
Response<BlobAppendInfo> response = await destBlob.AppendBlockFromUriAsync(
sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options);

// Ensure that we grab the whole ETag value from the service without removing the quotes
Assert.AreEqual(response.Value.ETag.ToString(), $"\"{response.GetRawResponse().Headers.ETag}\"");
Expand Down Expand Up @@ -1428,8 +1430,6 @@ public async Task AppendBlockFromUriAsync_EncryptionScope()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1449,7 +1449,7 @@ public async Task AppendBlockFromUriAsync_EncryptionScope()

// Act
Response<BlobAppendInfo> response = await destBlob.AppendBlockFromUriAsync(
sourceBlob.Uri,
sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options);

Assert.AreEqual(TestConfigDefault.EncryptionScope, response.Value.EncryptionScope);
Expand All @@ -1462,8 +1462,6 @@ public async Task AppendBlockFromUriAsync_Range()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(4 * Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1482,7 +1480,7 @@ public async Task AppendBlockFromUriAsync_Range()

// Act
await destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options);

// Assert
Expand All @@ -1500,8 +1498,6 @@ public async Task AppendBlockFromUriAsync_MD5()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1520,7 +1516,7 @@ public async Task AppendBlockFromUriAsync_MD5()

// Act
await destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options);
}
}
Expand All @@ -1531,8 +1527,6 @@ public async Task AppendBlockFromUriAsync_MD5_Fail()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1552,7 +1546,7 @@ public async Task AppendBlockFromUriAsync_MD5_Fail()
// Act
await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options),
actualException => Assert.AreEqual("Md5Mismatch", actualException.ErrorCode)
);
Expand Down Expand Up @@ -1583,8 +1577,6 @@ public async Task AppendBlockFromUriAsync_AccessConditions()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(7);

using (var stream = new MemoryStream(data))
Expand Down Expand Up @@ -1614,7 +1606,7 @@ public async Task AppendBlockFromUriAsync_AccessConditions()

// Act
await destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options);
}
}
Expand Down Expand Up @@ -1643,8 +1635,6 @@ public async Task AppendBlockFromUriAsync_AccessConditionsFail()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(7);

using (var stream = new MemoryStream(data))
Expand Down Expand Up @@ -1674,7 +1664,7 @@ public async Task AppendBlockFromUriAsync_AccessConditionsFail()
// Act
await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options),
actualException => Assert.IsTrue(true)
);
Expand All @@ -1689,8 +1679,6 @@ public async Task AppendBlockFromUriAsync_IfTags()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using Stream stream = new MemoryStream(data);
Expand Down Expand Up @@ -1721,7 +1709,7 @@ public async Task AppendBlockFromUriAsync_IfTags()

// Act
await destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options);
}

Expand All @@ -1732,8 +1720,6 @@ public async Task AppendBlockFromUriAsync_IfTagsFailed()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using Stream stream = new MemoryStream(data);
Expand All @@ -1759,19 +1745,20 @@ public async Task AppendBlockFromUriAsync_IfTagsFailed()
// Act
await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options),
e => Assert.AreEqual("ConditionNotMet", e.ErrorCode));
}

[RecordedTest]
// Net462 is sending the source SAS expiry unencoded to the service, while net6 and net7 sending it encoded.
// Both are valid, but make this test non-recordable.
[LiveOnly]
public async Task AppendBlockFromUriAsync_NonAsciiSourceUri()
{
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1790,7 +1777,7 @@ public async Task AppendBlockFromUriAsync_NonAsciiSourceUri()

// Act
await destBlob.AppendBlockFromUriAsync(
sourceUri: sourceBlob.Uri,
sourceUri: sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)),
options: options);
}
}
Expand All @@ -1801,7 +1788,7 @@ await destBlob.AppendBlockFromUriAsync(
public async Task AppendBlockFromUriAsync_SourceBearerToken()
{
// Arrange
BlobServiceClient serviceClient = BlobsClientBuilder.GetServiceClient_OAuth();
BlobServiceClient serviceClient = GetServiceClient_OAuth();
await using DisposingContainer test = await GetTestContainerAsync(
service: serviceClient,
publicAccessType: PublicAccessType.None);
Expand Down Expand Up @@ -1836,7 +1823,7 @@ public async Task AppendBlockFromUriAsync_SourceBearerToken()
public async Task AppendBlockFromUriAsync_SourceBearerTokenFail()
{
// Arrange
BlobServiceClient serviceClient = BlobsClientBuilder.GetServiceClient_OAuth();
BlobServiceClient serviceClient = GetServiceClient_OAuth();
await using DisposingContainer test = await GetTestContainerAsync(
service: serviceClient,
publicAccessType: PublicAccessType.None);
Expand Down Expand Up @@ -1874,8 +1861,6 @@ public async Task AppendBlockFromUriAsync_NullOptions()
await using DisposingContainer test = await GetTestContainerAsync();

// Arrange
await test.Container.SetAccessPolicyAsync(PublicAccessType.BlobContainer);

var data = GetRandomBuffer(Constants.KB);

using (var stream = new MemoryStream(data))
Expand All @@ -1888,7 +1873,8 @@ public async Task AppendBlockFromUriAsync_NullOptions()
await destBlob.CreateIfNotExistsAsync();

// Act
Response<BlobAppendInfo> response = await destBlob.AppendBlockFromUriAsync(sourceBlob.Uri);
Response<BlobAppendInfo> response = await destBlob.AppendBlockFromUriAsync(
sourceBlob.GenerateSasUri(BlobSasPermissions.Read, Recording.UtcNow.AddHours(1)));

// Ensure that we grab the whole ETag value from the service without removing the quotes
Assert.AreEqual(response.Value.ETag.ToString(), $"\"{response.GetRawResponse().Headers.ETag}\"");
Expand Down Expand Up @@ -2146,7 +2132,7 @@ public void CanMockClientConstructors()
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), new BlobClientOptions()).Object;
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), Tenants.GetNewSharedKeyCredentials(), new BlobClientOptions()).Object;
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), new AzureSasCredential("foo"), new BlobClientOptions()).Object;
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), Tenants.GetOAuthCredential(Tenants.TestConfigHierarchicalNamespace), new BlobClientOptions()).Object;
mock = new Mock<AppendBlobClient>(new Uri("https://test/test"), TestEnvironment.Credential, new BlobClientOptions()).Object;
}

private AppendBlobRequestConditions BuildDestinationAccessConditions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\Azure.Storage.Blobs.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Common\src\Azure.Storage.Common.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.Storage.Blobs.Batch\src\Azure.Storage.Blobs.Batch.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Azure.Management.Storage\src\Microsoft.Azure.Management.Storage.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Azure.ResourceManager.Storage\src\Azure.ResourceManager.Storage.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(AzureStorageSharedTestSources)\**\*.cs" LinkBase="Shared" />
Expand Down
Loading

0 comments on commit dd1b7fc

Please sign in to comment.