【问题标题】:Automating SSL client-side certificates in Firefox and Selenium testing在 Firefox 和 Selenium 测试中自动化 SSL 客户端证书
【发布时间】:2012-06-08 23:39:01
【问题描述】:

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

【问题讨论】:

    标签: firefox ssl selenium webdriver ssl-certificate


    【解决方案1】:

    我不知道这是否有帮助,但您可以更改配置文件中的一些首选项。在 Java 中,您可以这样做。

    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);
    

    我不确定这是你需要的。

    【讨论】:

      【解决方案2】:

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

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

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

      # 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()" 停止测试

      现在您的屏幕上应该有一个 Selenium 的“WebDriver”Firefox 实例。

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

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

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

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

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

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

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

      更多信息

      【讨论】:

      • 从 Firefox 版本 58 开始,它将是 cert9.db 和 key4.db。使用 Visual Studio 确保它们在属性中被标记为“始终复制”,以确保在构建时复制这些文件。
      猜你喜欢
      • 2010-10-16
      • 2010-11-22
      • 1970-01-01
      • 2017-06-01
      • 2012-07-19
      • 1970-01-01
      • 2013-06-20
      • 2013-08-04
      • 2017-04-28
      相关资源
      最近更新 更多