Client side SSL certificate automation in Firefox and Selenium tests

Is it possible to test client-side SSL certificates using Selenium and any browser? For example. Can you create a web driver and provide dummy certificates for it? Or use a prepared Firefox profile?

+7
source share
2 answers

Creating a Selenium Firefox test profile for SSL client-side certificates

You need to prepare a Selenium WebDriver Firefox profile into which there are imported client certificates.

First, you start WebDriver with the following configuration in the test code:

# Pre-seeded Firefox profile directory profile_directory = os.path.join(os.path.dirname(__file__), "..", "..", "certs", "firefox-client-ssl-profile") self.assertTrue(os.path.exists(profile_directory)) profile = FirefoxProfile(profile_directory) # Make sure the client side certificate selection does not interrupt the test # XXX: What happens in other language versions? profile.set_preference("security.default_personal_cert", "Select Automatically") self.driver = WebDriver(firefox_profile=profile) self.selenium_helper = SeleniumHelper(self, self.driver) self.selenium_helper.driver = self.driver 

Start unit tests and bring them to the testing point of the Zope test server. Stop the tests with "import pdb; pdb.set_trace ()"

You should now have a Firefox Selenium "WebDriver" instance on screen.

Import the client side certificate. Settings> Advanced> Encryption> View certificates. Import "client.p12" from your client certificate.

Visiting the URL launching the client certificate dialog box in Webdriver Firefox ::

  https://yourservevr/triggers-client-side-certificate-ssl-handshake 

This should encourage you to accept the client side certificate on the test server. Take it all by hand.

Go to Help> Troubleshooting Information> Application Basics> Show in Finder. This opens a temporary directory containing active Webdriver profile files.

Copy the Firefox profile files cert8.db and key3.db to the unit test WebDriver Firefox package. This is the folder in which Selenium selects seeds for the Firefox web driver when running the firefox-client-ssl-profile test.

Abort tests. Restart the tests. Run before pause. In Webdriver Firefox, see the settings, which now contain the certificates that you approved the last time you started in Settings> Advanced> Encryption> View certificates.

Additional Information

+12
source

I do not know if this will help, but you can change some settings in the profile. In Java you can do this.

 ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); //change profile name. there is a note somewhere on how to change it profile.setPreference(uaKey, uaValue); profile.setAcceptUntrustedCertificates(acceptUntrustedSsl); 

I'm not sure if this is what you need.

+1
source

All Articles