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

Adding Support to override the ClientRequestID guid format for test recording sessions. #39133

Merged
merged 13 commits into from
Oct 9, 2023
13 changes: 11 additions & 2 deletions sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ProxyTransport : HttpPipelineTransport
private readonly TestRecording _recording;
private readonly TestProxy _proxy;
private readonly bool _isWebRequestTransport;
private readonly bool _useDefaultClientIDFormat;

private const string DevCertIssuer = "CN=localhost";
private const string FiddlerCertIssuer = "CN=DO_NOT_TRUST_FiddlerRoot, O=DO_NOT_TRUST, OU=Created by http://www.fiddler2.com";
Expand All @@ -34,6 +35,7 @@ public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestReco
_filter = filter;

bool useFiddler = TestEnvironment.EnableFiddler;
_useDefaultClientIDFormat = TestEnvironment.DefaultClientGuidFormatInRecording;
wiboris marked this conversation as resolved.
Show resolved Hide resolved
string certIssuer = useFiddler ? FiddlerCertIssuer : DevCertIssuer;
_proxyHost = useFiddler ? "ipv4.fiddler" : TestProxy.IpAddress;

Expand Down Expand Up @@ -135,8 +137,15 @@ public override Request CreateRequest()
_recording.HasRequests = true;
lock (_recording.Random)
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
if (_useDefaultClientIDFormat)
{
// User want the client format to use the default format
request.ClientRequestId = _recording.Random.NewGuid().ToString();
}else
wiboris marked this conversation as resolved.
Show resolved Hide resolved
{
// Make sure ClientRequestId are the same across request and response
request.ClientRequestId = _recording.Random.NewGuid().ToString("N");
}
}
return request;
}
Expand Down
14 changes: 14 additions & 0 deletions sdk/core/Azure.Core.TestFramework/src/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,20 @@ internal static string GetSourcePath(Assembly assembly)
/// </summary>
public static bool GlobalIsRunningInCI => Environment.GetEnvironmentVariable("TF_BUILD") != null;

/// <summary>
/// Determines if during test recording if we should use the default guid format for clientID.
/// </summary>
public static bool DefaultClientGuidFormatInRecording
{
get
{
string guidDefaultFormat = Environment.GetEnvironmentVariable("RECORDING_DEFAULT_ClIENT_GUID");

bool.TryParse(guidDefaultFormat, out bool enableDefaultGuidFormat);

return enableDefaultGuidFormat;
}
}
/// <summary>
/// Determines if the current global test mode.
/// </summary>
Expand Down