Commit 2b205842 authored by justcoding121's avatar justcoding121

update tests

parent 5bbd1651
...@@ -15,25 +15,23 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -15,25 +15,23 @@ namespace Titanium.Web.Proxy.UnitTests
private readonly Random random = new Random(); private readonly Random random = new Random();
[TestMethod] [TestMethod]
public async Task Simple_Create_Certificate_Test() public async Task Simple_BC_Create_Certificate_Test()
{ {
var tasks = new List<Task>(); var tasks = new List<Task>();
var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value); var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value);
mgr.CertificateEngine = CertificateEngine.BouncyCastle;
mgr.ClearIdleCertificates(); mgr.ClearIdleCertificates();
for (int i = 0; i < 5; i++)
foreach (string host in hostNames) foreach (string host in hostNames)
{
tasks.Add(Task.Run(async () =>
{ {
tasks.Add(Task.Run(() =>
{
//get the connection //get the connection
var certificate = await mgr.CreateCertificateAsync(host); var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
Assert.IsNotNull(certificate); }));
})); }
}
await Task.WhenAll(tasks.ToArray()); await Task.WhenAll(tasks.ToArray());
...@@ -42,27 +40,27 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -42,27 +40,27 @@ namespace Titanium.Web.Proxy.UnitTests
//uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above) //uncomment this to compare WinCert maker performance with BC (BC takes more time for same test above)
//cannot run this test in build server since trusting the certificate won't happen successfully //cannot run this test in build server since trusting the certificate won't happen successfully
//[TestMethod] [TestMethod]
public async Task Simple_Create_Win_Certificate_Test() public async Task Simple_Create_Win_Certificate_Test()
{ {
var tasks = new List<Task>(); var tasks = new List<Task>();
var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value); var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value);
mgr.CertificateEngine = CertificateEngine.DefaultWindows;
mgr.CreateRootCertificate(true); mgr.CreateRootCertificate(true);
mgr.TrustRootCertificate(); mgr.TrustRootCertificateAsAdmin();
mgr.ClearIdleCertificates(); mgr.ClearIdleCertificates();
mgr.CertificateEngine = CertificateEngine.DefaultWindows;
foreach (string host in hostNames) for (int i = 0; i < 5; i++)
{ foreach (string host in hostNames)
tasks.Add(Task.Run(async () =>
{ {
tasks.Add(Task.Run(() =>
{
//get the connection //get the connection
var certificate = await mgr.CreateCertificateAsync(host); var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
Assert.IsNotNull(certificate); }));
})); }
}
await Task.WhenAll(tasks.ToArray()); await Task.WhenAll(tasks.ToArray());
......
...@@ -250,17 +250,8 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -250,17 +250,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
typeX509Enrollment.InvokeMember("InstallResponse", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue); typeX509Enrollment.InvokeMember("InstallResponse", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
typeValue = new object[] { null, 0, 1 }; typeValue = new object[] { null, 0, 1 };
try string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
{ return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
}
catch (Exception)
{
// ignored
}
return null;
} }
private X509Certificate2 MakeCertificateInternal(string sSubjectCN, bool isRoot, private X509Certificate2 MakeCertificateInternal(string sSubjectCN, bool isRoot,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment