Skip to content

Commit a713fc5

Browse files
author
Matthew Sackman
committed
Made the SSL tests run only if SSL_CERTS_DIR is defined, and it also does the right import into the trust store (certmgr).
1 parent b8b4f96 commit a713fc5

File tree

7 files changed

+49
-19
lines changed

7 files changed

+49
-19
lines changed

configs/dotnet-1.1.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<property name="target.framework" value="net-1.1" />
44
<property name="debug" value="true"/>
55
<property name="python.exec" value="python.exe"/>
6+
<property name="certmgr.exec" value="certmgr.exe"/>
67
</project>

configs/dotnet-2.0.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<property name="target.framework" value="net-2.0" />
44
<property name="debug" value="true"/>
55
<property name="python.exec" value="python.exe"/>
6+
<property name="certmgr.exec" value="certmgr.exe"/>
67
</project>

configs/mono-1.0.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<property name="debug" value="true"/>
55
<property name="msbuild" value="xbuild"/>
66
<property name="python.exec" value="python"/>
7+
<property name="certmgr.exec" value="certmgr"/>
78
</project>

configs/mono-2.0.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<property name="debug" value="true"/>
55
<property name="msbuild" value="xbuild"/>
66
<property name="python.exec" value="python"/>
7+
<property name="certmgr.exec" value="certmgr"/>
78
</project>

default.build

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,25 @@
305305
<copy file="${nunit.dllname}" todir="${bin.dir}"/>
306306
</target>
307307

308+
<target name="detect-ssl">
309+
<property name="ssl.avail" value="false"/>
310+
<property name="ssl.avail" value="true"
311+
if="${environment::variable-exists('SSL_CERTS_DIR')}"/>
312+
<property name="ssl.certs.dir" value="${environment::get-variable('SSL_CERTS_DIR')}"
313+
if="${environment::variable-exists('SSL_CERTS_DIR')}"/>
314+
</target>
315+
316+
<target name="import-ssl" description="import cacert into certmgr" depends="detect-ssl" if="${ssl.avail}">
317+
<exec program="${certmgr.exec}">
318+
<arg value="-add"/>
319+
<arg value="-c"/>
320+
<arg value="Trust"/>
321+
<arg value="${ssl.certs.dir}/testca/cacert.cer"/>
322+
</exec>
323+
</target>
324+
308325
<target name="unit" description="run unit tests"
309-
depends="build-unit">
326+
depends="build-unit,import-ssl">
310327
<exec program="src/unit/nunit/nunit-console.exe" useruntimeengine="true">
311328
<arg value="${unit-tests.dllname}"/>
312329
</exec>

src/unit/TestSslEndpointUnverified.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,18 @@ public void SendReceive(IConnection conn) {
8989

9090
[Test]
9191
public void TestHostWithPort() {
92-
ConnectionFactory cf = new ConnectionFactory();
92+
string sslDir = Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
93+
if (null == sslDir) {
94+
return;
95+
} else {
96+
ConnectionFactory cf = new ConnectionFactory();
9397

94-
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
95-
cf.Parameters.Ssl.Enabled = true;
98+
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
99+
cf.Parameters.Ssl.Enabled = true;
96100

97-
IProtocol proto = Protocols.DefaultProtocol;
98-
IConnection conn = cf.CreateConnection(proto, "localhost", 5671);
99-
SendReceive(conn);
101+
IProtocol proto = Protocols.DefaultProtocol;
102+
IConnection conn = cf.CreateConnection(proto, "localhost", 5671);
103+
SendReceive(conn);
104+
}
100105
}
101106
}

src/unit/TestSslEndpointVerified.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@ public class TestSslEndpointVerified: TestSslEndpointUnverified {
6363

6464
[Test]
6565
public void TestHostWithPort() {
66-
ConnectionFactory cf = new ConnectionFactory();
67-
68-
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
6966
string sslDir = Environment.GetEnvironmentVariable("SSL_CERTS_DIR");
70-
Assert.IsNotNull(sslDir);
71-
cf.Parameters.Ssl.CertPath = sslDir + "/client/keycert.p12";
72-
string p12Password = Environment.GetEnvironmentVariable("PASSWORD");
73-
Assert.IsNotNull(p12Password);
74-
cf.Parameters.Ssl.CertPassphrase = p12Password;
75-
cf.Parameters.Ssl.Enabled = true;
67+
if (null == sslDir) {
68+
return;
69+
} else {
70+
ConnectionFactory cf = new ConnectionFactory();
71+
72+
cf.Parameters.Ssl.ServerName = System.Net.Dns.GetHostName();
73+
Assert.IsNotNull(sslDir);
74+
cf.Parameters.Ssl.CertPath = sslDir + "/client/keycert.p12";
75+
string p12Password = Environment.GetEnvironmentVariable("PASSWORD");
76+
Assert.IsNotNull(p12Password);
77+
cf.Parameters.Ssl.CertPassphrase = p12Password;
78+
cf.Parameters.Ssl.Enabled = true;
7679

77-
IProtocol proto = Protocols.DefaultProtocol;
78-
IConnection conn = cf.CreateConnection(proto, "localhost", 5671);
79-
SendReceive(conn);
80+
IProtocol proto = Protocols.DefaultProtocol;
81+
IConnection conn = cf.CreateConnection(proto, "localhost", 5671);
82+
SendReceive(conn);
83+
}
8084
}
8185
}

0 commit comments

Comments
 (0)