mirror of
https://github.com/bitwarden/server.git
synced 2025-04-04 20:50:21 -05:00
Adjusted Handlers to new repository method names; updated tests to naming convention
This commit is contained in:
parent
f1f0d170fa
commit
df2ebff7a9
@ -63,6 +63,6 @@ public class SlackOAuthController(
|
|||||||
Type = IntegrationType.Slack,
|
Type = IntegrationType.Slack,
|
||||||
Configuration = JsonSerializer.Serialize(new SlackIntegration(token)),
|
Configuration = JsonSerializer.Serialize(new SlackIntegration(token)),
|
||||||
});
|
});
|
||||||
return Ok("Your bot is now installed.");
|
return Ok(integration.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,10 @@ public class SlackEventHandler(
|
|||||||
public async Task HandleEventAsync(EventMessage eventMessage)
|
public async Task HandleEventAsync(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var organizationId = eventMessage.OrganizationId ?? Guid.Empty;
|
var organizationId = eventMessage.OrganizationId ?? Guid.Empty;
|
||||||
var configurations = await configurationRepository.GetConfigurationsAsync(organizationId, IntegrationType.Slack, eventMessage.Type);
|
var configurations = await configurationRepository.GetConfigurationDetailsAsync(
|
||||||
|
organizationId,
|
||||||
|
IntegrationType.Slack,
|
||||||
|
eventMessage.Type);
|
||||||
|
|
||||||
foreach (var configuration in configurations)
|
foreach (var configuration in configurations)
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,10 @@ public class WebhookEventHandler(
|
|||||||
public async Task HandleEventAsync(EventMessage eventMessage)
|
public async Task HandleEventAsync(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var organizationId = eventMessage.OrganizationId ?? Guid.Empty;
|
var organizationId = eventMessage.OrganizationId ?? Guid.Empty;
|
||||||
var configurations = await configurationRepository.GetConfigurationsAsync(organizationId,
|
var configurations = await configurationRepository.GetConfigurationDetailsAsync(
|
||||||
IntegrationType.Webhook, eventMessage.Type);
|
organizationId,
|
||||||
|
IntegrationType.Webhook,
|
||||||
|
eventMessage.Type);
|
||||||
|
|
||||||
foreach (var configuration in configurations)
|
foreach (var configuration in configurations)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ namespace Bit.Api.Test.AdminConsole.Controllers;
|
|||||||
public class SlackOAuthControllerTests
|
public class SlackOAuthControllerTests
|
||||||
{
|
{
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task OAuthCallback_CompletesSuccessfully(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task OAuthCallback_AllParamsProvided_Succeeds(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
var token = "xoxb-test-token";
|
var token = "xoxb-test-token";
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
@ -36,7 +36,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task OAuthCallback_ThrowsBadResultWhenCodeIsEmpty(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task OAuthCallback_CodeIsEmpty_ThrowsBadRequest(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
sutProvider.GetDependency<ICurrentContext>()
|
sutProvider.GetDependency<ICurrentContext>()
|
||||||
@ -47,7 +47,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task OAuthCallback_ThrowsBadResultWhenSlackServiceReturnsEmpty(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task OAuthCallback_SlackServiceReturnsEmpty_ThrowsBadRequest(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
sutProvider.GetDependency<ICurrentContext>()
|
sutProvider.GetDependency<ICurrentContext>()
|
||||||
@ -61,7 +61,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task OAuthCallback_ThrowsNotFoundIfUserIsNotOrganizationAdmin(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task OAuthCallback_UserIsNotOrganizationAdmin_ThrowsNotFound(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
var token = "xoxb-test-token";
|
var token = "xoxb-test-token";
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
@ -76,7 +76,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task Redirect_ShouldRedirectToSlack(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task Redirect_Success(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
var expectedUrl = $"https://localhost/{organizationId}";
|
var expectedUrl = $"https://localhost/{organizationId}";
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task Redirect_ThrowsNotFoundWhenSlackServiceReturnsEmpty(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
public async Task Redirect_SlackServiceReturnsEmpty_ThrowsNotFound(SutProvider<SlackOAuthController> sutProvider, Guid organizationId)
|
||||||
{
|
{
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
sutProvider.GetDependency<ISlackService>().GetRedirectUrl(Arg.Any<string>()).Returns(string.Empty);
|
sutProvider.GetDependency<ISlackService>().GetRedirectUrl(Arg.Any<string>()).Returns(string.Empty);
|
||||||
@ -111,7 +111,7 @@ public class SlackOAuthControllerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task Redirect_ThrowsNotFoundWhenUserIsNotOrganizationAdmin(SutProvider<SlackOAuthController> sutProvider,
|
public async Task Redirect_UserIsNotOrganizationAdmin_ThrowsNotFound(SutProvider<SlackOAuthController> sutProvider,
|
||||||
Guid organizationId)
|
Guid organizationId)
|
||||||
{
|
{
|
||||||
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
sutProvider.Sut.Url = Substitute.For<IUrlHelper>();
|
||||||
|
@ -25,7 +25,7 @@ public class SlackEventHandlerTests
|
|||||||
private SutProvider<SlackEventHandler> GetSutProvider(
|
private SutProvider<SlackEventHandler> GetSutProvider(
|
||||||
List<OrganizationIntegrationConfigurationDetails> integrationConfigurations)
|
List<OrganizationIntegrationConfigurationDetails> integrationConfigurations)
|
||||||
{
|
{
|
||||||
_repository.GetConfigurationsAsync(Arg.Any<Guid>(),
|
_repository.GetConfigurationDetailsAsync(Arg.Any<Guid>(),
|
||||||
IntegrationType.Slack, Arg.Any<EventType>())
|
IntegrationType.Slack, Arg.Any<EventType>())
|
||||||
.Returns(integrationConfigurations);
|
.Returns(integrationConfigurations);
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public class SlackEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleEventAsync_DoesNothingWhenNoConfigurations(EventMessage eventMessage)
|
public async Task HandleEventAsync_NoConfigurations_DoesNothing(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(NoConfigurations());
|
var sutProvider = GetSutProvider(NoConfigurations());
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public class SlackEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleEventAsync_SendsEventViaSlackService(EventMessage eventMessage)
|
public async Task HandleEventAsync_OneConfiguration_SendsEventViaSlackService(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(OneConfiguration());
|
var sutProvider = GetSutProvider(OneConfiguration());
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public class SlackEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleEventAsync_SendsMultipleWhenConfigured(EventMessage eventMessage)
|
public async Task HandleEventAsync_TwoConfigurations_SendsMultipleEvents(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(TwoConfigurations());
|
var sutProvider = GetSutProvider(TwoConfigurations());
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ public class SlackEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleManyEventsAsync_SendsEventsViaSlackService(List<EventMessage> eventMessages)
|
public async Task HandleManyEventsAsync_OneConfiguration_SendsEventsViaSlackService(List<EventMessage> eventMessages)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(OneConfiguration());
|
var sutProvider = GetSutProvider(OneConfiguration());
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ public class SlackEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleManyEventsAsync_SendsMultipleEventsAndMultipleConfigurations(List<EventMessage> eventMessages)
|
public async Task HandleManyEventsAsync_TwoConfigurations_SendsMultipleEvents(List<EventMessage> eventMessages)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(TwoConfigurations());
|
var sutProvider = GetSutProvider(TwoConfigurations());
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class WebhookEventHandlerTests
|
|||||||
clientFactory.CreateClient(WebhookEventHandler.HttpClientName).Returns(_httpClient);
|
clientFactory.CreateClient(WebhookEventHandler.HttpClientName).Returns(_httpClient);
|
||||||
|
|
||||||
var repository = Substitute.For<IOrganizationIntegrationConfigurationRepository>();
|
var repository = Substitute.For<IOrganizationIntegrationConfigurationRepository>();
|
||||||
repository.GetConfigurationsAsync(Arg.Any<Guid>(),
|
repository.GetConfigurationDetailsAsync(Arg.Any<Guid>(),
|
||||||
IntegrationType.Webhook, Arg.Any<EventType>()).Returns(configurations);
|
IntegrationType.Webhook, Arg.Any<EventType>()).Returns(configurations);
|
||||||
|
|
||||||
return new SutProvider<WebhookEventHandler>()
|
return new SutProvider<WebhookEventHandler>()
|
||||||
@ -87,7 +87,7 @@ public class WebhookEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleEventAsync_DoesNothingWhenNoConfigurations(EventMessage eventMessage)
|
public async Task HandleEventAsync_NoConfigurations_DoesNothing(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(NoConfigurations());
|
var sutProvider = GetSutProvider(NoConfigurations());
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class WebhookEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleEventAsync_PostsEventToUrl(EventMessage eventMessage)
|
public async Task HandleEventAsync_OneConfiguration_PostsEventToUrl(EventMessage eventMessage)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(OneConfiguration());
|
var sutProvider = GetSutProvider(OneConfiguration());
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ public class WebhookEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleManyEventsAsync_DoesNothingWhenNoConfigurations(List<EventMessage> eventMessages)
|
public async Task HandleManyEventsAsync_NoConfigurations_DoesNothing(List<EventMessage> eventMessages)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(NoConfigurations());
|
var sutProvider = GetSutProvider(NoConfigurations());
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public class WebhookEventHandlerTests
|
|||||||
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleManyEventsAsync_PostsEventsToUrl(List<EventMessage> eventMessages)
|
public async Task HandleManyEventsAsync_OneConfiguration_PostsEventsToUrl(List<EventMessage> eventMessages)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(OneConfiguration());
|
var sutProvider = GetSutProvider(OneConfiguration());
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ public class WebhookEventHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleManyEventsAsync_PostsEventsToMultipleUrls(List<EventMessage> eventMessages)
|
public async Task HandleManyEventsAsync_TwoConfigurations_PostsEventsToMultipleUrls(List<EventMessage> eventMessages)
|
||||||
{
|
{
|
||||||
var sutProvider = GetSutProvider(TwoConfigurations());
|
var sutProvider = GetSutProvider(TwoConfigurations());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user