Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,20 @@ await Assert.ThrowsAsync<HubException>(
[MemberData(nameof(TransportTypes))]
public async Task RefreshChangingUserIdentifierClosesConnection(HttpTransportType transportType)
{
await using (var server = await StartServer<Startup>())
// Changing the user identifier on refresh aborts the connection on the server. With Long Polling the
// client sends a best-effort DELETE to clean up the connection when it's disposed. That DELETE carries
// the refreshed token (which now maps to a different user) and races the server's teardown: if the
// connection hasn't been removed from the manager yet, the server rejects the DELETE with 403 and the
// transport logs ErrorSendingDeleteRequest. Once the connection has been removed the DELETE gets a 404
// and is treated as benign, so whether the error is logged depends purely on timing. The connection is
// already closed either way (the test asserts that below), so this teardown error is expected.
bool ExpectedErrors(WriteContext writeContext)
{
return writeContext.LoggerName == LongPollingTransportLoggerName &&
writeContext.EventId.Name == "ErrorSendingDeleteRequest";
}

await using (var server = await StartServer<Startup>(ExpectedErrors))
{
// The SignalR UserIdentifier is derived from the JWT NameIdentifier claim, so changing
// the user name on refresh changes the connection's UserIdentifier and should close it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class HubConnectionTestsCollection : ICollectionFixture<InProcessTestServ
public partial class HubConnectionTests : FunctionalTestBase
{
private const string DefaultHubDispatcherLoggerName = "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher";
private const string LongPollingTransportLoggerName = "Microsoft.AspNetCore.Http.Connections.Client.Internal.LongPollingTransport";

private HubConnection CreateHubConnection(
string url,
Expand Down
Loading