在 Firefox 和 Selenium 测试中自动化 SSL 客户端证书 [英] Automating SSL client-side certificates in Firefox and Selenium testing

查看:41
本文介绍了在 Firefox 和 Selenium 测试中自动化 SSL 客户端证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 Selenium 和任何浏览器测试客户端 SSL 证书?例如.您可以创建一个 Web 驱动程序并为其提供虚拟证书吗?还是使用准备好的 Firefox 配置文件?

Is it possible to test client side SSL certificates with Selenium and any browser? E.g. Can you create a web driver and give dummy certificates for it? Or use a prepared Firefox profile?

推荐答案

为 SSL 客户端证书创建 Selenium Firefox 测试配置文件

您需要准备 Selenium 的 WebDriver Firefox 配置文件,其中已导入客户端证书.

You need to prepare Selenium's WebDriver Firefox profile which has client certificates imported in.

首先,您在测试代码中使用以下配置启动 WebDriver:

First you launch WebDriver with the following configuration in your 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

启动单元测试并将它们驱动到 Zope 测试服务器启动.使用 "import pdb ; pdb.set_trace()" 停止测试

Start unit tests and drive them to the point Zope test server is up. Stop tests with "import pdb ; pdb.set_trace()"

现在您的屏幕上应该有一个 Selenium 的WebDriver"Firefox 实例.

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

导入您的客户端证书.首选项 > 高级 > 加密 > 查看证书.从您的客户端证书供应中导入client.p12".

Import your client side certificate. Preferences > Advanced > Encryption > View certificates. Import "client.p12" from your client-side certificate supply.

访问在Webdriver的Firefox中触发客户端证书对话框的URL::

Visit in the URL triggering the client-side certificate dialog in Webdriver's Firefox::

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

这应该会提示您接受针对测试服务器的客户端证书.手动接受所有内容.

This should prompt you to accept the client side certificate against the test server. Accept everything manually.

访问菜单帮助 > 故障排除信息 > 应用程序基础 > 在 Finder 中显示.这将打开保存 Webdriver 的活动配置文件的临时目录.

Visit in menu Help > Troubleshooting Information > Application Basics > Show in Finder. This opens the temporary directory holding Webdriver's active profile files.

将 Firefox 配置文件 cert8.dbkey3.db 复制到您的单元测试包WebDriver 的 Firefox 配置文件的种子文件夹.这是 Selenium 为其挑选种子的文件夹测试开始时的 Firefox Web 驱动程序 firefox-client-ssl-profile.

Copy Firefox profile files cert8.db and key3.db to your unit test package WebDriver's Firefox profile's seed folder. This is the folder where Selenium picks seeds for Firefox web driver when the test starts firefox-client-ssl-profile.

中断测试.重新开始测试.再次运行直到暂停.在 Webdriver 的 Firefox 中在设置中查看它现在包含您在上次运行时批准的证书在首选项 > 高级 > 加密 > 查看证书.

Interrupt the tests. Restart the tests. Run until the pause again. In Webdriver's Firefox see in the settings that it now contains the certificates you did approve on the last run in Preferences > Advanced > Encryption > View certificates.

更多信息

https://support.mozilla.org/en-US/问题/824255

http://wiki.apache.org/httpd/DebuggingSSLProblems#Finding_out_what_caused_a_handshake_to_fail

http://www.openssl.org/docs/apps/s_client.html

https://omni.tenderapp.com/kb/omni-certificate-authorities/importing-pkcs12-certificates-in-keychain-for-safarichrome-in-mac-os-x

http://support.mozilla.org/en-US/kb/Recovering%20important%20data%20from%20an%20old%20profile#w_security-certificate-settings"""

这篇关于在 Firefox 和 Selenium 测试中自动化 SSL 客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆