diff --git a/src/Microsoft.Azure.SignalR.Common/Constants.cs b/src/Microsoft.Azure.SignalR.Common/Constants.cs index 43943a53d..a691ff4be 100644 --- a/src/Microsoft.Azure.SignalR.Common/Constants.cs +++ b/src/Microsoft.Azure.SignalR.Common/Constants.cs @@ -107,7 +107,7 @@ public static class Headers public static class ErrorCodes { - public const string WarningConnectionsNotExisted = "Warning.Connection.NotExisted"; + public const string WarningConnectionNotExisted = "Warning.Connection.NotExisted"; public const string WarningUserNotExisted = "Warning.User.NotExisted"; public const string WarningGroupNotExisted = "Warning.Group.NotExisted"; public const string InfoUserNotInGroup = "Info.User.NotInGroup"; diff --git a/src/Microsoft.Azure.SignalR.Management/RestHubLifetimeManager.cs b/src/Microsoft.Azure.SignalR.Management/RestHubLifetimeManager.cs index 97e44466b..492169437 100644 --- a/src/Microsoft.Azure.SignalR.Management/RestHubLifetimeManager.cs +++ b/src/Microsoft.Azure.SignalR.Management/RestHubLifetimeManager.cs @@ -248,7 +248,7 @@ public async Task CloseConnectionAsync(string connectionId, string reason, Cance throw new ArgumentException(NullOrEmptyStringErrorMessage, nameof(connectionId)); } var api = await _restApiProvider.GetCloseConnectionEndpointAsync(_appName, _hubName, connectionId, reason); - await _restClient.SendAsync(api, HttpMethod.Delete, _productInfo, handleExpectedResponseAsync: null, cancellationToken: cancellationToken); + await _restClient.SendAsync(api, HttpMethod.Delete, _productInfo, handleExpectedResponse: static response => FilterExpectedResponse(response, ErrorCodes.WarningConnectionNotExisted), cancellationToken: cancellationToken); } private static void ValidateUserIdAndGroupName(string userId, string groupName) @@ -275,7 +275,7 @@ public async Task ConnectionExistsAsync(string connectionId, CancellationT await _restClient.SendAsync(api, HttpMethod.Head, _productInfo, handleExpectedResponse: response => { exists = response.StatusCode == HttpStatusCode.OK; - return FilterExpectedResponse(response, ErrorCodes.WarningConnectionsNotExisted); + return FilterExpectedResponse(response, ErrorCodes.WarningConnectionNotExisted); }, cancellationToken: cancellationToken); return exists; } diff --git a/test/Microsoft.Azure.SignalR.E2ETests/Management/ServiceHubContextE2EFacts.cs b/test/Microsoft.Azure.SignalR.E2ETests/Management/ServiceHubContextE2EFacts.cs index eed145752..b2e2129a8 100644 --- a/test/Microsoft.Azure.SignalR.E2ETests/Management/ServiceHubContextE2EFacts.cs +++ b/test/Microsoft.Azure.SignalR.E2ETests/Management/ServiceHubContextE2EFacts.cs @@ -816,6 +816,98 @@ public async Task AddNonexistentConnectionToGroupRestApiTest() await context.Groups.AddToGroupAsync(Guid.NewGuid().ToString(), "group"); } + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task CloseNonexistentConnectionToGroupRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.ClientManager.CloseConnectionAsync(Guid.NewGuid().ToString()); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task RemoveNonexistentConnectionFromGroupRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.Groups.RemoveFromGroupAsync(Guid.NewGuid().ToString(), "group"); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task RemoveNonexistentConnectionFromAllGroupsRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.Groups.RemoveFromAllGroupsAsync(Guid.NewGuid().ToString()); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task AddNonexistentUserToGroupRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.UserGroups.AddToGroupAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task AddNonexistentUserToGroupWithTTLRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.UserGroups.AddToGroupAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), TimeSpan.Zero); + await context.UserGroups.AddToGroupAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), TimeSpan.FromSeconds(1)); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task RemoveNonexistentUserFromGroupRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.UserGroups.RemoveFromGroupAsync(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); + } + + [ConditionalFact] + [SkipIfConnectionStringNotPresent] + public async Task RemoveNonexistentUserFromAllGroupsRestApiTest() + { + using var serviceManager = new ServiceManagerBuilder().WithOptions(o => + { + o.ConnectionString = TestConfiguration.Instance.ConnectionString; + o.ServiceTransportType = ServiceTransportType.Transient; + }).BuildServiceManager(); + using var context = await serviceManager.CreateHubContextAsync(HubName, default); + await context.UserGroups.RemoveFromAllGroupsAsync(Guid.NewGuid().ToString()); + } + private static IDictionary> GenerateUserGroupDict(IList userNames, IList groupNames) { return (from i in Enumerable.Range(0, userNames.Count)