Skip to content

Expose Default Certificate Constants - #251

Open
ErikMcClure wants to merge 3 commits into
httpmock:masterfrom
ErikMcClure:patch-1
Open

Expose Default Certificate Constants#251
ErikMcClure wants to merge 3 commits into
httpmock:masterfrom
ErikMcClure:patch-1

Conversation

@ErikMcClure

@ErikMcClure ErikMcClure commented Jul 14, 2026

Copy link
Copy Markdown

If you control the TLS connection chain, there's no need to add a test certificate to the machine keychain. Instead, if the library simply exposed the already existing constants, these could be turned into a Certificate using tokio_native_tls::native_tls::Certificate::from_pem, which could then be fed into tokio_native_tls::native_tls::TlsConnector::builder().add_root_certificate inside a test, which is more convenient.

@FalkWoldmann FalkWoldmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for this PR. Builder is a private module (mod builder; in server/mod.rs), so pub const on these two lines doesn't make them reachable outside the crate. httpmock::server::builder::DEFAULT_CA_CERTIFICATE still fails with E0603: module builder is private. Confirmed by building it.

Fix: add pub use builder::{DEFAULT_CA_PRIVATE_KEY, DEFAULT_CA_CERTIFICATE}; to server/mod.rs (or make builder itself pub mod).

@ErikMcClure

Copy link
Copy Markdown
Author

I added the pub use to server/mod.rs

@FalkWoldmann

Copy link
Copy Markdown
Member

Awesome, thanks! Could you please feature-gate the constants? e.g

// src/server/builder.rs
#[cfg(feature = "https")]
pub const DEFAULT_CA_PRIVATE_KEY: &str = include_str!("../../certs/ca.key");
#[cfg(feature = "https")]
pub const DEFAULT_CA_CERTIFICATE: &str = include_str!("../../certs/ca.pem");

and

// src/server/mod.rs
pub use builder::HttpMockServerBuilder;
#[cfg(feature = "https")]
pub use builder::{DEFAULT_CA_PRIVATE_KEY, DEFAULT_CA_CERTIFICATE};

@ErikMcClure

Copy link
Copy Markdown
Author

I featured-gated the constants and fixed the format, but the tests seem to fail for reasons that seem unrelated to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants