Skip to content

ConnectionBuilder.TLSConfig option and Connection.Disconnect #6

Description

@TopherGopher

Part of the easymongo refactor (see PLAN.md on the refactor branch). Needed so easymongotest can connect to mongotest's TLS mode, and so tests can close connections cleanly.

Working context (read this first)

Scope

  • func (cb *ConnectionBuilder) TLSConfig(cfg *tls.Config) *ConnectionBuilder storing the config in MongoConnectOptions and applying opts.SetTLSConfig(cfg) in clientOptions().
  • Connection.Disconnect(ctx) error if not already landed by the connect.go migration issue; ensure it also clears the global connection when it was the cached one.
  • Remove the large commented-out TLS block in connect.go (lines around 158-200) in favour of the real option.
  • README: a short "Connecting with TLS" snippet.

Implementation details

Verified in v2.9.0: func (c *options.ClientOptions) SetTLSConfig(cfg *tls.Config) *options.ClientOptions and the resulting ClientOptions.TLSConfig *tls.Config field, which the unit test can read back. Add tlsConfig *tls.Config to MongoConnectOptions and apply it in clientOptions() after ApplyURI so it wins over any tls= URI parameter.

When both the URI contains tls=true and a config is given, the driver uses the config; when only the URI says tls=true, the driver uses system roots, which will fail against mongotest's self-signed CA. That is the failure the second integration test asserts (expect an error within the 2 second connect timeout, do not assert on the error text).

Tests first

  • Unit: ConnectWith(uri).TLSConfig(cfg) results in clientOptions().TLSConfig == cfg.
  • Integration (after easymongotest exists): connect to a mongotest.Run(t, mongotest.WithTLS()) instance with its Container.TLSConfig(); a plain connection to the same URI fails within the connect timeout.

Acceptance

  • Both tests pass; the dead TLS comment block is gone.

Depends on: #8. Can land on driver v1 (the same SetTLSConfig exists there) before the driver migration pull request; Disconnect is then adjusted in #2.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions