协商身份验证和 Microsoft.AspNetCore.Mvc.Testing
Negotiate authentication and Microsoft.AspNetCore.Mvc.Testing
docs.microsoft.com recommends to use Microsoft.AspNetCore.Mvc.Testing for integration tests and it seems to be a great choice, but it seems that they missed to add the ability to test with NegotiateDefaults.AuthenticationScheme.
添加到启动。cs/ConfigureServices
services.AddAuthentication (NegotiateDefaults.AuthenticationScheme).AddNegotiate ();
导致测试失败
Message:
System.NotSupportedException : Negotiate authentication requires a server that supports IConnectionItemsFeature like Kestrel.
有人知道如何将 Microsoft.AspNetCore.Mvc.Testing 与使用 NegotiateDefaults.AuthenticationScheme 的端点一起使用吗?它只是不受支持,就像异常声明一样吗?
我放弃了 Microsoft.AspNetCore.Mvc.Testing 并改用自定义 NUnit 基础 class:
public class AspNetCoreIntegrationTestBase {
public CancellationTokenSource CancellationTokenSource {
get;
private set;
}
public Task TestWebserver {
get;
private set;
}
[OneTimeSetUp]
public void Setup() {
CancellationTokenSource = new CancellationTokenSource();
TestWebserver = Program.CreateHostBuilder(new string[0]).Build().StartAsync(CancellationTokenSource.Token);
}
[OneTimeTearDown]
public void CleanUp() {
CancellationTokenSource.Cancel();
TestWebserver.Dispose();
}
}
要使用的httpclient需要用
初始化
UseDefaultCredentials = true
docs.microsoft.com recommends to use Microsoft.AspNetCore.Mvc.Testing for integration tests and it seems to be a great choice, but it seems that they missed to add the ability to test with NegotiateDefaults.AuthenticationScheme.
添加到启动。cs/ConfigureServices
services.AddAuthentication (NegotiateDefaults.AuthenticationScheme).AddNegotiate ();
导致测试失败
Message: System.NotSupportedException : Negotiate authentication requires a server that supports IConnectionItemsFeature like Kestrel.
有人知道如何将 Microsoft.AspNetCore.Mvc.Testing 与使用 NegotiateDefaults.AuthenticationScheme 的端点一起使用吗?它只是不受支持,就像异常声明一样吗?
我放弃了 Microsoft.AspNetCore.Mvc.Testing 并改用自定义 NUnit 基础 class:
public class AspNetCoreIntegrationTestBase {
public CancellationTokenSource CancellationTokenSource {
get;
private set;
}
public Task TestWebserver {
get;
private set;
}
[OneTimeSetUp]
public void Setup() {
CancellationTokenSource = new CancellationTokenSource();
TestWebserver = Program.CreateHostBuilder(new string[0]).Build().StartAsync(CancellationTokenSource.Token);
}
[OneTimeTearDown]
public void CleanUp() {
CancellationTokenSource.Cancel();
TestWebserver.Dispose();
}
}
要使用的httpclient需要用
初始化UseDefaultCredentials = true