WireMock.Net icon indicating copy to clipboard operation
WireMock.Net copied to clipboard

Overriding the default ssl certificate via file.

Open adusak opened this issue 6 years ago • 10 comments

Hey, I have a question regarding the configuration of SSL certificate. As I understand WireMock used to ship with a custom self-signed which was used when setting up https endpoints. Sice .NET Core 3 it relies on the dev certificate created by the SDK toolkit.

My question is whether it is possible to override this configuration a use a custom ssl certificate from a file.

My use-case is for example is CI. We run some builds on build agents but not all of them are correctly configured with the dev certificate. So some of the unit tests can fail. I would like to be able to remove the dependency on the environment and be able to configure the SSL certificate from a file - since importing to cert store is out of the question on the build agent.

Is there some settings I am overlooking?

Thank you for your time and an awesome nuget!

adusak avatar Nov 06 '20 20:11 adusak

Hello @adusak, are you running WireMock.Net as C# in your unit-tests? Or do you use a separate Docker instance?

StefH avatar Nov 07 '20 10:11 StefH

Hey, I am using it in C# unit tests.

adusak avatar Nov 07 '20 10:11 adusak

Hi @adusak,

I've created a fix based on this article: https://devblogs.microsoft.com/aspnet/configuring-https-in-asp-net-core-across-different-platforms/

I've added a new property CertificateSettings on the WireMockServerSettings class.

StefH avatar Nov 07 '20 11:11 StefH

Sorry, please use MyGet version WireMock.Net.1.3.5-ci-13960.nupkg.

See : https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

StefH avatar Nov 07 '20 12:11 StefH

Wow, nice! It works like a charm 🙂 I was actually thinking of doing a PR with something along those lines if the config was missing. Thanks!

adusak avatar Nov 07 '20 16:11 adusak

If you install version WireMock.Net.1.3.5-ci-13964.nupkg : this one has an extra setting "X509StoreThumbprintOrSubjectName" which you can set if you like.

(https://github.com/WireMock-Net/WireMock.Net/blob/certificate/src/WireMock.Net/Settings/IWireMockCertificateSettings.cs#L25)

(needed in case you have multiple localhost certificates defined in your store)

StefH avatar Nov 07 '20 16:11 StefH

See also https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#certificatesettings

StefH avatar Nov 08 '20 09:11 StefH

@adusak Can you do a last final test ?

StefH avatar Nov 10 '20 09:11 StefH

Tested with the WireMock.Net.1.3.5-ci-13964.nupkg version and it still works great!

adusak avatar Nov 10 '20 13:11 adusak

Code is merged to master. A new official NuGet will be ready soon.

StefH avatar Nov 10 '20 15:11 StefH