验证请求Microsoft.Owin.Testing.TestServer [英] Authenticating requests to Microsoft.Owin.Testing.TestServer
问题描述
我使用owin TESTSERVER类进行单元测试我的Web API。它的工作只是我不能确定如何进行身份验证的要求很大,所以我不能要求身份验证的真正测试终点,比其他以确保未经授权的请求未经授权。
I'm using the owin TestServer class to unit test my web api. It's working great except that I'm unsure how to authenticate requests, so I can't really test endpoints that require authentication, other than to make sure that unauthenticated requests are unauthorized.
我配置的WebAPI只使用承载令牌认证,如下所示:
I am configuring WebApi to use only bearer token authentication as indicated here:
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
任何想法我怎么能轻易做到这一点?
Any ideas how I could do this easily?
推荐答案
我发现有用的文档使用TESTSERVER + OAuth认证结果
的http://www.aaron-powell.com/posts/2014-01-12-integration-testing-katana-with-auth.html
I found useful documentation to use TestServer+OAuth authentication
http://www.aaron-powell.com/posts/2014-01-12-integration-testing-katana-with-auth.html
他还提供了整体的解决方案VS在GitHub上。结果
<一href=\"https://github.com/aaronpowell/Owin.AuthenticatedTests/tree/a154931dd82e5180daf7163c2129f3a90401df55\" rel=\"nofollow\">https://github.com/aaronpowell/Owin.AuthenticatedTests/tree/a154931dd82e5180daf7163c2129f3a90401df55
He also provides whole VS solution at GitHub.
https://github.com/aaronpowell/Owin.AuthenticatedTests/tree/a154931dd82e5180daf7163c2129f3a90401df55
这篇关于验证请求Microsoft.Owin.Testing.TestServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!