-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Make Kestrel config case-insensitive for certificates #23268
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
Changes from all commits
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 |
---|---|---|
|
@@ -68,6 +68,39 @@ public void ReadCertificatesSection_ReturnsCollection() | |
Assert.True(storeCert.AllowInvalid); | ||
} | ||
|
||
[Fact] | ||
public void ReadCertificatesSection_IsCaseInsensitive() | ||
{ | ||
var config = new ConfigurationBuilder().AddInMemoryCollection(new[] | ||
{ | ||
new KeyValuePair<string, string>("Certificates:filecert:Path", "/path/cert.pfx"), | ||
new KeyValuePair<string, string>("Certificates:FILECERT:Password", "certpassword"), | ||
}).Build(); | ||
var reader = new ConfigurationReader(config); | ||
var certificates = reader.Certificates; | ||
Assert.NotNull(certificates); | ||
Assert.Equal(1, certificates.Count); | ||
|
||
var fileCert = certificates["FiLeCeRt"]; | ||
Assert.True(fileCert.IsFileCert); | ||
Assert.False(fileCert.IsStoreCert); | ||
Assert.Equal("/path/cert.pfx", fileCert.Path); | ||
Assert.Equal("certpassword", fileCert.Password); | ||
} | ||
|
||
[Fact] | ||
public void ReadCertificatesSection_ThrowsOnCaseInsensitiveDuplicate() | ||
{ | ||
var exception = Assert.Throws<ArgumentException>(() => | ||
new ConfigurationBuilder().AddInMemoryCollection(new[] | ||
{ | ||
new KeyValuePair<string, string>("Certificates:filecert:Password", "certpassword"), | ||
new KeyValuePair<string, string>("Certificates:FILECERT:Password", "certpassword"), | ||
}).Build()); | ||
|
||
Assert.Contains("An item with the same key has already been added", exception.Message); | ||
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. This string is in Kestrel/Core/src/CoreStrings.resx - would it better to add a reference to that resource file to the .csproj? 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. CoreStrings is already InternalsVisibleTo to this project you just need to add a using for Microsoft.AspNetCore.Server.Kestrel.Core. |
||
} | ||
|
||
[Fact] | ||
public void ReadEndpointsWhenNoEndpointsSection_ReturnsEmptyCollection() | ||
{ | ||
|
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.
This should still pass if the entire key is UPPERCASE, right? I know this PR only changes the dictionary comparer, but I see no reason not to verify the rest of it case insensitive while we're at it.