You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rust/pact_ffi/src/mock_server/mod.rs
+17-7Lines changed: 17 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ ffi_fn! {
120
120
/// * `pact` - Handle to a Pact model created with created with `pactffi_new_pact`.
121
121
/// * `addr` - Address to bind to (i.e. `127.0.0.1` or `[::1]`). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case the loopback adapter is used.
122
122
/// * `port` - Port number to bind to. A value of zero will result in the operating system allocating an available port.
123
-
/// * `transport` - The transport to use (i.e. http, https, grpc). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case http will be used.
123
+
/// * `transport` - The transport to use (i.e. http, https, grpc). Must be a valid UTF-8 NULL-terminated string, or NULL or empty, in which case http will be used. Passing `https` will start a TLS-enabled server using a self-signed certificate; use `pactffi_get_tls_ca_certificate` to obtain the CA cert for client configuration.
124
124
/// * `transport_config` - (OPTIONAL) Configuration for the transport as a valid JSON string. Set to NULL or empty if not required.
125
125
///
126
126
/// The port of the mock server is returned.
@@ -181,12 +181,22 @@ ffi_fn! {
181
181
.with_id(Uuid::new_v4().to_string())
182
182
.bind_to(socket_addr.to_string());
183
183
184
-
let builder = match builder.with_transport(transport.as_str()){
185
-
Ok(builder) => builder,
186
-
Err(err) => {
187
-
error!("Failed to configure mock server transport '{}' - {}", transport, err);
188
-
return -3;
189
-
}
184
+
let builder = match transport.as_str(){
185
+
"https" => match builder.with_self_signed_tls(){
186
+
Ok(builder) => builder,
187
+
Err(err) => {
188
+
error!("Failed to configure TLS for HTTPS mock server - {}", err);
189
+
return -3;
190
+
}
191
+
},
192
+
"http" => builder,
193
+
_ => match builder.with_transport(transport.as_str()){
194
+
Ok(builder) => builder,
195
+
Err(err) => {
196
+
error!("Failed to configure mock server transport '{}' - {}", transport, err);
0 commit comments