在Firefox和Selenium测试中自动执行SSL客户端证书 [英] Automating SSL client-side certificates in Firefox and Selenium testing
问题描述
是否可以使用Selenium和任何浏览器来测试客户端SSL证书?例如。你可以创建一个网络驱动程序,并给它虚拟证书?或者使用准备好的Firefox配置文件?
为SSL客户端证书创建Selenium Firefox测试配置文件
您需要准备Selenium的WebDriver Firefox配置文件,其中已经导入了客户端证书。 首先,启动WebDriver在你的测试代码中配置如下:
$ p $ #预先播种的Firefox配置文件目录
profile_diretory = os.path.join (os.path.dirname(__ file__),..,..,certs,firefox-client-ssl-profile)
self.assertTrue(os.path.exists(profile_diretory) )
$ b $ profile = FirefoxProfile(profile_diretory)
#确保客户端的证书选择不会中断测试
#XXX:在其他语言版本中会发生什么?
profile.set_preference(security.default_personal_cert,自动选择)
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()测试
现在你的屏幕上应该有一个Selenium的WebDriverFirefox实例。
导入您的客户端证书。首选项>高级>加密>查看证书。
从您的客户端证书提供中导入client.p12。
访问Webdriver的Firefox中的客户端证书对话框的URL: / b>
https:// yourservevr / triggers-client-side-certificate-ssl-handshake
这会提示您接受针对测试服务器的客户端证书。
手动接受所有内容。
访问菜单帮助>故障排除信息>应用程序基础>在Finder中显示。
这将打开保存Webdriver的活动配置文件的临时目录。
$ b 复制Firefox配置文件
cert8.db
和 key3.db
到您的单元测试包WebDriver的Firefox配置文件的种子文件夹。这是Selenium在测试开始时为
Firefox网络驱动程序挑选种子的文件夹。
firefox-client-ssl-profile
。 中断测试。重新启动测试。运行,直到再次停顿。在Webdriver的Firefox
中,请参阅它现在包含您在最后一次运行中认可的证书的设置
,在首选项>高级>加密>查看证书。
更多信息
- mozilla.org/en-US/questions/824255\">https://support.mozilla.org/en-US/questions/824255
-
http://wiki.apache.org/httpd/DebuggingSSLProblems#Finding_out_what_caused_a_handshake_to_fail
< li>< http://support.mozilla.org/en-US/kb/Recovering%20important%20data%20from%20an%20old%20profile#w_security-certificate-settings
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?
Creating Selenium Firefox test profile for SSL client-side certificates
You need to prepare Selenium's WebDriver Firefox profile whichh has client certificates imported in.
First you launch WebDriver with the following configuration in your test code:
# Pre-seeded Firefox profile directory
profile_diretory = os.path.join(os.path.dirname(__file__), "..", "..", "certs", "firefox-client-ssl-profile")
self.assertTrue(os.path.exists(profile_diretory))
profile = FirefoxProfile(profile_diretory)
# Make sure the client side cert seletion 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 drive them to the point Zope test server is up. Stop tests with "import pdb ; pdb.set_trace()"
You should now have a Selenium's "WebDriver" Firefox instance on your screen.
Import your client side certificate. Preferences > Advanced > Encryption > View certificates. Import "client.p12" from your client-side certificate supply.
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.
Visit in menu Help > Troubleshooting Information > Application Basics > Show in Finder. This opens the temporary directory holding Webdriver's active profile files.
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
.
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.
More info
这篇关于在Firefox和Selenium测试中自动执行SSL客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!