Skip to content

Commit 1814567

Browse files
authored
Migrated Azure.Storage.Blobs to new generator. (Azure#18830)
1 parent 601d903 commit 1814567

File tree

2,903 files changed

+245541
-222197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,903 files changed

+245541
-222197
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text;
5+
using System.Text.RegularExpressions;
6+
using Azure.Storage.Test.Shared;
7+
8+
namespace Azure.Storage.Blobs.Batch.Tests
9+
{
10+
public class BatchStorageRecordedTestSanitizer : StorageRecordedTestSanitizer
11+
{
12+
private static Regex pattern = new Regex(@"sig=\S+\s", RegexOptions.Compiled);
13+
14+
public override byte[] SanitizeBody(string contentType, byte[] body)
15+
{
16+
if (contentType != null && contentType.Contains("multipart/mixed"))
17+
{
18+
string bodyAsString = Encoding.UTF8.GetString(body);
19+
bodyAsString = pattern.Replace(bodyAsString, "sig=Sanitized ");
20+
return Encoding.UTF8.GetBytes(bodyAsString);
21+
}
22+
else
23+
{
24+
return base.SanitizeBody(contentType, body);
25+
}
26+
}
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Text;
5+
using NUnit.Framework;
6+
7+
namespace Azure.Storage.Blobs.Batch.Tests
8+
{
9+
public class BatchStorageRecordedTestSanitizerTests
10+
{
11+
[Test]
12+
public void ShouldStripSignatureFromBody()
13+
{
14+
// Arrange
15+
var sampleBody = "DELETE /test-container/blob3?sv=2020-06-12&ss=b&srt=sco&st=2021-02-18T19%3A39%3A42Z&se=2021-02-18T21%3A39%3A42Z&sp=rwdxlacuptf&sig=abcde HTTP/1.1\r\n"
16+
+ "DELETE /test-container/blob3?sv=2020-06-12&ss=b&srt=sco&st=2021-02-18T19%3A39%3A42Z&se=2021-02-18T21%3A39%3A42Z&sp=rwdxlacuptf&sig=abcd HTTP/1.1\r\n";
17+
var expectedSanitizedBody = "DELETE /test-container/blob3?sv=2020-06-12&ss=b&srt=sco&st=2021-02-18T19%3A39%3A42Z&se=2021-02-18T21%3A39%3A42Z&sp=rwdxlacuptf&sig=Sanitized HTTP/1.1\r\n"
18+
+ "DELETE /test-container/blob3?sv=2020-06-12&ss=b&srt=sco&st=2021-02-18T19%3A39%3A42Z&se=2021-02-18T21%3A39%3A42Z&sp=rwdxlacuptf&sig=Sanitized HTTP/1.1\r\n";
19+
// Act
20+
var sanitizedBody = new BatchStorageRecordedTestSanitizer().SanitizeBody("multipart/mixed", Encoding.UTF8.GetBytes(sampleBody));
21+
22+
// Assert
23+
Assert.AreEqual(expectedSanitizedBody, Encoding.UTF8.GetString(sanitizedBody));
24+
}
25+
}
26+
}

sdk/storage/Azure.Storage.Blobs.Batch/tests/BlobBatchClientTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.InteropServices;
99
using System.Threading.Tasks;
1010
using Azure.Core.TestFramework;
11+
using Azure.Storage.Blobs.Batch.Tests;
1112
using Azure.Storage.Blobs.Models;
1213
using Azure.Storage.Blobs.Specialized;
1314
using Azure.Storage.Sas;
@@ -25,6 +26,7 @@ public BlobBatchClientTests(bool async, BlobClientOptions.ServiceVersion service
2526
{
2627
// Batch delimiters are random so disable body comparison
2728
Matcher = new RecordMatcher(compareBodies: false);
29+
Sanitizer = new BatchStorageRecordedTestSanitizer();
2830
}
2931

3032
[SetUp]

0 commit comments

Comments
 (0)