-
Notifications
You must be signed in to change notification settings - Fork 693
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
Add an allowInsecureConnections property in NuGet.Config #5343
Changes from all commits
1ad3dad
c002f58
7201267
6211314
80b70c5
154e4b8
0ea9583
78fad14
04d764c
5ebe789
aeadf7f
d912d1e
e1d8767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ internal sealed class PackageSourceContextInfoFormatter : NuGetMessagePackFormat | |
private const string SourcePropertyName = "source"; | ||
private const string IsEnabledPropertyName = "isenabled"; | ||
private const string ProtocolVersionPropertyName = "protocolversion"; | ||
private const string AllowInsecureConnectionsPropertyName = "allowInsecureConnections"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your use of camel-casing better, but should this be lowercase to be consistent? |
||
private const string IsMachineWidePropertyName = "ismachinewide"; | ||
private const string NamePropertyName = "name"; | ||
private const string DescriptionPropertyName = "description"; | ||
|
@@ -33,6 +34,7 @@ private PackageSourceContextInfoFormatter() | |
string? description = null; | ||
int originalHashCode = 0; | ||
int protocolVersion = PackageSource.DefaultProtocolVersion; | ||
bool allowInsecureConnections = false; | ||
|
||
int propertyCount = reader.ReadMapHeader(); | ||
for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++) | ||
|
@@ -60,6 +62,9 @@ private PackageSourceContextInfoFormatter() | |
case ProtocolVersionPropertyName: | ||
protocolVersion = reader.ReadInt32(); | ||
break; | ||
case AllowInsecureConnectionsPropertyName: | ||
allowInsecureConnections = reader.ReadBoolean(); | ||
break; | ||
default: | ||
reader.Skip(); | ||
break; | ||
|
@@ -69,7 +74,7 @@ private PackageSourceContextInfoFormatter() | |
Assumes.NotNullOrEmpty(source); | ||
Assumes.NotNullOrEmpty(name); | ||
|
||
return new PackageSourceContextInfo(source, name, isEnabled, protocolVersion) | ||
return new PackageSourceContextInfo(source, name, isEnabled, protocolVersion, allowInsecureConnections) | ||
{ | ||
IsMachineWide = isMachineWide, | ||
Description = description, | ||
|
@@ -79,11 +84,13 @@ private PackageSourceContextInfoFormatter() | |
|
||
protected override void SerializeCore(ref MessagePackWriter writer, PackageSourceContextInfo value, MessagePackSerializerOptions options) | ||
{ | ||
writer.WriteMapHeader(count: 7); | ||
writer.WriteMapHeader(count: 8); | ||
writer.Write(SourcePropertyName); | ||
writer.Write(value.Source); | ||
writer.Write(ProtocolVersionPropertyName); | ||
writer.Write(value.ProtocolVersion); | ||
writer.Write(AllowInsecureConnectionsPropertyName); | ||
writer.Write(value.AllowInsecureConnections); | ||
writer.Write(IsEnabledPropertyName); | ||
writer.Write(value.IsEnabled); | ||
writer.Write(IsMachineWidePropertyName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
#nullable enable | ||
NuGet.Configuration.PackageSource.AllowInsecureConnections.get -> bool | ||
NuGet.Configuration.PackageSource.AllowInsecureConnections.set -> void | ||
NuGet.Configuration.PackageSourceMappingProvider.ShouldSkipSave.get -> bool | ||
NuGet.Configuration.PackageSourceMapping.SearchForPattern(string! packageId) -> string? | ||
~NuGet.Configuration.PackageSourceMappingProvider.PackageSourceMappingProvider(NuGet.Configuration.ISettings settings, bool shouldSkipSave) -> void | ||
~NuGet.Configuration.SourceItem.AllowInsecureConnections.get -> string | ||
~NuGet.Configuration.SourceItem.AllowInsecureConnections.set -> void | ||
~NuGet.Configuration.SourceItem.SourceItem(string key, string value) -> void | ||
~NuGet.Configuration.SourceItem.SourceItem(string key, string value, string protocolVersion, string allowInsecureConnections) -> void | ||
~static readonly NuGet.Configuration.ConfigurationConstants.AllowInsecureConnections -> string |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,41 @@ public string ProtocolVersion | |
set => AddOrUpdateAttribute(ConfigurationConstants.ProtocolVersionAttribute, value); | ||
} | ||
|
||
public SourceItem(string key, string value, string protocolVersion = "") | ||
public string AllowInsecureConnections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check what happens when the nuget.config already has a value for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! That's very helpful! Fixed and added tests. Manually tested in VS, the non-default value of |
||
{ | ||
get | ||
{ | ||
if (Attributes.TryGetValue(ConfigurationConstants.AllowInsecureConnections, out var attribute)) | ||
{ | ||
return Settings.ApplyEnvironmentTransform(attribute); | ||
} | ||
|
||
return null; | ||
} | ||
set => AddOrUpdateAttribute(ConfigurationConstants.AllowInsecureConnections, value); | ||
} | ||
|
||
public SourceItem(string key, string value) | ||
: this(key, value, protocolVersion: "", allowInsecureConnections: "") | ||
{ | ||
} | ||
|
||
public SourceItem(string key, string value, string protocolVersion) | ||
: this(key, value, protocolVersion, allowInsecureConnections: "") | ||
{ | ||
} | ||
|
||
public SourceItem(string key, string value, string protocolVersion, string allowInsecureConnections) | ||
: base(key, value) | ||
{ | ||
if (!string.IsNullOrEmpty(protocolVersion)) | ||
{ | ||
ProtocolVersion = protocolVersion; | ||
} | ||
if (!string.IsNullOrEmpty(allowInsecureConnections)) | ||
{ | ||
AllowInsecureConnections = allowInsecureConnections; | ||
} | ||
} | ||
|
||
internal SourceItem(XElement element, SettingsFile origin) | ||
|
@@ -37,7 +65,7 @@ internal SourceItem(XElement element, SettingsFile origin) | |
|
||
public override SettingBase Clone() | ||
{ | ||
var newSetting = new SourceItem(Key, Value, ProtocolVersion); | ||
var newSetting = new SourceItem(Key, Value, ProtocolVersion, AllowInsecureConnections); | ||
|
||
if (Origin != null) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -130,5 +130,42 @@ public async Task Save_SourceWithDifferentProtocolVersion_SavesNewValue() | |||||
savedSources!.Count.Should().Be(1); | ||||||
savedSources[0].ProtocolVersion.Should().Be(3); | ||||||
} | ||||||
|
||||||
[Fact] | ||||||
public async Task Save_SourceWithDifferentAllowInsecureConnections_SavesNewValue() | ||||||
{ | ||||||
PackageSource packageSource = new(name: "Source-Name", source: "Source-Path") | ||||||
{ | ||||||
ProtocolVersion = 3, | ||||||
AllowInsecureConnections = false | ||||||
}; | ||||||
|
||||||
Mock<IPackageSourceProvider> packageSourceProvider = new(); | ||||||
packageSourceProvider.Setup(psp => psp.LoadPackageSources()) | ||||||
.Returns(new[] { packageSource }); | ||||||
|
||||||
List<PackageSource>? savedSources = null; | ||||||
packageSourceProvider.Setup(psp => psp.SavePackageSources(It.IsAny<IEnumerable<PackageSource>>())) | ||||||
.Callback((IEnumerable<PackageSource> newSources) => { savedSources = newSources.ToList(); }); | ||||||
|
||||||
var target = new NuGetSourcesService(options: default, | ||||||
Mock.Of<IServiceBroker>(), | ||||||
new AuthorizationServiceClient(Mock.Of<IAuthorizationService>()), | ||||||
packageSourceProvider.Object); | ||||||
|
||||||
List<PackageSourceContextInfo> updatedSources = new(1) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
{ | ||||||
new PackageSourceContextInfo(packageSource.Source, packageSource.Name, packageSource.IsEnabled, protocolVersion: 3, allowInsecureConnections: true) | ||||||
}; | ||||||
|
||||||
// Act | ||||||
await target.SavePackageSourceContextInfosAsync(updatedSources, CancellationToken.None); | ||||||
|
||||||
// Assert | ||||||
savedSources.Should().NotBeNull(); | ||||||
savedSources!.Count.Should().Be(1); | ||||||
savedSources[0].ProtocolVersion.Should().Be(3); | ||||||
savedSources[0].AllowInsecureConnections.Should().Be(true); | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above, which I don't think is useful, is now inaccurate.
// If key properties have not changed, we don't need to do anything
// If identifying properties have not changed, we don't need to do anything
// If Name/Source/IsEnabled/ProtocolVersion/AllowInsecureConnections has not changed, we don't need to do
anythingI vote for 4 or 1.