fix(pact-ffi): pactffi_create_mock_server_for_transport is unable to start a TLS mock server#530
Open
rholshausen wants to merge 1 commit intomasterfrom
Open
fix(pact-ffi): pactffi_create_mock_server_for_transport is unable to start a TLS mock server#530rholshausen wants to merge 1 commit intomasterfrom
rholshausen wants to merge 1 commit intomasterfrom
Conversation
…start a TLS mock server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(pact_ffi):
pactffi_create_mock_server_for_transportnow starts a TLS server when transport is"https"Problem
Callers passing
"https"topactffi_create_mock_server_for_transportreceived a plain HTTP server, not an HTTPS one. The function's doc comment explicitly listshttpsas a supported transport value, so this was a silent regression against the documented contract.Root cause
The function forwarded every transport string — including
"http"and"https"— directly toMockServerBuilder::with_transport(...). That method looks up the transport in the plugin catalogue and stores aCatalogueEntryon the builder config. It has no effect on whether the underlying server uses TLS.Whether TLS is used is decided later, in
ServerManager::spawn_http_mock_server, which checksbuilder.tls_configured(). That flag is only set totruewhen one of the explicit TLS-configuration methods (with_tls_config,with_tls_certs, orwith_self_signed_tls) has been called on the builder. Because the FFI path called none of them,"https"was silently treated as plain HTTP.The older, now-deprecated FFI functions (
create_tls_mock_server*,start_tls_mock_server*) worked correctly because they took an explicitServerConfigand passed it straight through to the mock server. That explicit TLS branch was dropped when the replacementpactffi_create_mock_server_for_transportwas introduced.Fix
Special-case the transport string in
pactffi_create_mock_server_for_transportbefore dispatching to the builder:"https"builder.with_self_signed_tls()— setstls_configon the builder, causingspawn_http_mock_serverto callstart_https()"http"builder.with_transport(...)for plugin-provided transports (unchanged)The doc comment on the function has been updated to state that
"https"starts a TLS server using a self-signed certificate, and points callers topactffi_get_tls_ca_certificatefor configuring their HTTP clients.Test
A new integration test
https_mock_server_starts_and_responds_over_tlsinpact_ffi/tests/tests.rs:GET /→ 200 interaction via the handle API.transport = "https"and port 0 (OS-assigned).danger_accept_invalid_certs(true)(the self-signed cert is not trusted by the system CA store).pactffi_mock_server_matchedreturns true, and the mismatch list is empty.Note on crypto provider initialisation
The test binary links both the
ringbackend (viapact_mock_server) and theaws-lc-rsbackend (viareqwest 0.13). When both are present, rustls panics atServerConfig::builder()unless a process-levelCryptoProviderhas been explicitly installed.MockServerBuilder::with_self_signed_tlsis missing the provider-installation guard thatwith_tls_certsalready has, so the test installs the ring provider explicitly at startup:rustlshas been added topact_ffi's[dev-dependencies]with theringfeature for this purpose. This is a test-only dependency; it does not affect the shipped library. The missing guard inwith_self_signed_tlsshould be reported as a bug upstream inpact-core-mock-server.Files changed
rust/pact_ffi/src/mock_server/mod.rs— transport dispatch logic and doc updaterust/pact_ffi/tests/tests.rs— new integration testrust/pact_ffi/Cargo.toml—rustlsadded to[dev-dependencies]