简体   繁体   English

使用TestServer托管ASOS

[英]Hosting ASOS with TestServer

I have an OpenIdDict authentication server which is based on AspNet.Security.OpenIdConnect.Server . 我有一个OpenIdDict身份验证服务器,它基于AspNet.Security.OpenIdConnect.Server The setup works as expected. 设置按预期工作。

Now to do some in process integration;system tests which span the whole backend architecture I use the TestServer class. 现在做一些进程集成;跨越整个后端架构的系统测试我使用TestServer类。

Why I test like this is another question 为什么我这样测试是另一个问题

  • Most test code coverage with least amount of work 大多数测试代码覆盖率最低,工作量最少
  • It has been decided to not do unit tests... (too much work they say) 已决定不进行单元测试......(他们说太多工作)
  • Real integration tests which span much less code where also seen as to much work when I want to achieve a good coverage 真正的集成测试,其中包含更少的代码,当我想要实现良好的覆盖时,也可以看到很多工作
  • The test are based on an framework that is build using a domain language approach which means I can describe functionality the same for our current web api tests, for selenium web ui tests, for selenium load tests and for wpf ui testing. 该测试基于使用域语言方法构建的框架,这意味着我可以为我们当前的web api测试,selenium web ui测试,硒负载测试和wpf ui测试描述相同的功能。

When I call an web api endpoint of my ressource server the authorization wants to load http://localhost/.well-known/openid-configuration but fails. 当我调用我的资源服务器的web api端点时,授权想要加载http://localhost/.well-known/openid-configuration但是失败了。

{"IDX10803: Unable to obtain configuration from: ' http://localhost/.well-known/openid-configuration '."}) {“IDX10803:无法从以下位置获取配置:' http://localhost/.well-known/openid-configuration '。”})

This are the OpenIdConnectSettings I use for the Testing Environment: 这是我用于测试环境的OpenIdConnectSettings:

  • AllowInsecureHttp = true, AllowInsecureHttp = true,
  • RequireHttpsMetadata = false RequireHttpsMetadata = false

Can I get the server to emit the configuration or can I provide the configuration in an other way? 我可以让服务器发出配置,还是可以通过其他方式提供配置?

What's important to note with TestServer is that everything happens in memory: no socket is open to handle the HTTP requests your application might send. 使用TestServer需要注意的是,所有内容都发生在内存中:没有打开套接字来处理应用程序可能发送的HTTP请求。

Unfortunately, the OpenID Connect client middleware (that uses HttpClient internally) has no way to know that and tries to send a "real" HTTP request to OpenIddict to retrieve the discovery document. 不幸的是,OpenID Connect客户端中间件(内部使用HttpClient )无法知道并试图向OpenIddict发送“真实”HTTP请求以检索发现文档。

To work around this issue, the recommended approach is to replace the default backchannel handler used by the OIDC middleware to use the in-memory handler provided by TestServer.CreateHandler() : 要解决此问题,建议的方法是替换OIDC中间件使用的默认反向通道处理程序,以使用TestServer.CreateHandler()提供的内存中处理程序:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    Authority = "http://localhost:54540/",
    RequireHttpsMetadata = false,
    ClientId = "myClient",
    ClientSecret = "secret_secret_secret",
    BackchannelHttpHandler = server.CreateHandler()
});

Note: the same approach also applies to the JWT bearer middleware and the aspnet-contrib introspection middleware. 注意:同样的方法也适用于JWT承载中间件和aspnet-contrib内省中间件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM