首页 > 解决方案 > 测试用例在带有 https 的 docker windows 控制台中失败 vstest.console.exe

问题描述

我正在使用带有 Nunit 的 restsharp 运行 API 测试,并且测试用例vstest.console.exe在 docker windows 中失败,得到“0”作为响应。在本地系统上传递时。

我正在从 docker 容器中访问 https 应用程序。

这是因为 SSL 证书,我用 HTTP 请求验证它按预期工作。

验证我使用的连接

invoke-WebRequest -UseBasicParsing https://hostname

并在容器中收到此错误

invoke-WebRequest :底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。

当我使用invoke-WebRequest -UseBasicParsing http://hostname时,我得到 200 个状态码。

标签: c#.netwindowspowershelldocker

解决方案


此问题与 vstest.console.exe 无关。这个问题是因为 SSL/TLS。由于 CA(证书颁发机构),该容器无法与我的应用程序建立 https 连接。

当我将 CA 导入我的容器时,一切都按预期工作。要导入证书,我使用了 PowerShell 命令

Import-Certificate -FilePath "file.cer" -CertStoreLocation Cert:\\LocalMachine\\Root

推荐阅读