dont repeat "ClientCertificate" in enum values

pull/16552/head
Jan Tattermusch 6 years ago
parent 209aee1c69
commit 460faf4bc2
  1. 18
      src/csharp/Grpc.Core/ServerCredentials.cs
  2. 28
      src/csharp/Grpc.IntegrationTesting/SslCredentialsTest.cs

@ -68,7 +68,7 @@ namespace Grpc.Core
/// all. (A client may present a self signed or signed certificate or not
/// present a certificate at all and any of those option would be accepted)
/// </summary>
DontRequestClientCertificate = 0,
DontRequest = 0,
/// <summary>
/// Server requests client certificate but does not enforce that the client
/// presents a certificate.
@ -78,7 +78,7 @@ namespace Grpc.Core
/// The client's key certificate pair must be valid for the SSL connection to
/// be established.
///</summary>
RequestClientCertificateButDontVerify,
RequestButDontVerify,
/// <summary>
/// Server requests client certificate but does not enforce that the client
/// presents a certificate.
@ -89,7 +89,7 @@ namespace Grpc.Core
/// The client's key certificate pair must be valid for the SSL connection to
/// be established.
/// </summary>
RequestClientCertificateAndVerify,
RequestAndVerify,
/// <summary>
/// Server requests client certificate and enforces that the client presents a
/// certificate.
@ -99,7 +99,7 @@ namespace Grpc.Core
/// The client's key certificate pair must be valid for the SSL connection to
/// be established.
///</summary>
RequestAndRequireClientCertificateButDontVerify,
RequestAndRequireButDontVerify,
/// <summary>
/// Server requests client certificate and enforces that the client presents a
/// certificate.
@ -109,7 +109,7 @@ namespace Grpc.Core
/// The client's key certificate pair must be valid for the SSL connection to
/// be established.
/// </summary>
RequestAndRequireClientCertificateAndVerify,
RequestAndRequireAndVerify,
}
/// <summary>
/// Server-side SSL credentials.
@ -127,7 +127,7 @@ namespace Grpc.Core
/// <param name="rootCertificates">PEM encoded client root certificates used to authenticate client.</param>
/// <param name="forceClientAuth">Deprecated, use clientCertificateRequest overload instead.</param>
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates, bool forceClientAuth)
: this(keyCertificatePairs, rootCertificates, forceClientAuth ? SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify : SslClientCertificateRequestType.DontRequestClientCertificate)
: this(keyCertificatePairs, rootCertificates, forceClientAuth ? SslClientCertificateRequestType.RequestAndRequireAndVerify : SslClientCertificateRequestType.DontRequest)
{
}
@ -142,7 +142,7 @@ namespace Grpc.Core
this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly();
GrpcPreconditions.CheckArgument(this.keyCertificatePairs.Count > 0,
"At least one KeyCertificatePair needs to be provided.");
if (clientCertificateRequest == SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify)
if (clientCertificateRequest == SslClientCertificateRequestType.RequestAndRequireAndVerify)
{
GrpcPreconditions.CheckNotNull(rootCertificates,
"Cannot require and verify client certificate unless you provide rootCertificates.");
@ -157,7 +157,7 @@ namespace Grpc.Core
/// (client certificate won't be requested and checked by the server at all).
/// </summary>
/// <param name="keyCertificatePairs">Key-certificates to use.</param>
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs) : this(keyCertificatePairs, null, SslClientCertificateRequestType.DontRequestClientCertificate)
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs) : this(keyCertificatePairs, null, SslClientCertificateRequestType.DontRequest)
{
}
@ -190,7 +190,7 @@ namespace Grpc.Core
{
get
{
return this.clientCertificateRequest == SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify;
return this.clientCertificateRequest == SslClientCertificateRequestType.RequestAndRequireAndVerify;
}
}

@ -91,7 +91,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: false,
clientCertRequestType: SslClientCertificateRequestType.DontRequestClientCertificate);
clientCertRequestType: SslClientCertificateRequestType.DontRequest);
await CheckAccepted(expectPeerAuthenticated: false);
}
@ -101,7 +101,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: true,
clientCertRequestType: SslClientCertificateRequestType.DontRequestClientCertificate);
clientCertRequestType: SslClientCertificateRequestType.DontRequest);
await CheckAccepted(expectPeerAuthenticated: false);
}
@ -111,7 +111,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: false,
clientCertRequestType: SslClientCertificateRequestType.RequestClientCertificateButDontVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestButDontVerify);
await CheckAccepted(expectPeerAuthenticated: false);
}
@ -121,7 +121,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: false,
clientCertRequestType: SslClientCertificateRequestType.RequestClientCertificateAndVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestAndVerify);
await CheckAccepted(expectPeerAuthenticated: false);
}
@ -131,7 +131,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: true,
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireClientCertificateButDontVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireButDontVerify);
await CheckAccepted(expectPeerAuthenticated: true);
await CheckAuthContextIsPopulated();
@ -142,7 +142,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: true,
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireAndVerify);
await CheckAccepted(expectPeerAuthenticated: true);
await CheckAuthContextIsPopulated();
@ -153,7 +153,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: false,
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireClientCertificateButDontVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireButDontVerify);
CheckRejected();
}
@ -163,7 +163,7 @@ namespace Grpc.IntegrationTesting
{
InitClientAndServer(
clientAddKeyCertPair: false,
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify);
clientCertRequestType: SslClientCertificateRequestType.RequestAndRequireAndVerify);
CheckRejected();
}
@ -172,20 +172,20 @@ namespace Grpc.IntegrationTesting
public void Constructor_LegacyForceClientAuth()
{
var creds = new SslServerCredentials(new[] { keyCertPair }, rootCert, true);
Assert.AreEqual(SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify, creds.ClientCertificateRequest);
Assert.AreEqual(SslClientCertificateRequestType.RequestAndRequireAndVerify, creds.ClientCertificateRequest);
var creds2 = new SslServerCredentials(new[] { keyCertPair }, rootCert, false);
Assert.AreEqual(SslClientCertificateRequestType.DontRequestClientCertificate, creds2.ClientCertificateRequest);
Assert.AreEqual(SslClientCertificateRequestType.DontRequest, creds2.ClientCertificateRequest);
}
[Test]
public void Constructor_NullRootCerts()
{
var keyCertPairs = new[] { keyCertPair };
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.DontRequestClientCertificate));
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestClientCertificateAndVerify));
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestAndRequireClientCertificateButDontVerify));
Assert.Throws(typeof(ArgumentNullException), () => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestAndRequireClientCertificateAndVerify));
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.DontRequest));
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestAndVerify));
Assert.DoesNotThrow(() => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestAndRequireButDontVerify));
Assert.Throws(typeof(ArgumentNullException), () => new SslServerCredentials(keyCertPairs, null, SslClientCertificateRequestType.RequestAndRequireAndVerify));
}
private async Task CheckAccepted(bool expectPeerAuthenticated)

Loading…
Cancel
Save