-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
ClientCertificateMode now read from config #18759
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 | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||
// Copyright (c) .NET Foundation. All rights reserved. | ||||||||
// Copyright (c) .NET Foundation. All rights reserved. | ||||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||
|
||||||||
using System; | ||||||||
|
@@ -15,17 +15,32 @@ internal class ConfigurationReader | |||||||
private const string EndpointDefaultsKey = "EndpointDefaults"; | ||||||||
private const string EndpointsKey = "Endpoints"; | ||||||||
private const string UrlKey = "Url"; | ||||||||
private const string ClientCertificateModeKey = "ClientCertificateMode"; | ||||||||
|
||||||||
private IConfiguration _configuration; | ||||||||
private IDictionary<string, CertificateConfig> _certificates; | ||||||||
private IList<EndpointConfig> _endpoints; | ||||||||
private EndpointDefaults _endpointDefaults; | ||||||||
|
||||||||
private string _clientCertificateMode; | ||||||||
public ConfigurationReader(IConfiguration configuration) | ||||||||
{ | ||||||||
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); | ||||||||
} | ||||||||
|
||||||||
|
||||||||
public string ClientCertificateMode | ||||||||
{ | ||||||||
get | ||||||||
{ | ||||||||
if (string.IsNullOrEmpty(_clientCertificateMode)) | ||||||||
{ | ||||||||
ReadClientCertificateMode(); | ||||||||
} | ||||||||
return _clientCertificateMode; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
||||||||
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: remove the extra newline above and below property. |
||||||||
public IDictionary<string, CertificateConfig> Certificates | ||||||||
{ | ||||||||
get | ||||||||
|
@@ -65,6 +80,10 @@ public IEnumerable<EndpointConfig> Endpoints | |||||||
} | ||||||||
} | ||||||||
|
||||||||
private void ReadClientCertificateMode() | ||||||||
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 should do the enum parsing instead of LoadClientCertificateMode in KestrelConfigurationLoader. 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. Compare to ParseProtocols |
||||||||
{ | ||||||||
_clientCertificateMode = _configuration[ClientCertificateModeKey]; | ||||||||
} | ||||||||
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.
Suggested change
|
||||||||
private void ReadCertificates() | ||||||||
{ | ||||||||
_certificates = new Dictionary<string, CertificateConfig>(0); | ||||||||
|
@@ -121,8 +140,8 @@ private void ReadEndpoints() | |||||||
_endpoints.Add(endpoint); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
private static HttpProtocols? ParseProtocols(string protocols) | ||||||||
private static HttpProtocols? ParseProtocols(string protocols) | ||||||||
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. Undo this. |
||||||||
{ | ||||||||
if (Enum.TryParse<HttpProtocols>(protocols, ignoreCase: true, out var result)) | ||||||||
{ | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||
// Copyright (c) .NET Foundation. All rights reserved. | ||||||||
// Copyright (c) .NET Foundation. All rights reserved. | ||||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||||||||
|
||||||||
using System; | ||||||||
|
@@ -12,6 +12,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests | |||||||
{ | ||||||||
public class ConfigurationReaderTests | ||||||||
{ | ||||||||
|
||||||||
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.
Suggested change
|
||||||||
[Fact] | ||||||||
public void ReadClientCertificateMode_ReturnsValue() | ||||||||
{ | ||||||||
var config = new ConfigurationBuilder().AddInMemoryCollection( | ||||||||
new[] | ||||||||
{ | ||||||||
new KeyValuePair<string, string>("ClientCertificateMode", "AllowCertificate") | ||||||||
} | ||||||||
).Build(); | ||||||||
var reader = new ConfigurationReader(config); | ||||||||
var clientCertificateMode = reader.ClientCertificateMode; | ||||||||
Assert.NotNull(clientCertificateMode); | ||||||||
} | ||||||||
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.
Suggested change
|
||||||||
[Fact] | ||||||||
public void ReadClientCertificateModeWhenNoClientCertificateMode_ReturnsNull() | ||||||||
{ | ||||||||
var config = new ConfigurationBuilder().AddInMemoryCollection().Build(); | ||||||||
var reader = new ConfigurationReader(config); | ||||||||
var clientCertificateMode = reader.ClientCertificateMode; | ||||||||
Assert.Null(clientCertificateMode); | ||||||||
} | ||||||||
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.
Suggested change
|
||||||||
[Fact] | ||||||||
public void ReadCertificatesWhenNoCertificatesSection_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.
Can we make this type ClientCertificateMode?