Skip to content

Commit

Permalink
Merge branch 'maksimkim-sni'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Petz committed Sep 14, 2015
2 parents e1cec24 + b937429 commit beccdab
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 34 deletions.
56 changes: 29 additions & 27 deletions SharpNetSH.Test/AddActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,40 @@ public void VerifySSLCertOutput()

var tests = new[]
{
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) true, (bool?) false, (bool?) true, (bool?) false, (bool?) true},
new object[] {"testipport", null, "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", null, "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", null, "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", null, (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", null, (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), null, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, null, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, null, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, null, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, null, (bool?) true, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, null, (bool?) false},
new object[] {"testipport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, null}
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) true, (bool?) false, (bool?) true, (bool?) false, (bool?) true},
new object[] {null, "testhostnameport", null, "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", null, "testcerthash", null, "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {null, "testhostnameport", "testcerthash", "testcertstorename", null, "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", null, (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {null, "testhostnameport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", null, (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), null, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {null, "testhostnameport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, null, (bool?) false, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, null, (bool?) true, (bool?) false, (bool?) true, (bool?) false},
new object[] {null, "testhostnameport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, null, (bool?) false, (bool?) true, (bool?) false},
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, null, (bool?) true, (bool?) false},
new object[] {null, "testhostnameport", "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, null, (bool?) false},
new object[] {"testipport", null, "testcerthash", "testcertstorename", "testsslctlidentifier", "testsslctlstorename", (Guid?) new Guid("11111111-1111-1111-1111-111111111111"), (uint?) 1, (uint?) 1, (bool?) false, (bool?) true, (bool?) false, (bool?) true, null}
};

foreach (var values in tests)
{
var nullValueIndex = values.ToList().IndexOf(null);
var nullValueIndices = values.Select((val, idx) => Tuple.Create(val, idx)).Where(t => t.Item1 == null).Select(t => t.Item2).ToArray();


new NetSH(harness).Http.Add.SSLCert(ipPort: (string)values[0],
certHash: (string)values[1],
certStoreName: (string)values[2],
sslCtlIdentifier: (string)values[3],
sslCtlStoreName: (string)values[4],
appId: (Guid?) values[5],
revocationFreshnessTime: (uint?) values[6],
urlRetrievalTimeout: (uint?) values[7],
verifyClientCertRevocation: (bool?) values[8],
verifyRevocationWithCachedClientCertOnly: (bool?) values[9],
usageCheck: (bool?) values[10],
dsMapperUsage: (bool?) values[11],
clientCertNegotiation: (bool?) values[12]);
hostnamePort: (string)values[1],
certHash: (string)values[2],
certStoreName: (string)values[3],
sslCtlIdentifier: (string)values[4],
sslCtlStoreName: (string)values[5],
appId: (Guid?) values[6],
revocationFreshnessTime: (uint?) values[7],
urlRetrievalTimeout: (uint?) values[8],
verifyClientCertRevocation: (bool?) values[9],
verifyRevocationWithCachedClientCertOnly: (bool?) values[10],
usageCheck: (bool?) values[11],
dsMapperUsage: (bool?) values[12],
clientCertNegotiation: (bool?) values[13]);

var value = harness.Value;
var parameters = typeof (IAddAction).GetMethod("SSLCert").GetParameters();
Expand All @@ -66,7 +68,7 @@ public void VerifySSLCertOutput()
var type = x.ParameterType;
var name = x.Name.ToLower();

if (i == nullValueIndex)
if (nullValueIndices.Contains(i))
{
Assert.IsTrue(!value.Contains(name + "="));
i++;
Expand Down
4 changes: 3 additions & 1 deletion SharpNetSH.Test/DeleteActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public void VerifyIpListenOutput()
public void VerifySSLCertOutput()
{
var harness = new StringHarness();
new NetSH(harness).Http.Delete.SSLCert("testipport");
new NetSH(harness).Http.Delete.SSLCert(ipPort:"testipport");
Assert.AreEqual("netsh http delete sslcert ipport=testipport", harness.Value);
new NetSH(harness).Http.Delete.SSLCert(hostnamePort: "www.contoso.com:1414");
Assert.AreEqual("netsh http delete sslcert hostnameport=www.contoso.com:1414", harness.Value);
}

[TestMethod]
Expand Down
5 changes: 4 additions & 1 deletion SharpNetSH.Test/ShowActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public void VerifySSLCertOutput()
new NetSH(harness).Http.Show.SSLCert();
Assert.AreEqual("netsh http show sslcert", harness.Value);

new NetSH(harness).Http.Show.SSLCert("testipport");
new NetSH(harness).Http.Show.SSLCert(ipPort: "testipport");
Assert.AreEqual("netsh http show sslcert ipport=testipport", harness.Value);

new NetSH(harness).Http.Show.SSLCert(hostnamePort: "www.contoso.com:4443");
Assert.AreEqual("netsh http show sslcert hostnameport=www.contoso.com:4443", harness.Value);
}

[TestMethod]
Expand Down
4 changes: 3 additions & 1 deletion SharpNetSH/Actions/HTTP/IAddAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IAddAction
/// See <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc307220(v=vs.85).aspx">MSDN</a>.
/// </summary>
/// <param name="ipPort">Specifies the IP address and port for the binding.</param>
/// <param name="hostnamePort">Specifies hostname and port for the binding.</param>
/// <param name="certHash">Specifies the SHA hash of the certificate. This hash is 20 bytes long and specified as a hexadecimal string.</param>
/// <param name="certStoreName">Specifies the store name for the certificate. Defaults to MY. Certificate must be stored in the local computer context.</param>
/// <param name="sslCtlIdentifier">Lists the certificate issuers that can be trusted. This list can be a subset of the certificate issuers that are trusted by the computer.</param>
Expand All @@ -30,7 +31,8 @@ public interface IAddAction
/// <param name="dsMapperUsage">Turns on or turns off DS mappers. Default is disabled.</param>
/// <param name="clientCertNegotiation">Turns on or turns off negotiation of certificate. Default is disabled.</param>
[MethodName("sslcert")]
IResponse SSLCert([ParameterName("ipport")] string ipPort,
IResponse SSLCert([ParameterName("ipport")] string ipPort = null,
[ParameterName("hostnameport")] string hostnamePort = null,
[ParameterName("certhash")] string certHash = null,
[ParameterName("certstorename")] string certStoreName = null,
[ParameterName("sslctlidentifier")] string sslCtlIdentifier = null,
Expand Down
3 changes: 2 additions & 1 deletion SharpNetSH/Actions/HTTP/IDeleteAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public interface IDeleteAction
/// See <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc307229(v=vs.85).aspx">MSDN</a>.
/// </summary>
/// <param name="ipPort">Specifies the IPv4 or IPv6 address and port for which the SSL certificate bindings will be deleted.</param>
/// <param name="ipPort">Specifies the hostname and port for which the SSL certificate bindings will be deleted.</param>
[MethodName("sslcert")]
IResponse SSLCert([ParameterName("ipport")] String ipPort);
IResponse SSLCert([ParameterName("ipport")] String ipPort = null, [ParameterName("hostnameport")] String hostnamePort = null);

/// <summary>
/// Deletes a global timeout and makes the HTTP.sys service revert to default values.
Expand Down
7 changes: 4 additions & 3 deletions SharpNetSH/Actions/HTTP/IShowAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public interface IShowAction
IResponse ServiceStateRequestQueueView([ParameterName("verbose")] Boolean? verbose = null);

/// <summary>
/// Lists SSL server certificate bindings and the corresponding client certificate policies for an IP address and port.
/// Lists SSL server certificate bindings and the corresponding client certificate policies for an IP address/hostname and port. Not specifying an ipport or hostnameport lists all bindings.
/// See <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/cc307243(v=vs.85).aspx">MSDN</a>.
/// </summary>
/// <param name="ipPort">Specifies the IPv4 or IPv6 address and port for which the SSL certificate bindings will be displayed. Not specifying an ipport lists all bindings.</param>
/// <param name="ipPort">Specifies the IPv4 or IPv6 address and port for which the SSL certificate bindings will be displayed.</param>
/// <param name="hostnamePort">Specifies the hostname and port for which the SSL certificate bindings will be displayed.</param>
[MethodName("sslcert")]
[ResponseProcessor(typeof(BlockProcessor), @"\s+:\s+")]
IResponse SSLCert([ParameterName("ipport")] String ipPort = null);
IResponse SSLCert([ParameterName("ipport")] string ipPort = null, [ParameterName("hostnameport")] string hostnamePort = null);

/// <summary>
/// Shows the timeout values of the service (in seconds).
Expand Down

0 comments on commit beccdab

Please sign in to comment.