Commit 8eca0091 authored by justcoding121's avatar justcoding121

update tests

parent 95900411
......@@ -15,25 +15,23 @@ namespace Titanium.Web.Proxy.UnitTests
private readonly Random random = new Random();
[TestMethod]
public async Task Simple_Create_Certificate_Test()
public async Task Simple_BC_Create_Certificate_Test()
{
var tasks = new List<Task>();
var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value);
mgr.CertificateEngine = CertificateEngine.BouncyCastle;
mgr.ClearIdleCertificates();
foreach (string host in hostNames)
{
tasks.Add(Task.Run(async () =>
for (int i = 0; i < 5; i++)
foreach (string host in hostNames)
{
tasks.Add(Task.Run(() =>
{
//get the connection
var certificate = await mgr.CreateCertificateAsync(host);
Assert.IsNotNull(certificate);
}));
}
var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
}));
}
await Task.WhenAll(tasks.ToArray());
......@@ -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)
//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()
{
var tasks = new List<Task>();
var mgr = new CertificateManager(new Lazy<Action<Exception>>(() => (e => { })).Value);
mgr.CertificateEngine = CertificateEngine.DefaultWindows;
mgr.CreateRootCertificate(true);
mgr.TrustRootCertificate();
mgr.TrustRootCertificateAsAdmin();
mgr.ClearIdleCertificates();
mgr.CertificateEngine = CertificateEngine.DefaultWindows;
foreach (string host in hostNames)
{
tasks.Add(Task.Run(async () =>
for (int i = 0; i < 5; i++)
foreach (string host in hostNames)
{
tasks.Add(Task.Run(() =>
{
//get the connection
var certificate = await mgr.CreateCertificateAsync(host);
Assert.IsNotNull(certificate);
}));
}
var certificate = mgr.CreateCertificate(host, false);
Assert.IsNotNull(certificate);
}));
}
await Task.WhenAll(tasks.ToArray());
......
......@@ -250,17 +250,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
typeX509Enrollment.InvokeMember("InstallResponse", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
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);
}
catch (Exception)
{
// ignored
}
return null;
string empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
}
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