-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test-Proxy] During recording, re-use existing request body (#5304)
* during recording, replay the body as it is exactly * add test to ensure CompressionUtilities.DecompressBinary doesn't have a secondary affect on the input array Co-authored-by: JoshLove-msft <[email protected]>
- Loading branch information
1 parent
861e768
commit 684d78b
Showing
3 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/CompressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Azure.Sdk.Tools.TestProxy.Common; | ||
using Azure.Sdk.Tools.TestProxy.Models; | ||
using Azure.Sdk.Tools.TestProxy.Sanitizers; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Azure.Sdk.Tools.TestProxy.Tests | ||
{ | ||
public class CompressionUtilityTests | ||
{ | ||
[Fact] | ||
public void EnsureDecompressionPristineBytes() | ||
{ | ||
// generate | ||
byte[] uncompressedBody = Encoding.UTF8.GetBytes("\"{\\u0022TableName\\u0022: \\u0022listtable09bf2a3d\\u0022}\""); | ||
byte[] compressedBody = CompressionUtilities.CompressBodyCore(uncompressedBody, new string[] { "gzip" }); | ||
|
||
byte[] savedCompressedBody = new byte[compressedBody.Length]; | ||
compressedBody.CopyTo(savedCompressedBody, 0); | ||
|
||
var headerDict = new HeaderDictionary(); | ||
headerDict.Add("Content-Encoding", new string[1] { "gzip" }); | ||
|
||
// intentionally testing DecompressBody vs DecompressBodyCore, as that is where the header values are intercepted and treated differently | ||
byte[] decompressedResult = CompressionUtilities.DecompressBody(compressedBody, headerDict); | ||
|
||
|
||
Assert.Equal(compressedBody, savedCompressedBody); | ||
Assert.NotEqual(decompressedResult, compressedBody); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters