Skip to content

Commit

Permalink
Enable telemetry: allowInsecureConnections and `disableTLSCertifica…
Browse files Browse the repository at this point in the history
…eValidation` properties (#6244)
  • Loading branch information
Nigusu-Allehu authored Jan 31, 2025
1 parent 4ccad76 commit ee7086f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private static TelemetryEvent GetSourceSummaryEvent(
var dotnetCuratedFeed = false;
var httpsV2 = 0;
var httpsV3 = 0;
int allowInsecureConnections = 0;
int disableTLSCertificateValidation = 0;

if (packageSources != null)
{
Expand All @@ -85,6 +87,18 @@ private static TelemetryEvent GetSourceSummaryEvent(
if (source.IsHttps)
{
httpsV3++;

if (source.DisableTLSCertificateValidation)
{
disableTLSCertificateValidation++;
}
}
else
{
if (source.AllowInsecureConnections)
{
allowInsecureConnections++;
}
}

if (UriUtility.IsNuGetOrg(source.Source))
Expand All @@ -100,6 +114,18 @@ private static TelemetryEvent GetSourceSummaryEvent(
if (source.IsHttps)
{
httpsV2++;

if (source.DisableTLSCertificateValidation)
{
disableTLSCertificateValidation++;
}
}
else
{
if (source.AllowInsecureConnections)
{
allowInsecureConnections++;
}
}

if (UriUtility.IsNuGetOrg(source.Source))
Expand Down Expand Up @@ -142,7 +168,9 @@ private static TelemetryEvent GetSourceSummaryEvent(
dotnetCuratedFeed,
protocolDiagnosticTotals,
httpsV2,
httpsV3);
httpsV3,
allowInsecureConnections,
disableTLSCertificateValidation);
}

/// <summary>
Expand Down Expand Up @@ -172,14 +200,18 @@ public SourceSummaryTelemetryEvent(
bool dotnetCuratedFeed,
PackageSourceTelemetry.Totals protocolDiagnosticTotals,
int httpsV2,
int httpsV3)
int httpsV3,
int allowInsecureConnections,
int disableTLSCertificateValidation)
: base(eventName)
{
this["NumLocalFeeds"] = local;
this["NumHTTPv2Feeds"] = httpV2;
this["NumHTTPv3Feeds"] = httpV3;
this["NumHTTPSv2Feeds"] = httpsV2;
this["NumHTTPSv3Feeds"] = httpsV3;
this["NumHTTPNotSecureFeedsThatAllowInsecureConnections"] = allowInsecureConnections;
this["NumHTTPSFeedsThatDisableTLSCertificateValidation"] = disableTLSCertificateValidation;
this["NuGetOrg"] = nugetOrg;
this["VsOfflinePackages"] = vsOfflinePackages;
this["DotnetCuratedFeed"] = dotnetCuratedFeed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class SourceTelemetryTests
private const string ProtocolDuration = "protocol.duration";
private const string NumHTTPSv2Feeds = "NumHTTPSv2Feeds";
private const string NumHTTPSv3Feeds = "NumHTTPSv3Feeds";
private const string AllowInsecureConnections = "NumHTTPNotSecureFeedsThatAllowInsecureConnections";
private const string DisableTLSCertificateValidation = "NumHTTPSFeedsThatDisableTLSCertificateValidation";

private static readonly Guid Parent = Guid.Parse("33411664-388A-4C48-A607-A2C554171FCE");
private static readonly PackageSourceTelemetry.Totals ProtocolDiagnosticTotals = new PackageSourceTelemetry.Totals(1, 2, TimeSpan.FromMilliseconds(3), numberOfSourcesWithAnHttpResource: 0);
Expand Down Expand Up @@ -473,6 +475,38 @@ public void LocalAndHttpSources_WithHTTPSv2Feeds_FeedCountsAreCorrect()
totalFeeds.Should().Be(sources.Count);
}

[Fact]
public void HttpSources_WithAllowInsecureConnectionsAndDisableTlsCertificateValidation_FeedCountsAreCorrect()
{
PackageSource source1 = new PackageSource("http://test");
source1.AllowInsecureConnections = true;
PackageSource source2 = new PackageSource("http://test2/v3/index.json");
source2.AllowInsecureConnections = true;
PackageSource source3 = new PackageSource("http://test3");
source3.AllowInsecureConnections = false;
PackageSource source4 = new PackageSource("https://test3");
source4.AllowInsecureConnections = false;
source4.DisableTLSCertificateValidation = true;


var sources = new List<PackageSource>()
{
source1,
source2,
source3,
source4
};

var summary = SourceTelemetry.GetRestoreSourceSummaryEvent(Parent, sources, ProtocolDiagnosticTotals);
var summaryInts = GetValuesAsInts(summary);

int? numHTTPSFeedsThatDisableTLSCertificateValidation = summaryInts[DisableTLSCertificateValidation];
int? numHTTPNotSecureFeedsThatAllowInsecureConnections = summaryInts[AllowInsecureConnections];

numHTTPSFeedsThatDisableTLSCertificateValidation.Should().Be(1);
numHTTPNotSecureFeedsThatAllowInsecureConnections.Should().Be(2);
}

[Fact]
public void LocalAndHttpSources_WithHTTPSv3Feeds_FeedCountsAreCorrect()
{
Expand Down

0 comments on commit ee7086f

Please sign in to comment.