Skip to content

Add ClientBuilder helper to make setting up TLS connections easy. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 11, 2021

Conversation

mordak
Copy link
Contributor

@mordak mordak commented May 6, 2021

Addresses #190

Also add support for rustls in addition to native-tls. I think using rustls should be easier (and could even be the default?), so I just made it first class like native-tls. I have tested both the native_tls() and rustls() paths.

This just adds the ClientBuilder. If we're happy with the API here and the way it works, then I can take care of:

  • Fixing up the examples (doc and /examples) to use it where appropriate.
  • If we want to get rid of any code that is superseded by this?

I have not tested the STARTTLS code, since I do not have a STARTTLS enabled server to work with. How do we want to handle automating the tests to make sure it all works?

I have not added it, but I can see an argument for adding some knobs to control which CA bundle is added, or adding private CAs or something. The alternative it to just leave the existing API as is, which allows users to make their own TLS connection using whatever configuration that they want.


This change is Reviewable

Add support for rustls in addition to native-tls.
@codecov
Copy link

codecov bot commented May 6, 2021

Codecov Report

Merging #197 (fb07d97) into master (c443a3a) will decrease coverage by 3.72%.
The diff coverage is 21.21%.

Impacted Files Coverage Δ
src/error.rs 2.73% <0.00%> (-0.21%) ⬇️
src/extensions/idle.rs 0.00% <0.00%> (ø)
src/types/deleted.rs 98.61% <ø> (ø)
src/client.rs 85.55% <25.00%> (+0.60%) ⬆️
src/client_builder.rs 27.27% <27.27%> (ø)
src/types/unsolicited_response.rs 40.00% <0.00%> (-2.86%) ⬇️

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

I like the approach! I left a suggestion in there that I think can deal with the more customized setup routines users may have. As for testing STARTTLS, I thought our integration test already did that? If not, we should add one.

mordak and others added 3 commits May 6, 2021 16:02
@mordak
Copy link
Contributor Author

mordak commented May 6, 2021

As for testing STARTTLS, I thought our integration test already did that? If not, we should add one.

We have one, but it is marked ignore. Is there another one?

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Ugh, you're right, I forgot that Greenmail doesn't support STARTTLS. That's awkward. I suppose we'll just have to leave that one for users to test then 😢

@jonhoo
Copy link
Owner

jonhoo commented May 8, 2021

Ugh, separately, we really should add a codecov configuration file that sets less onerous restrictions for PRs Currently they basically always fail. Something like this one (docs here).

@mordak
Copy link
Contributor Author

mordak commented May 9, 2021

Ugh, separately, we really should add a codecov configuration file that sets less onerous restrictions for PRs Currently they basically always fail. Something like this one (docs here).

Happily added. Having the codecov always fail is a bit annoying. I copied the one you linked and tweaked it for the values that we're seeing in PRs here (ie 70% coverage low line, and don't fail for -2%). No problem if you want to change them to be tighter.

@mordak
Copy link
Contributor Author

mordak commented May 9, 2021

Separately - what, if anything, do we want to move to the builder API?

  • Doc examples?
  • Examples?
  • Anything in the lib?

I can see some of the docs and examples being kind of obvious. For the lib, some of the Client setup stuff could be moved the builder API internally while preserving the public API, or we could remove the public API in favour of the builder API, or we could just leave the lib as is and call it a day. Do you have an inclination here?

@jonhoo
Copy link
Owner

jonhoo commented May 9, 2021

I think my preference here is actually to only have the builder API + Client::new for custom streams. What do you think?

Remove these functions. Update documentation to reference the ClientBuilder.
Update examples to use the ClientBuilder except for timeout.rs, which
now serves as an example of how to use Client::new() with a custom stream.
@mordak
Copy link
Contributor Author

mordak commented May 9, 2021

Ugh, you're right, I forgot that Greenmail doesn't support STARTTLS. That's awkward. I suppose we'll just have to leave that one for users to test then 😢

I put together a local test for this and confirmed the STARTTLS implementation in the ClientBuilder works.

@mordak
Copy link
Contributor Author

mordak commented May 9, 2021

I think my preference here is actually to only have the builder API + Client::new for custom streams. What do you think?

Oh that sounds good to me. I prefer having one good way to do it: it is less code to maintain and nicer for users.

I pushed a diff that removes connect() and connect_starttls() and updates the examples, tests and docs to use the ClientBuilder instead. I think the only possible wrinkle is the greenmail tests, which may not be happy with the certificate validation. If that's the case then I can figure it out.

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@@ -15,10 +15,12 @@ categories = ["email", "network-programming"]

[features]
tls = ["native-tls"]
rustls-tls = ["rustls-connector"]
Copy link
Owner

Choose a reason for hiding this comment

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

Separately, I wonder if we want to take this opportunity to rename the "other" tls feature native-tls, since it isn't really "more" standard than rustls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a good idea, so did a PR up here.

@jonhoo jonhoo merged commit 7204697 into jonhoo:master May 11, 2021
@jonhoo jonhoo mentioned this pull request May 11, 2021
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