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

Opt out Https everywhere in packages.config restore scenarios in all NuGet tools #5356

Conversation

heng-liu
Copy link
Contributor

@heng-liu heng-liu commented Aug 11, 2023

Bug

Fixes:NuGet/Home#12788

Regression? Last working version:

Description

When allowInsecureConnections property in packageSources section is set to true in NuGet.Config files, suppress warnings for HTTP sources in packages.config restore scenarios(including install and update) in all NuGet tools.

The PRs enable the HTTP warnings in those scenarios are:
#4583
#4633

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@heng-liu heng-liu requested a review from a team as a code owner August 11, 2023 22:20
[Theory]
[InlineData("true")]
[InlineData("TRUE")]
public async Task UpdateCommand_WithHttpSourceAndTrueAllowInsecureConnections_NoWarns(string allowInsecureConnections)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the following test look mostly the same. In an effort to dedupe code, you could have one test that parameterizes this. Also consider this feedback elsewhere.

[Theory]
[InlineData("true", true])
[InlineData("TRUE", true])
[InlineData("false", false])
[InlineData("FALSE", false])
[InlineData("invalid", false])
...
public async Task UpdateCommand_WhenAllowInsecureConnectionsIsSet_WarnsAppropriately(string allowInsecureConnectionsValue, bool allowInsecureConnectionsValue)
{
    ...

    const string warning = "You are running the 'update' operation with an 'http' source";

    if (allowInsecureConnections)
    {
        r.AllOutput.Should().NotContain(warning, because: r.AllOutput);
    }
    else
    {
        r.AllOutput.Should().Contain(warning, because: r.AllOutput);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dtivel ! There are also comments suggesting differently: #5343 (comment)
So I think people might have different preferences.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't view it as a difference in preferences. The spirit of the comment is to deduplicate code.

I showed one path to deduplication. Even with the other approach, which is also fine, you can still deduplicate code by extracting reusable code into helper methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what @dtivel suggested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point I was making in the comment you linked is that Setup had many branches, making it hard to understand the path to a test failure. I think the proposal here is to extract setup helper methods, which is OK to consider, and a different topic, really. I did this in my recent PR (eg, SetupUIServiceWithPackageSearchMetadata) which had MUCH more complicated Setup, .so it's hard to say it's needed in your PR.

Another viewpoint I don't see in this thread, but which has been expressed in my PR reviews, is that deduping a few lines of code isn't necessarily making it easier for the reader. There's a bit of an art to it.

I'd say spend just a little effort (<30 minutes?) to see if you can extract methods that saves more than 3-4 lines or so per test. Sometimes you need to return objects and pass them around, and end up with nearly the same setup code. Given, there are 1000+ lines of tests in this file with far more complicated duplicated code, we may want to separately come up with a guideline as a Team, then apply that decision to new tests, and refactor old tests.

Copy link
Contributor Author

@heng-liu heng-liu Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it would be good to have a guideline as a Team so we will have a consistent standard to follow.
Otherwise, we will have to keep addressing different comments and that is not efficient.
There are many existing tests have the same setup without deduplication: RestoreCommand_VerifyMinClientVersionV2SourceAsync and RestoreCommand_VerifyMinClientVersionV3SourceAsync
So it's not clear when shall we deduplicate code and when shall we keep duplicate code to make test easy to understand.

@heng-liu heng-liu force-pushed the dev-hengliu-optoutHttpWarning-packagesConfigRestore branch from f4b8f9f to 324c440 Compare August 15, 2023 22:27
@heng-liu
Copy link
Contributor Author

Thanks all for reviewing!
All comments are addressed. Could you please review it again? Thanks!

@@ -430,6 +430,7 @@
<comment>{0} - package id</comment>
</data>
<data name="Warning_HttpServerUsage" xml:space="preserve">
<value>You are running the '{0}' operation with an 'http' source, '{1}'. Support for 'http' sources will be removed in a future version.</value>
<value>You are running the '{0}' operation with an 'HTTP' source, '{1}'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this aligns to the new plan. You should check with @JonDouglas on what the message should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aortiz-msft ! There are 5 Warning_HttpServerUsage in our codebase: https://github.com/search?q=repo%3ANuGet%2FNuGet.Client%20name%3D%22Warning_HttpServerUsage%22&type=code
And only one of the 5 is different. That's why I made this change to make all of them the same.
Hi @JonDouglas , could you help advise if this change is needed? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aortiz-msft could you point reviewers to what plan you're referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Theory]
[InlineData("true")]
[InlineData("TRUE")]
public async Task UpdateCommand_WithHttpSourceAndTrueAllowInsecureConnections_NoWarns(string allowInsecureConnections)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what @dtivel suggested.

@heng-liu heng-liu requested a review from aortiz-msft August 16, 2023 14:54
[InlineData("", true)]
[InlineData("true", false)]
[InlineData("TRUE", false)]
public async Task Restore_WithHttpSourceAndFalseAllowInsecureConnections_WarnsCorrectly(string allowInsecureConnections, bool hasHttpWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: isHttpWarningExpected?

[InlineData("", true)]
[InlineData("true", false)]
[InlineData("TRUE", false)]
public async Task UpdateCommand_WithHttpSourceAndAllowInsecureConnections_WarnsCorrectly(string allowInsecureConnections, bool hasHttpWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

[InlineData("", true)]
[InlineData("true", false)]
[InlineData("TRUE", false)]
public async Task MsbuildRestore_PackagesConfigDependency_WithHttpSourceAndAllowInsecureConnections_WarnsCorrectly(string allowInsecureConnections, bool hasHttpWarning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor

@aortiz-msft aortiz-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@heng-liu heng-liu changed the title Suppress Http warnings in packages.config restore scenarios in all NuGet tools Opt out Https everywhere in packages.config restore scenarios in all NuGet tools Aug 17, 2023
@heng-liu heng-liu merged commit 8027512 into dev-feature-optoutHttpWarnings Aug 17, 2023
@heng-liu heng-liu deleted the dev-hengliu-optoutHttpWarning-packagesConfigRestore branch August 17, 2023 21:18
heng-liu added a commit that referenced this pull request Aug 21, 2023
heng-liu added a commit that referenced this pull request Aug 21, 2023
heng-liu added a commit that referenced this pull request Aug 28, 2023
heng-liu added a commit that referenced this pull request Sep 8, 2023
heng-liu added a commit that referenced this pull request Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants