Testing From Trenches: Hostname Does Not Match The Server Certificate

Image for post
Image for post
Image for post
Image for post

This post is solution how to handle error “Hostname Does Not Match The Server Certificate” in Ruby.

Every SSL certificate has, among other information, signed site domain name. If that domain name does not match actual domain in browser address bar, you will get following error:

hostname "domain name" does not match the server certificate (OpenSSL::SSL::SSLError).

You will get various errors when certificate is not valid. Expired certificate is usual one. If you created self signed certificate for test site, you will get error that certificate root is not valid.

If this is production site, you should leave it immediately. But if this is test site, you want to handle such errors.

If you use Ruby gem httpclient, with following code you can handle this error:

http_client = HTTPClient.new { self.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE }

Originally published at https://blog.tentamen.eu on June 5, 2019.

Written by

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store