How to use V3 CosmosClient with Emulator while ignoring SSL errors?
See original GitHub issueDescribe the bug Impossible to connect CosmosClient to Emulator while trying to ignore SSL certificates.
I already searched this repo and the web to find some information about how to ignore the SSL error if we try to connect to the emulator. All I could find was some hints on how to solve these problems on V2 DocumentClient (like #42), but nothing for V3 CosmosClient.
I dig through the public interface of the class, their options, etc. and the only maybe promising I could find was the Collection<RequestHandler> CustomHandlers
. So I wrote my own handler (see below), added it to the options
new CosmosClient(EndPoint, Key, new CosmosClientOptions { CustomHandlers = { new IgnoringSSLErrorsRequestHandler() } });
and guess what, it won’t be called (so I also don’t know if the implementation is correct or does really work).
Expected behavior
Some code example on how it is possible to instantiate an CosmosClient
that will ignore SSL errors.
Actual behavior Nothing is available to work around this problem, except importing the certificate to the windows certificate store, but we need some solution in pure code.
Environment summary SDK Version: 3.6.0 OS Version: Windows
Additional context
internal class IgnoringSSLErrorsRequestHandler : RequestHandler
{
private readonly HttpClient _httpClient;
public IgnoringSSLErrorsRequestHandler()
{
var messageHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true };
_httpClient = new HttpClient(messageHandler);
}
public override async Task<ResponseMessage> SendAsync(RequestMessage request, CancellationToken cancellationToken)
{
var httpRequest = new HttpRequestMessage
{
Method = request.Method,
RequestUri = request.RequestUri,
};
foreach (var headerKey in request.Headers.AllKeys())
{
httpRequest.Headers.Add(headerKey, request.Headers[headerKey]);
}
foreach (var kvp in request.Properties)
{
httpRequest.Properties.Add(kvp);
}
var response = await _httpClient.SendAsync(httpRequest, cancellationToken);
return new ResponseMessage(response.StatusCode, request)
{
Content = await response.Content.ReadAsStreamAsync()
};
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:28 (9 by maintainers)
Top GitHub Comments
I gave up trying to work around the ssl issue, and I am currently trying to get a custom cosmos docker image to work.
Honestly, this has been the biggest waste of dev time in my entire life. The MS Cosmos team should add a
no SSL
config option; just like the rest of the tools we use! You dont have to run mongo, mysql, etc etc locally with a cert… you can if you want to, but it isn’t mandatory. That’s the part that annoys me most; treating developers with kid gloves!I’d really like to NOT import a certificate somewhere. I’d like to use the emulator locally without validating the certificate in my test code. That should really be possible, especially for testing.