Raise appropriate errors when conflicting TLS options are present in the options dictionary. :param options: Instance of _CaseInsensitiveDictionary containing MongoDB URI options.
(options: _CaseInsensitiveDictionary)
| 251 | |
| 252 | |
| 253 | def _handle_security_options(options: _CaseInsensitiveDictionary) -> _CaseInsensitiveDictionary: |
| 254 | """Raise appropriate errors when conflicting TLS options are present in |
| 255 | the options dictionary. |
| 256 | |
| 257 | :param options: Instance of _CaseInsensitiveDictionary containing |
| 258 | MongoDB URI options. |
| 259 | """ |
| 260 | # Implicitly defined options must not be explicitly specified. |
| 261 | tlsinsecure = options.get("tlsinsecure") |
| 262 | if tlsinsecure is not None: |
| 263 | for opt in _IMPLICIT_TLSINSECURE_OPTS: |
| 264 | if opt in options: |
| 265 | err_msg = "URI options %s and %s cannot be specified simultaneously." |
| 266 | raise InvalidURI( |
| 267 | err_msg % (options.cased_key("tlsinsecure"), options.cased_key(opt)) |
| 268 | ) |
| 269 | |
| 270 | # Handle co-occurence of OCSP & tlsAllowInvalidCertificates options. |
| 271 | tlsallowinvalidcerts = options.get("tlsallowinvalidcertificates") |
| 272 | if tlsallowinvalidcerts is not None: |
| 273 | if "tlsdisableocspendpointcheck" in options: |
| 274 | err_msg = "URI options %s and %s cannot be specified simultaneously." |
| 275 | raise InvalidURI( |
| 276 | err_msg |
| 277 | % ("tlsallowinvalidcertificates", options.cased_key("tlsdisableocspendpointcheck")) |
| 278 | ) |
| 279 | if tlsallowinvalidcerts is True: |
| 280 | options["tlsdisableocspendpointcheck"] = True |
| 281 | |
| 282 | # Handle co-occurence of CRL and OCSP-related options. |
| 283 | tlscrlfile = options.get("tlscrlfile") |
| 284 | if tlscrlfile is not None: |
| 285 | for opt in ("tlsinsecure", "tlsallowinvalidcertificates", "tlsdisableocspendpointcheck"): |
| 286 | if options.get(opt) is True: |
| 287 | err_msg = "URI option %s=True cannot be specified when CRL checking is enabled." |
| 288 | raise InvalidURI(err_msg % (opt,)) |
| 289 | |
| 290 | if "ssl" in options and "tls" in options: |
| 291 | |
| 292 | def truth_value(val: Any) -> Any: |
| 293 | if val in ("true", "false"): |
| 294 | return val == "true" |
| 295 | if isinstance(val, bool): |
| 296 | return val |
| 297 | return val |
| 298 | |
| 299 | if truth_value(options.get("ssl")) != truth_value(options.get("tls")): |
| 300 | err_msg = "Can not specify conflicting values for URI options %s and %s." |
| 301 | raise InvalidURI(err_msg % (options.cased_key("ssl"), options.cased_key("tls"))) |
| 302 | |
| 303 | return options |
| 304 | |
| 305 | |
| 306 | def _handle_option_deprecations(options: _CaseInsensitiveDictionary) -> _CaseInsensitiveDictionary: |
no test coverage detected