Skip to content

Commit

Permalink
Adding Unit Test and Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MantavyaDh committed Dec 24, 2024
1 parent b0597f4 commit ac20c16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Agent.Sdk/Util/VssUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static bool IsCustomServerCertificateValidationSupported(ITraceWriter tra
return true;
}

// The function is to check if the custom server certificate validation is supported on the current platform.
private static bool CheckSupportOfCustomServerCertificateValidation(ITraceWriter trace)
{
using (var handler = new HttpClientHandler())
Expand All @@ -175,10 +176,11 @@ private static bool CheckSupportOfCustomServerCertificateValidation(ITraceWriter
try
{
client.GetAsync(_testUri).GetAwaiter().GetResult();
trace.Verbose("Custom Server Validation Callback Successful, SSL diagnostic data collection is enabled.");
}
catch (Exception e)
{
trace.Verbose($"SSL diagnostic data collection is disabled, due to issue:\n{e.Message}");
trace.Verbose($"Custom Server Validation Callback Unsuccessful, SSL diagnostic data collection is disabled, due to issue:\n{e.Message}");
return false;
}
return true;
Expand Down
33 changes: 33 additions & 0 deletions src/Test/L0/Util/VssUtilL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,38 @@ public void VerifyOverwriteVssConnectionSetting()
}
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void VerifyVSSConnectionUsingLegacyHandler()
{
Regex _serverSideAgentPlatformMatchingRegex = new Regex("vstsagentcore-(.+)(?=/)", RegexOptions.Compiled | RegexOptions.IgnoreCase);

using (TestHostContext hc = new TestHostContext(this))
{
Tracing trace = hc.GetTrace();
// Act.
try
{
Environment.SetEnvironmentVariable("AZP_AGENT_USE_LEGACY_HTTP", "true");

var exception = Record.Exception(() =>
{
var connection = VssUtil.CreateConnection(
new Uri("https://github.com/Microsoft/vsts-agent"),
new VssCredentials(),
trace);
});

Assert.Null(exception);
}
finally
{
Environment.SetEnvironmentVariable("AZP_AGENT_USE_LEGACY_HTTP", "");
}
}

}
}
}

0 comments on commit ac20c16

Please sign in to comment.