Skip to content

Change server_certificate to PathBuf#22

Open
olback wants to merge 4 commits intomicrosoft:mainfrom
olback:server_certificare-pathbuf
Open

Change server_certificate to PathBuf#22
olback wants to merge 4 commits intomicrosoft:mainfrom
olback:server_certificare-pathbuf

Conversation

@olback
Copy link
Copy Markdown

@olback olback commented Apr 19, 2026

Change server_certificate to PathBuf since not all valid paths can be represented as strings (e.g., paths with non-UTF-8 characters).

Description

Related Issues

Checklist

  • cargo bfmt passes
  • cargo bclippy passes
  • cargo btest passes
  • New/changed functionality has tests
  • Public API changes are documented - Changelog says unleasead, which should allow for any breaking changes?

Change server_certificate to PathBuf since not all valid paths can be represented as strings (e.g., paths with non-UTF-8 characters).
@olback olback requested a review from a team as a code owner April 19, 2026 16:35
@olback
Copy link
Copy Markdown
Author

olback commented Apr 19, 2026

@microsoft-github-policy-service agree

@saurabh500
Copy link
Copy Markdown
Contributor

@olback can you open a issue describing what would happen if this change is not made with some more details?

@olback
Copy link
Copy Markdown
Author

olback commented Apr 21, 2026

@saurabh500 Sure, see #23

@saurabh500
Copy link
Copy Markdown
Contributor

@olback we are still setting up infrastructure to allow PR builds. In the meanwhile I will leave a few comments.

@saurabh500
Copy link
Copy Markdown
Contributor

Please run cargo build in mssql-py-core project.
You will see compilation error due to API change (mssql-py-core is not in workspace and cargo build from Workspace doesn't build it).

Since we haven't released mssql-tds breaking change is OK, but since all consumers of mssql-tds are in the repo itself (for now), it would be good to make sure that all consumers compile

@saurabh500
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI review requested due to automatic review settings April 24, 2026 17:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates certificate path handling to use PathBuf instead of String, enabling support for non-UTF-8 filesystem paths (particularly relevant on Unix-like platforms).

Changes:

  • Replace server_certificate: Option<String> with Option<PathBuf> across core types and tests.
  • Update certificate loading/validation helpers to accept &Path and store PathBuf in error variants.
  • Adjust Rust and Python binding tests/call sites to pass PathBuf/&Path and log paths via display().

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mssql-tds/tests/test_mock_server_tls.rs Updates tests to construct server_certificate as a PathBuf.
mssql-tds/tests/test_mock_server.rs Updates multiple tests to pass PathBuf for server_certificate.
mssql-tds/src/error/mod.rs Changes certificate-related error variants to store PathBuf paths.
mssql-tds/src/core.rs Updates public EncryptionOptions.server_certificate type to Option<PathBuf>.
mssql-tds/src/connection/transport/ssl_handler.rs Adjusts logging and tests for PathBuf-based certificate pinning.
mssql-tds/src/connection/transport/certificate_validator.rs Refactors certificate loading/validation APIs to accept &Path and updates tests accordingly.
mssql-py-core/src/connection.rs Updates PyO3 extraction to parse server_certificate as PathBuf.
Comments suppressed due to low confidence (1)

mssql-tds/src/connection/transport/certificate_validator.rs:1

  • This repeats path.to_path_buf() several times when constructing errors. Consider creating a single owned PathBuf upfront (e.g., let path_buf = path.to_path_buf();) and reusing/cloning it for error variants, which reduces duplication and makes future edits less error-prone.
// Copyright (c) Microsoft Corporation.

Comment thread mssql-tds/src/connection/transport/ssl_handler.rs Outdated
Comment thread mssql-tds/src/connection/transport/certificate_validator.rs Outdated
trust_server_certificate: true, // This should be ignored
host_name_in_cert: None,
server_certificate: Some(cert_path.to_str().unwrap().to_string()),
server_certificate: Some(cert_path.clone()),
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

PR metadata indicates cargo btest was not run. Since this PR changes a public type (EncryptionOptions.server_certificate) and associated validation code, it would be important to run the full test suite (cargo btest) and update the checklist before merging to avoid regressions.

Copilot uses AI. Check for mistakes.
@olback
Copy link
Copy Markdown
Author

olback commented Apr 24, 2026

Since we haven't released mssql-tds breaking change is OK, but since all consumers of mssql-tds are in the repo itself (for now), it would be good to make sure that all consumers compile

Of course, I totally missed the python crate. Should be all good now though. @saurabh500

@saurabh500
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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.

3 participants