【问题标题】:Betamax HTTPS Recording with Proxy - Certificate Error - Java GroovyBetamax HTTPS 代理记录 - 证书错误 - Java Groovy
【发布时间】:2016-09-03 16:59:08
【问题描述】:

我无法让 HTTPS URL 与 betamax 一起使用。

这与下面发布的其他问题类似,但是我已经完成了 betamax.pem 文件导入,它似乎没有任何效果:

这是我运行的导入命令:

c:\Users\UserAccount>"%JAVA_HOME%/bin/keytool.exe" -importcert -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -file betamax.pem -alias betamax -storepass changeit -noprompt

这是我的配置:

    static final File TAPES =
    new File(System.getProperty('BETAMAX_TAPEDIR') ?:
        'src/integrationTest/resources/betamax/tapes')

    static final TapeMode TAPEMODE =
    System.getProperty('BETAMAX_MAKETAPES') ?
        TapeMode.READ_WRITE :
        TapeMode.READ_ONLY

    static final Integer PROXYPORT =
    System.getProperty('BETAMAX_PROXYPORT') ?
        System.getProperty('BETAMAX_PROXYPORT').toInteger() :
        Configuration.DEFAULT_PROXY_PORT

    @Shared
    Configuration configuration =  Configuration.builder()
            .tapeRoot(TAPES)
            .ignoreLocalhost(false)
            .defaultMode(TAPEMODE)
            .proxyPort(PROXYPORT)
            .sslEnabled(true)
            .build()

    @Rule
    RecorderRule recorder = new RecorderRule(configuration)

    @Betamax(tape='GradleNews.tape')
    def "Try record HTTPS"()
    {
      when:
      def http = new RESTClient('https://discuss.gradle.org')
      http.head path: 'c/books-articles'

      then:
      true
    }

产生:

javax.net.ssl.SSLException: hostname in certificate didn't match: <discuss.gradle.org> != <*.discourse.org> OR <*.discourse.org> OR <discourse.org>

谁能看出我做错了什么?

以下是类似问题的报告: Betamax fails to record HTTPS traffic

【问题讨论】:

  • 你用的是什么版本?
  • 旁注:我真的很喜欢System.getProperty('BETAMAX_MAKETAPES')。它可爱又有效:)
  • 这似乎是 Betamax 中的一个错误。当我下载discuss.gradle.org 时,它似乎可以正确保存到磁带。但是,在尝试解析 discourse.org 的证书时看到异常向我表明 RESTClient 正在以我们没有正确安装 MITM 的方式寻找 discourse.org。你用的是什么 RESTClient?
  • 感谢 ysb33r 使用系统道具。目前使用HTTPBuilder restclient,但最终想使用okhttp客户端。

标签: groovy spock betamax


【解决方案1】:

总而言之,这个问题的答案是 HTTPBuilder 不尊重 Betamax 实现的自动重定向到代理。这记录在 betamax.software 文档中,我似乎误解了。要使用 HTTPBuilder(或它的 RESTClient 衍生产品),只需手动将 httpclient 上的代理主机/端口分别设置为 127.0.0.1/5555。当使用尊重 JVM 代理设置的 HTTP 客户端时,它似乎可以无缝地工作。

还值得注意的是,错误消息非常具有误导性。使用 RESTClient 时,它似乎指向证书中的一个问题,这让我花了一天时间试图弄清楚为什么它没有在证书存储中看到 betamax 证书。但是,证书没有问题,纯粹是通过手动设置代理来解决的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    相关资源
    最近更新 更多