@@ -76,7 +76,8 @@ public async Task ConnectUsingTlsAndUserPassword(string virtualHost)
7676 else
7777 {
7878 connectionSettings . TlsSettings . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateChainErrors ;
79- connectionSettings . TlsSettings . RemoteCertificateValidationCallback = ( sender , certificate , chain , errors ) => true ;
79+ connectionSettings . TlsSettings . RemoteCertificateValidationCallback =
80+ ( sender , certificate , chain , errors ) => true ;
8081 }
8182
8283 Assert . Equal ( "localhost" , connectionSettings . Host ) ;
@@ -92,18 +93,22 @@ public async Task ConnectUsingTlsAndUserPassword(string virtualHost)
9293 Assert . Equal ( State . Closed , connection . State ) ;
9394 }
9495
95- [ Fact ]
96- public async Task ConnectUsingTlsAndClientCertificate ( )
96+ [ Theory ]
97+ [ InlineData ( "/my_tls_host_certificate" ) ]
98+ [ InlineData ( "/" ) ]
99+ public async Task ConnectUsingTlsAndClientCertificate ( string virtualHost )
97100 {
101+ await CreateVhostAsync ( virtualHost ) ;
98102 string clientCertFile = GetClientCertFile ( ) ;
99103 var cert = new X509Certificate2 ( clientCertFile , "grapefruit" ) ;
100104
101- await CreateUserFromCertSubject ( cert ) ;
105+ await CreateUserFromCertSubject ( cert , virtualHost ) ;
102106
103107 ConnectionSettings connectionSettings = _connectionSettingBuilder
104108 . Scheme ( "amqps" )
105109 . SaslMechanism ( SaslMechanism . External )
106110 . Port ( _port )
111+ . VirtualHost ( virtualHost )
107112 . Build ( ) ;
108113
109114 Assert . True ( connectionSettings . UseSsl ) ;
@@ -125,14 +130,15 @@ public async Task ConnectUsingTlsAndClientCertificate()
125130 else
126131 {
127132 connectionSettings . TlsSettings . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateChainErrors ;
128- connectionSettings . TlsSettings . RemoteCertificateValidationCallback = ( sender , certificate , chain , errors ) => true ;
133+ connectionSettings . TlsSettings . RemoteCertificateValidationCallback =
134+ ( sender , certificate , chain , errors ) => true ;
129135 }
130136
131137 Assert . Equal ( "localhost" , connectionSettings . Host ) ;
132138 Assert . Equal ( _port , connectionSettings . Port ) ;
133139 Assert . Null ( connectionSettings . User ) ;
134140 Assert . Null ( connectionSettings . Password ) ;
135- Assert . Equal ( "/" , connectionSettings . VirtualHost ) ;
141+ Assert . Equal ( virtualHost , connectionSettings . VirtualHost ) ;
136142 Assert . Equal ( "amqps" , connectionSettings . Scheme ) ;
137143 Assert . Equal ( SaslMechanism . External , connectionSettings . SaslMechanism ) ;
138144
@@ -142,10 +148,10 @@ public async Task ConnectUsingTlsAndClientCertificate()
142148 Assert . Equal ( State . Closed , connection . State ) ;
143149 }
144150
145- private Task CreateUserFromCertSubject ( X509Certificate cert )
151+ private Task CreateUserFromCertSubject ( X509Certificate cert , string virtualHost )
146152 {
147153 string userName = cert . Subject . Trim ( ) . Replace ( " " , string . Empty ) ;
148- return _httpApiClient . CreateUserAsync ( userName ) ;
154+ return _httpApiClient . CreateUserAsync ( userName , virtualHost ) ;
149155 }
150156
151157 private static string GetClientCertFile ( )
@@ -156,6 +162,7 @@ private static string GetClientCertFile()
156162 {
157163 clientCertFile = Path . GetFullPath ( Path . Combine ( cwd , "../../../../../.ci/certs/client_localhost.p12" ) ) ;
158164 }
165+
159166 Assert . True ( File . Exists ( clientCertFile ) ) ;
160167 return clientCertFile ;
161168 }
0 commit comments