Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock/create X509Certificate2 for unit testing?

I have handler which creates jwt token with utilization of X509Certificate2. For unit test I need to provide certificate and it is not possible for me take it from the local store. Is there way, how to mock, create or load certificate from the file?

So far I tried BouncingCastle method from this ticket, but with no success. The method ToX509Certificate2() does convert certificate, but without keys. So if this is good way to go, is possible to generate these keys somehow?

Thanks a lot for hints

like image 826
Qerts Avatar asked Aug 24 '16 13:08

Qerts


1 Answers

As Steve suggested, I created my own certificate on the run. I utilised method from this ticket. Certificate is fully functional for purpose of testing.

like image 110
Qerts Avatar answered Oct 19 '22 02:10

Qerts