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 @@ -82,26 +82,26 @@ public async Task ValidateUserCanSaveAsync(Guid? userId, Send send)

if (disableSendRequirement.DisableSend)
{
throw new BadRequestException("Due to an Enterprise Policy, you are only able to delete an existing Send.");
throw new BadRequestException("Due to an Enterprise policy, you are only able to delete an existing Send.");
}

if (sendOptionsRequirement.DisableHideEmail && send.HideEmail.GetValueOrDefault())
{
throw new BadRequestException(
"Due to an Enterprise Policy, you are not allowed to hide your email address from recipients when creating or editing a Send.");
"Due to an Enterprise policy, you are not allowed to hide your email address from recipients when creating or editing a Send.");
}

var passwordRequired = sendControlsRequirement.WhoCanAccess == SendWhoCanAccessType.PasswordProtected;
var emailsRequired = sendControlsRequirement.WhoCanAccess == SendWhoCanAccessType.SpecificPeople;
if ((passwordRequired && send.Password == null) || (emailsRequired && send.Emails == null))
{
var requiredAccessControl = passwordRequired ? "password" : emailsRequired ? "email verification" : "(cannot determine required auth)";
throw new BadRequestException($"Due to an Enterprise Policy your Sends must be protected by {requiredAccessControl}");
throw new BadRequestException($"Due to an Enterprise policy your Sends must be protected by {requiredAccessControl}");
}

if (emailsRequired && sendControlsRequirement.AllowedDomains != null && !SendAllEmailsHaveAllowedDomains(send.Emails, sendControlsRequirement.AllowedDomains))
{
throw new BadRequestException($"Due to an Enterprise Policy your Sends must be protected by email verification and access granted only to the following domain(s): {sendControlsRequirement.AllowedDomains}");
throw new BadRequestException($"Due to an Enterprise policy your Sends must be protected by email verification and access granted only to the following domain(s): {sendControlsRequirement.AllowedDomains}");
}

if (sendControlsRequirement.AllowedSendTypes != null && !sendControlsRequirement.AllowedSendTypes.Contains(send.Type))
Expand Down
12 changes: 6 additions & 6 deletions test/Core.Test/Tools/Services/NonAnonymousSendCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public async Task SaveSendAsync_DisableSend_Applies_throws(SendType sendType)

// Configure validation service to throw when DisableSend policy applies
_sendValidationService.ValidateUserCanSaveAsync(send.UserId.Value, send)
.Throws(new BadRequestException("Due to an Enterprise Policy, you are only able to delete an existing Send."));
.Throws(new BadRequestException("Due to an Enterprise policy, you are only able to delete an existing Send."));

// Act & Assert
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
_nonAnonymousSendCommand.SaveSendAsync(send));

Assert.Contains("Enterprise Policy", exception.Message);
Assert.Contains("Enterprise policy", exception.Message);

// Verify the validation service was called
await _sendValidationService.Received(1).ValidateUserCanSaveAsync(send.UserId.Value, send);
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task SaveSendAsync_DisableHideEmail_Applies_throws(bool isNewSend)

// Configure validation service to throw when HideEmail policy applies
_sendValidationService.ValidateUserCanSaveAsync(userId, send)
.Throws(new BadRequestException("Due to an Enterprise Policy, you are not allowed to hide your email address from recipients when creating or editing a Send."));
.Throws(new BadRequestException("Due to an Enterprise policy, you are not allowed to hide your email address from recipients when creating or editing a Send."));

// Act & Assert
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
Expand Down Expand Up @@ -250,13 +250,13 @@ public async Task SaveSendAsync_DisableSend_Applies_Throws_vNext(SendType sendTy

// Configure validation service to throw when DisableSend policy applies in vNext implementation
_sendValidationService.ValidateUserCanSaveAsync(userId, send)
.Returns(Task.FromException(new BadRequestException("Due to an Enterprise Policy, you are only able to delete an existing Send.")));
.Returns(Task.FromException(new BadRequestException("Due to an Enterprise policy, you are only able to delete an existing Send.")));

// Act & Assert
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
_nonAnonymousSendCommand.SaveSendAsync(send));

Assert.Contains("Enterprise Policy", exception.Message);
Assert.Contains("Enterprise policy", exception.Message);

// Verify validation service was called
await _sendValidationService.Received(1).ValidateUserCanSaveAsync(userId, send);
Expand Down Expand Up @@ -333,7 +333,7 @@ public async Task SaveSendAsync_DisableHideEmail_Applies_Throws_vNext(bool isNew

// Configure validation service to throw when DisableHideEmail policy applies in vNext implementation
_sendValidationService.ValidateUserCanSaveAsync(userId, send)
.Throws(new BadRequestException("Due to an Enterprise Policy, you are not allowed to hide your email address from recipients when creating or editing a Send."));
.Throws(new BadRequestException("Due to an Enterprise policy, you are not allowed to hide your email address from recipients when creating or editing a Send."));

// Act & Assert
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
Expand Down
6 changes: 3 additions & 3 deletions test/Core.Test/Tools/Services/SendValidationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task ValidateUserCanSaveAsync_WhenPasswordAuthRequiredByPolicy(
.Returns(new SendControlsPolicyRequirement { DisableSend = false, DisableHideEmail = false, WhoCanAccess = SendWhoCanAccessType.PasswordProtected });

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ValidateUserCanSaveAsync(userId, send));
Assert.Equal("Due to an Enterprise Policy your Sends must be protected by password", exception.Message);
Assert.Equal("Due to an Enterprise policy your Sends must be protected by password", exception.Message);
}

[Theory, BitAutoData]
Expand All @@ -228,7 +228,7 @@ public async Task ValidateUserCanSaveAsync_WhenEmailAuthRequiredByPolicy(
.Returns(new SendControlsPolicyRequirement { DisableSend = false, DisableHideEmail = false, WhoCanAccess = SendWhoCanAccessType.SpecificPeople });

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ValidateUserCanSaveAsync(userId, send));
Assert.Equal("Due to an Enterprise Policy your Sends must be protected by email verification", exception.Message);
Assert.Equal("Due to an Enterprise policy your Sends must be protected by email verification", exception.Message);
}

[Theory, BitAutoData]
Expand All @@ -250,7 +250,7 @@ public async Task ValidateUserCanSaveAsync_WhenEmailAuthAndDomainsRequiredByPoli
.Returns(new SendControlsPolicyRequirement { DisableSend = false, DisableHideEmail = false, WhoCanAccess = SendWhoCanAccessType.SpecificPeople, AllowedDomains = "bitwarden.com" });

var exception = await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ValidateUserCanSaveAsync(userId, send));
Assert.Equal("Due to an Enterprise Policy your Sends must be protected by email verification and access granted only to the following domain(s): bitwarden.com", exception.Message);
Assert.Equal("Due to an Enterprise policy your Sends must be protected by email verification and access granted only to the following domain(s): bitwarden.com", exception.Message);
}

[Theory, BitAutoData]
Expand Down
Loading