Skip to content

Commit

Permalink
Do not show warning icons for HTTP sources in VS Options when allowIn…
Browse files Browse the repository at this point in the history
…secureConnections is true (#5399)
  • Loading branch information
heng-liu committed Sep 8, 2023
1 parent 9014d80 commit 7c6c3e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override AccessibleObject GetChild(int index)
{
var item = (PackageSourceContextInfo)CheckedListBox.Items[index];
PackageSource packageSource = new PackageSource(item.Source, item.Name);
if (packageSource.IsHttp && !packageSource.IsHttps)
if (packageSource.IsHttp && !packageSource.IsHttps && !packageSource.AllowInsecureConnections)
{
var sourceMessage = string.Concat(
Resources.Warning_HTTPSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ protected override void OnDrawItem(DrawItemEventArgs e)
graphics.DrawString(currentItem.Name, e.Font, foreBrush, nameBounds, drawFormat);

var packageSource = new PackageSource(currentItem.Source, currentItem.Name);
var isSourceHttp = packageSource.IsHttp && !packageSource.IsHttps;
packageSource.AllowInsecureConnections = currentItem.AllowInsecureConnections;
var shouldShowHttpWarningIcon = packageSource.IsHttp && !packageSource.IsHttps && !packageSource.AllowInsecureConnections;
Rectangle warningBounds = default;

if (isSourceHttp)
if (shouldShowHttpWarningIcon)
{
var warningIcon = GetWarningIcon();

Expand All @@ -152,7 +153,7 @@ protected override void OnDrawItem(DrawItemEventArgs e)
}

var sourceBounds = new Rectangle(
isSourceHttp ? warningBounds.Right : nameBounds.Left,
shouldShowHttpWarningIcon ? warningBounds.Right : nameBounds.Left,
nameBounds.Bottom,
textWidth,
e.Bounds.Bottom - nameBounds.Bottom);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ private void UpdateUI()
// Always enable addButton for PackageSourceListBox
addButton.Enabled = true;
}

// Show HttpWarning for the selected source if needed
if (selectedSource != null)
{
SetHttpWarningVisibilityForSelectSource(selectedSource);
}
else if (selectedMachineSource != null)
{
SetHttpWarningVisibilityForSelectSource(selectedMachineSource);
}
}

internal async Task InitializeOnActivatedAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -477,6 +487,8 @@ private TryUpdateSourceResults TryUpdateSource()
selectedPackageSource.Source = source;
_packageSources.ResetCurrentItem();

SetHttpWarningVisibilityForSelectSource(selectedPackageSource);

return TryUpdateSourceResults.Successful;
}

Expand Down Expand Up @@ -703,12 +715,13 @@ private static bool IsPathRootedSafe(string path)
return path.IndexOfAny(Path.GetInvalidPathChars()) == -1 && Path.IsPathRooted(path);
}

private void NewPackageSource_TextChanged(object sender, EventArgs e)
private void SetHttpWarningVisibilityForSelectSource(PackageSourceContextInfo selectedSource)
{
var source = new PackageSource(NewPackageSource.Text.Trim(), NewPackageName.Text.Trim());
var source = new PackageSource(selectedSource.Source, selectedSource.Name);
source.AllowInsecureConnections = selectedSource.AllowInsecureConnections;

// Warn if the source is http, support for this will be removed
if (source.IsHttp && !source.IsHttps)
// Warn if the selected source is http, and the AllowInsecureConnections for this source is set to false.
if (source.IsHttp && !source.IsHttps && !source.AllowInsecureConnections)
{
HttpWarning.Visible = true;
HttpWarningIcon.Visible = true;
Expand Down

0 comments on commit 7c6c3e3

Please sign in to comment.