2023-11-22 22:07:37 +01:00
using Bit.Core.AdminConsole.Entities ;
using Bit.Core.AdminConsole.Enums ;
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies ;
2024-10-24 17:13:45 +02:00
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationDomains.Interfaces ;
2024-10-16 11:33:00 +02:00
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces ;
2023-11-22 22:07:37 +01:00
using Bit.Core.AdminConsole.Repositories ;
using Bit.Core.AdminConsole.Services.Implementations ;
using Bit.Core.Auth.Entities ;
2023-05-10 21:52:08 +02:00
using Bit.Core.Auth.Enums ;
2023-04-14 19:25:56 +02:00
using Bit.Core.Auth.Models.Data ;
using Bit.Core.Auth.Repositories ;
2024-10-09 16:32:49 +02:00
using Bit.Core.Auth.UserFeatures.TwoFactorAuth.Interfaces ;
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
using Bit.Core.Enums ;
2021-06-11 17:33:32 +02:00
using Bit.Core.Exceptions ;
2023-05-12 09:22:19 +02:00
using Bit.Core.Models.Data.Organizations.OrganizationUsers ;
2021-06-11 17:33:32 +02:00
using Bit.Core.Repositories ;
using Bit.Core.Services ;
Postgres & MySql Support For Self-Hosted Installations (#1386)
* EF Database Support Init (#1221)
* scaffolding for ef support
* deleted old postgres repos
* added tables to oncreate
* updated all the things to .NET 5
* Addition to #1221: Migrated DockerFiles from dotnet/3.1 to 5.0 (#1223)
* Migrated DockerFiles from dotnet/3.1 to 5.0
* Migrated SSO/Dockerfile from dotnet 3.1 to 5.0
Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
* EFDatabaseSupport: Updated links and description in README.md and SETUP.md (#1232)
* Updated requirements in README.md
* Updated link to documentation of app-secrets
* upgraded dotnet version to 5.0
* Ef database support implementation examples (#1265)
* mostly finished testing the user repo
* finished testing user repo
* finished org, user, ssoconfig, and ssouser ef implementations
* removed unused prop
* fixed a sql file
* fixed a spacing issue
* fixed a spacing issue
* removed extra database creation
* refactoring
* MsSql => SqlServer
* refactoring
* code review fixes
* build fix
* code review
* continued attempts to fix the the build
* skipped another test
* finished all create test
* initial pass at several repos
* continued building out repos
* initial pass at several repos
* initial pass at device repo
* initial pass at collection repo
* initial run of all Entity Framework implementations
* signup, signin, create/edit ciphers works
* sync working
* all web vault pages seem to load with 100% 200s
* bulkcopy, folders, and favorites
* group and collection management
* sso, groups, emergency access, send
* get basic creates matching on all repos
* got everything building again post merge
* removed some IDE config files
* cleanup
* no more notimplemented methods in the cipher repo
* no more not implementeds everywhere
* cleaned up schema/navigation properties and fixed tests
* removed a sql comment that was written in c# style
* fixed build issues from merge
* removed unsupported db providers
* formatting
* code review refactors
* naming cleanup for queries
* added provider methods
* cipher repo cleanup
* implemented several missing procedures from the EF implementation surround account revision dates, keys, and storage
* fixed the build
* added a null check
* consolidated some cipher repo methods
* formatting fix
* cleaned up indentation of queries
* removed .idea file
* generated postgres migrations
* added mysql migrations
* formatting
* Bug Fixes & Formatting
* Formatting
* fixed a bug with bulk import when using MySql
* code review fixes
* fixed the build
* implemented new methods
* formatting
* fixed the build
* cleaned up select statements in ef queries
* formatting
* formatting
* formatting
Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
2021-07-08 18:35:48 +02:00
using Bit.Test.Common.AutoFixture ;
using Bit.Test.Common.AutoFixture.Attributes ;
2021-06-11 17:33:32 +02:00
using NSubstitute ;
using Xunit ;
2023-11-22 22:07:37 +01:00
using AdminConsoleFixtures = Bit . Core . Test . AdminConsole . AutoFixture ;
2023-05-12 09:22:19 +02:00
using GlobalSettings = Bit . Core . Settings . GlobalSettings ;
2021-06-11 17:33:32 +02:00
2023-11-22 22:07:37 +01:00
namespace Bit.Core.Test.AdminConsole.Services ;
2022-08-29 22:06:55 +02:00
2021-06-11 17:33:32 +02:00
[SutProviderCustomize]
public class PolicyServiceTests
{
[Theory, BitAutoData]
public async Task SaveAsync_OrganizationDoesNotExist_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.DisableSend)] Policy policy , SutProvider < PolicyService > sutProvider )
2021-06-11 17:33:32 +02:00
{
SetupOrg ( sutProvider , policy . OrganizationId , null ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Organization not found" , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
}
2022-06-08 15:44:28 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_OrganizationCannotUsePolicies_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.DisableSend)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
var orgId = Guid . NewGuid ( ) ;
2022-08-29 22:06:55 +02:00
2021-06-11 17:33:32 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
{
UsePolicies = false ,
} ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "cannot use policies" , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
2022-08-29 22:06:55 +02:00
}
2021-06-11 17:33:32 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_SingleOrg_RequireSsoEnabled_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.SingleOrg)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
policy . Enabled = false ;
2022-06-08 15:44:28 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-06-11 17:33:32 +02:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
sutProvider . GetDependency < IPolicyRepository > ( )
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . RequireSso )
. Returns ( Task . FromResult ( new Policy { Enabled = true } ) ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
2022-01-11 10:40:51 +01:00
Guid . NewGuid ( ) ) ) ;
2021-06-11 17:33:32 +02:00
Assert . Contains ( "Single Sign-On Authentication policy is enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
2022-08-29 22:06:55 +02:00
}
2021-06-11 17:33:32 +02:00
[Theory, BitAutoData]
2023-11-22 22:07:37 +01:00
public async Task SaveAsync_SingleOrg_VaultTimeoutEnabled_ThrowsBadRequest ( [ AdminConsoleFixtures . Policy ( PolicyType . SingleOrg ) ] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
policy . Enabled = false ;
2022-01-11 10:40:51 +01:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-11-08 14:37:40 +01:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
2022-08-29 20:53:16 +02:00
2021-11-08 14:37:40 +01:00
sutProvider . GetDependency < IPolicyRepository > ( )
2023-11-22 22:07:37 +01:00
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . MaximumVaultTimeout )
2021-11-08 14:37:40 +01:00
. Returns ( new Policy { Enabled = true } ) ;
2022-08-29 22:06:55 +02:00
2021-11-08 14:37:40 +01:00
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
2022-08-29 22:06:55 +02:00
2021-11-08 14:37:40 +01:00
Assert . Contains ( "Maximum Vault Timeout policy is enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
2022-08-29 22:06:55 +02:00
2021-11-09 16:37:32 +01:00
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
2021-11-08 14:37:40 +01:00
. UpsertAsync ( default ) ;
}
2022-08-29 22:06:55 +02:00
[Theory]
2022-06-08 15:44:28 +02:00
[BitAutoData(PolicyType.SingleOrg)]
[BitAutoData(PolicyType.RequireSso)]
2021-11-15 10:25:10 +01:00
public async Task SaveAsync_PolicyRequiredByKeyConnector_DisablePolicy_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
PolicyType policyType ,
2021-11-15 10:25:10 +01:00
Policy policy ,
2021-11-09 16:37:32 +01:00
SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-11-09 16:37:32 +01:00
policy . Enabled = false ;
2021-11-15 10:25:10 +01:00
policy . Type = policyType ;
2021-11-08 14:37:40 +01:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-11-09 16:37:32 +01:00
{
Id = policy . OrganizationId ,
2021-11-15 10:25:10 +01:00
UsePolicies = true ,
} ) ;
2021-11-09 16:37:32 +01:00
2021-11-17 11:46:35 +01:00
var ssoConfig = new SsoConfig { Enabled = true } ;
2023-05-10 21:52:08 +02:00
var data = new SsoConfigurationData { MemberDecryptionType = MemberDecryptionType . KeyConnector } ;
2021-11-09 16:37:32 +01:00
ssoConfig . SetData ( data ) ;
2021-11-17 11:46:35 +01:00
sutProvider . GetDependency < ISsoConfigRepository > ( )
. GetByOrganizationIdAsync ( policy . OrganizationId )
2021-11-09 16:37:32 +01:00
. Returns ( ssoConfig ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Key Connector is enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
2021-11-15 10:25:10 +01:00
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
2022-08-29 22:06:55 +02:00
}
2021-11-08 14:37:40 +01:00
[Theory, BitAutoData]
public async Task SaveAsync_RequireSsoPolicy_NotEnabled_ThrowsBadRequestAsync (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.RequireSso)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-11-08 14:37:40 +01:00
policy . Enabled = true ;
2022-06-08 15:44:28 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-06-11 17:33:32 +02:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
sutProvider . GetDependency < IPolicyRepository > ( )
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . SingleOrg )
. Returns ( Task . FromResult ( new Policy { Enabled = false } ) ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
2022-01-11 10:40:51 +01:00
Guid . NewGuid ( ) ) ) ;
2021-06-11 17:33:32 +02:00
Assert . Contains ( "Single Organization policy not enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
2022-08-29 22:06:55 +02:00
}
2021-06-11 17:33:32 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_NewPolicy_Created (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.ResetPassword)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
policy . Id = default ;
2023-06-07 10:56:31 +02:00
policy . Data = null ;
2021-06-11 17:33:32 +02:00
2022-06-10 01:57:56 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-06-11 17:33:32 +02:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
2023-07-18 17:00:49 +02:00
sutProvider . GetDependency < IPolicyRepository > ( )
2023-11-22 22:07:37 +01:00
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . SingleOrg )
2023-07-18 17:00:49 +02:00
. Returns ( Task . FromResult ( new Policy { Enabled = true } ) ) ;
2021-06-11 17:33:32 +02:00
var utcNow = DateTime . UtcNow ;
2024-10-22 11:38:01 +02:00
await sutProvider . Sut . SaveAsync ( policy , Guid . NewGuid ( ) ) ;
2021-06-11 17:33:32 +02:00
await sutProvider . GetDependency < IEventService > ( ) . Received ( )
. LogPolicyEventAsync ( policy , EventType . Policy_Updated ) ;
await sutProvider . GetDependency < IPolicyRepository > ( ) . Received ( )
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
. UpsertAsync ( policy ) ;
2021-06-11 17:33:32 +02:00
Assert . True ( policy . CreationDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
Assert . True ( policy . RevisionDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
2022-08-29 22:06:55 +02:00
}
2021-06-11 17:33:32 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_VaultTimeoutPolicy_NotEnabled_ThrowsBadRequestAsync (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.MaximumVaultTimeout)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
policy . Enabled = true ;
2022-06-08 15:44:28 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
2021-11-08 14:37:40 +01:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
sutProvider . GetDependency < IPolicyRepository > ( )
2023-11-22 22:07:37 +01:00
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . SingleOrg )
2021-11-08 14:37:40 +01:00
. Returns ( Task . FromResult ( new Policy { Enabled = false } ) ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
2022-01-11 10:40:51 +01:00
Guid . NewGuid ( ) ) ) ;
2021-11-08 14:37:40 +01:00
Assert . Contains ( "Single Organization policy not enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
2022-08-29 22:06:55 +02:00
}
2021-11-08 14:37:40 +01:00
[Theory, BitAutoData]
public async Task SaveAsync_ExistingPolicy_UpdateTwoFactor (
2024-03-21 13:07:13 +01:00
Organization organization ,
[AdminConsoleFixtures.Policy(PolicyType.TwoFactorAuthentication)] Policy policy ,
SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-11-08 14:37:40 +01:00
// If the policy that this is updating isn't enabled then do some work now that the current one is enabled
2024-03-21 13:07:13 +01:00
organization . UsePolicies = true ;
policy . OrganizationId = organization . Id ;
2021-06-11 17:33:32 +02:00
2024-03-21 13:07:13 +01:00
SetupOrg ( sutProvider , organization . Id , organization ) ;
2022-08-29 22:06:55 +02:00
2021-06-11 17:33:32 +02:00
sutProvider . GetDependency < IPolicyRepository > ( )
. GetByIdAsync ( policy . Id )
. Returns ( new Policy
{
Id = policy . Id ,
Type = PolicyType . TwoFactorAuthentication ,
2024-03-21 13:07:13 +01:00
Enabled = false
2021-06-11 17:33:32 +02:00
} ) ;
2022-08-29 22:06:55 +02:00
2024-03-21 13:07:13 +01:00
var orgUserDetailUserInvited = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Invited ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "user1@test.com" ,
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = false
} ;
var orgUserDetailUserAcceptedWith2FA = new OrganizationUserUserDetails
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Accepted ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
2024-03-21 13:07:13 +01:00
Email = "user2@test.com" ,
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = true
} ;
var orgUserDetailUserAcceptedWithout2FA = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Accepted ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "user3@test.com" ,
2021-06-11 17:33:32 +02:00
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
2024-03-21 13:07:13 +01:00
HasMasterPassword = true
} ;
var orgUserDetailAdmin = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . Admin ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "admin@test.com" ,
Name = "ADMIN" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = false
2021-06-11 17:33:32 +02:00
} ;
2022-08-29 22:06:55 +02:00
2021-06-11 17:33:32 +02:00
sutProvider . GetDependency < IOrganizationUserRepository > ( )
. GetManyDetailsByOrganizationAsync ( policy . OrganizationId )
2024-03-21 13:07:13 +01:00
. Returns ( new List < OrganizationUserUserDetails >
2021-06-11 17:33:32 +02:00
{
2024-03-21 13:07:13 +01:00
orgUserDetailUserInvited ,
orgUserDetailUserAcceptedWith2FA ,
orgUserDetailUserAcceptedWithout2FA ,
orgUserDetailAdmin
2021-06-11 17:33:32 +02:00
} ) ;
2024-10-09 16:32:49 +02:00
sutProvider . GetDependency < ITwoFactorIsEnabledQuery > ( )
. TwoFactorIsEnabledAsync ( Arg . Any < IEnumerable < OrganizationUserUserDetails > > ( ) )
. Returns ( new List < ( OrganizationUserUserDetails user , bool hasTwoFactor ) > ( )
{
( orgUserDetailUserInvited , false ) ,
( orgUserDetailUserAcceptedWith2FA , true ) ,
( orgUserDetailUserAcceptedWithout2FA , false ) ,
( orgUserDetailAdmin , false ) ,
} ) ;
2021-06-11 17:33:32 +02:00
2024-10-16 11:33:00 +02:00
var removeOrganizationUserCommand = sutProvider . GetDependency < IRemoveOrganizationUserCommand > ( ) ;
2021-06-11 17:33:32 +02:00
var utcNow = DateTime . UtcNow ;
var savingUserId = Guid . NewGuid ( ) ;
2024-10-22 11:38:01 +02:00
await sutProvider . Sut . SaveAsync ( policy , savingUserId ) ;
2021-06-11 17:33:32 +02:00
2024-10-16 11:33:00 +02:00
await removeOrganizationUserCommand . Received ( )
2024-09-04 12:18:23 +02:00
. RemoveUserAsync ( policy . OrganizationId , orgUserDetailUserAcceptedWithout2FA . Id , savingUserId ) ;
2021-06-11 17:33:32 +02:00
await sutProvider . GetDependency < IMailService > ( ) . Received ( )
2024-03-21 13:07:13 +01:00
. SendOrganizationUserRemovedForPolicyTwoStepEmailAsync ( organization . DisplayName ( ) , orgUserDetailUserAcceptedWithout2FA . Email ) ;
2024-10-16 11:33:00 +02:00
await removeOrganizationUserCommand . DidNotReceive ( )
2024-09-04 12:18:23 +02:00
. RemoveUserAsync ( policy . OrganizationId , orgUserDetailUserInvited . Id , savingUserId ) ;
2024-03-21 13:07:13 +01:00
await sutProvider . GetDependency < IMailService > ( ) . DidNotReceive ( )
. SendOrganizationUserRemovedForPolicyTwoStepEmailAsync ( organization . DisplayName ( ) , orgUserDetailUserInvited . Email ) ;
2024-10-16 11:33:00 +02:00
await removeOrganizationUserCommand . DidNotReceive ( )
2024-09-04 12:18:23 +02:00
. RemoveUserAsync ( policy . OrganizationId , orgUserDetailUserAcceptedWith2FA . Id , savingUserId ) ;
2024-03-21 13:07:13 +01:00
await sutProvider . GetDependency < IMailService > ( ) . DidNotReceive ( )
. SendOrganizationUserRemovedForPolicyTwoStepEmailAsync ( organization . DisplayName ( ) , orgUserDetailUserAcceptedWith2FA . Email ) ;
2024-10-16 11:33:00 +02:00
await removeOrganizationUserCommand . DidNotReceive ( )
2024-09-04 12:18:23 +02:00
. RemoveUserAsync ( policy . OrganizationId , orgUserDetailAdmin . Id , savingUserId ) ;
2024-03-21 13:07:13 +01:00
await sutProvider . GetDependency < IMailService > ( ) . DidNotReceive ( )
. SendOrganizationUserRemovedForPolicyTwoStepEmailAsync ( organization . DisplayName ( ) , orgUserDetailAdmin . Email ) ;
2021-06-11 17:33:32 +02:00
await sutProvider . GetDependency < IEventService > ( ) . Received ( )
. LogPolicyEventAsync ( policy , EventType . Policy_Updated ) ;
await sutProvider . GetDependency < IPolicyRepository > ( ) . Received ( )
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
. UpsertAsync ( policy ) ;
2021-06-11 17:33:32 +02:00
Assert . True ( policy . CreationDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
Assert . True ( policy . RevisionDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
2022-08-29 22:06:55 +02:00
}
2021-06-11 17:33:32 +02:00
2024-03-21 13:07:13 +01:00
[Theory, BitAutoData]
public async Task SaveAsync_EnableTwoFactor_WithoutMasterPasswordOr2FA_ThrowsBadRequest (
Organization organization ,
[AdminConsoleFixtures.Policy(PolicyType.TwoFactorAuthentication)] Policy policy ,
SutProvider < PolicyService > sutProvider )
{
organization . UsePolicies = true ;
policy . OrganizationId = organization . Id ;
SetupOrg ( sutProvider , organization . Id , organization ) ;
var orgUserDetailUserWith2FAAndMP = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "user1@test.com" ,
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = true
} ;
var orgUserDetailUserWith2FANoMP = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "user2@test.com" ,
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = false
} ;
var orgUserDetailUserWithout2FA = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "user3@test.com" ,
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = false
} ;
var orgUserDetailAdmin = new OrganizationUserUserDetails
{
Id = Guid . NewGuid ( ) ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . Admin ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Email = "admin@test.com" ,
Name = "ADMIN" ,
UserId = Guid . NewGuid ( ) ,
HasMasterPassword = false
} ;
sutProvider . GetDependency < IOrganizationUserRepository > ( )
. GetManyDetailsByOrganizationAsync ( policy . OrganizationId )
. Returns ( new List < OrganizationUserUserDetails >
{
orgUserDetailUserWith2FAAndMP ,
orgUserDetailUserWith2FANoMP ,
orgUserDetailUserWithout2FA ,
orgUserDetailAdmin
} ) ;
2024-10-09 16:32:49 +02:00
sutProvider . GetDependency < ITwoFactorIsEnabledQuery > ( )
. TwoFactorIsEnabledAsync ( Arg . Is < IEnumerable < Guid > > ( ids = >
ids . Contains ( orgUserDetailUserWith2FANoMP . UserId . Value )
& & ids . Contains ( orgUserDetailUserWithout2FA . UserId . Value )
& & ids . Contains ( orgUserDetailAdmin . UserId . Value ) ) )
. Returns ( new List < ( Guid userId , bool hasTwoFactor ) > ( )
{
( orgUserDetailUserWith2FANoMP . UserId . Value , true ) ,
( orgUserDetailUserWithout2FA . UserId . Value , false ) ,
( orgUserDetailAdmin . UserId . Value , false ) ,
} ) ;
2024-03-21 13:07:13 +01:00
2024-10-16 11:33:00 +02:00
var removeOrganizationUserCommand = sutProvider . GetDependency < IRemoveOrganizationUserCommand > ( ) ;
2024-03-21 13:07:13 +01:00
var savingUserId = Guid . NewGuid ( ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
2024-10-22 11:38:01 +02:00
( ) = > sutProvider . Sut . SaveAsync ( policy , savingUserId ) ) ;
2024-03-21 13:07:13 +01:00
Assert . Contains ( "Policy could not be enabled. Non-compliant members will lose access to their accounts. Identify members without two-step login from the policies column in the members page." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
2024-10-16 11:33:00 +02:00
await removeOrganizationUserCommand . DidNotReceiveWithAnyArgs ( )
2024-09-04 12:18:23 +02:00
. RemoveUserAsync ( organizationId : default , organizationUserId : default , deletingUserId : default ) ;
2024-03-21 13:07:13 +01:00
await sutProvider . GetDependency < IMailService > ( ) . DidNotReceiveWithAnyArgs ( )
. SendOrganizationUserRemovedForPolicyTwoStepEmailAsync ( default , default ) ;
await sutProvider . GetDependency < IEventService > ( ) . DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default ) ;
await sutProvider . GetDependency < IPolicyRepository > ( ) . DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
}
2022-06-08 15:44:28 +02:00
[Theory, BitAutoData]
2021-06-11 17:33:32 +02:00
public async Task SaveAsync_ExistingPolicy_UpdateSingleOrg (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.TwoFactorAuthentication)] Policy policy , SutProvider < PolicyService > sutProvider )
2022-08-29 22:06:55 +02:00
{
2021-06-11 17:33:32 +02:00
// If the policy that this is updating isn't enabled then do some work now that the current one is enabled
2022-06-08 15:44:28 +02:00
var org = new Organization
2021-06-11 17:33:32 +02:00
{
Id = policy . OrganizationId ,
UsePolicies = true ,
Name = "TEST" ,
2022-08-29 22:06:55 +02:00
} ;
2021-06-11 17:33:32 +02:00
2022-05-10 23:12:09 +02:00
SetupOrg ( sutProvider , policy . OrganizationId , org ) ;
2022-08-29 22:06:55 +02:00
2021-06-11 17:33:32 +02:00
sutProvider . GetDependency < IPolicyRepository > ( )
. GetByIdAsync ( policy . Id )
2022-05-10 23:12:09 +02:00
. Returns ( new Policy
2021-06-11 17:33:32 +02:00
{
Id = policy . Id ,
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
Type = PolicyType . SingleOrg ,
2021-06-11 17:33:32 +02:00
Enabled = false ,
} ) ;
2022-05-10 23:12:09 +02:00
var orgUserDetail = new Core . Models . Data . Organizations . OrganizationUsers . OrganizationUserUserDetails
2022-08-29 22:06:55 +02:00
{
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
Id = Guid . NewGuid ( ) ,
2021-06-11 17:33:32 +02:00
Status = OrganizationUserStatusType . Accepted ,
Type = OrganizationUserType . User ,
// Needs to be different from what is passed in as the savingUserId to Sut.SaveAsync
Families for Enterprise (#1714)
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Create common test infrastructure project
* Add helpers to further type PlanTypes
* Enable testing of ASP.net MVC controllers
Controller properties have all kinds of validations in the background.
In general, we don't user properties on our Controllers, so the easiest
way to allow for Autofixture-based testing of our Controllers is to just
omit setting all properties on them.
* Workaround for broken MemberAutoDataAttribute
https://github.com/AutoFixture/AutoFixture/pull/1164 shows that only
the first test case is pulled for this attribute.
This is a workaround that populates the provided parameters, left to
right, using AutoFixture to populate any remaining.
* WIP: Organization sponsorship flow
* Add Attribute to use the Bit Autodata dependency chain
BitAutoDataAttribute is used to mark a Theory as autopopulating
parameters.
Extract common attribute methods to to a helper class. Cannot
inherit a common base, since both require inheriting from different
Xunit base classes to work.
* WIP: scaffolding for families for enterprise sponsorship flow
* Fix broken tests
* Create sponsorship offer (#1688)
* Initial db work (#1687)
* Add organization sponsorship databases to all providers
* Generalize create and update for database, specialize in code
* Add PlanSponsorshipType to db model
* Write valid json for test entries
* Initial scaffolding of emails (#1686)
* Initial scaffolding of emails
* Work on adding models for FamilyForEnterprise emails
* Switch verbage
* Put preliminary copy in emails
* Skip test
* Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store
* Add sponsorship type to token and creates sponsorship
* PascalCase properties
* Require sponsorship for remove
* Create subscription sponsorship helper class
* Handle Sponsored subscription changes
* Add sponsorship id to subscription metadata
* Make sponsoring references nullable
This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons
* WIP: Validate and remove subscriptions
* Update sponsorships on organization and org user delete
* Add friendly name to organization sponsorship
* Add sponsorship available boolean to orgDetails
* Add sponsorship service to DI
* Use userId to find org users
* Send f4e offer email
* Simplify names of f4e mail messages
* Fix Stripe org default tax rates
* Universal sponsorship redeem api
* Populate user in current context
* Add product type to organization details
* Use upgrade path to change sponsorship
Sponsorships need to be annual to match the GB add-on charge rate
* Use organization and auth to find organization sponsorship
* Add resend sponsorship offer api endpoint
* Fix double email send
* Fix sponsorship upgrade options
* Add is sponsored item to subscription response
* Add sponsorship validation to upcoming invoice webhook
* Add sponsorship validation to upcoming invoice webhook
* Fix organization delete sponsorship hooks
* Test org sponsorship service
* Fix sproc
* Fix build error
* Update emails
* Fix tests
* Skip local test
* Add newline
* Fix stripe subscription update
* Finish emails
* Skip test
* Fix unit tests
* Remove unused variable
* Fix unit tests
* Switch to handlebars ifs
* Remove ending email
* Remove reconfirmation template
* Switch naming convention
* Switch naming convention
* Fix migration
* Update copy and links
* Switch to using Guid in the method
* Remove unneeded css styles
* Add sql files to Sql.sqlproj
* Removed old comments
* Made name more verbose
* Fix SQL error
* Move unit tests to service
* Fix sp
* Revert "Move unit tests to service"
This reverts commit 1185bf3ec8ca36ccd75717ed2463adf8885159a6.
* Do repository validation in service layer
* Fix tests
* Fix merge conflicts and remove TODO
* Remove unneeded models
* Fix spacing and formatting
* Switch Org -> Organization
* Remove single use variables
* Switch method name
* Fix Controller
* Switch to obfuscating email
* Fix unit tests
Co-authored-by: Justin Baur <admin@justinbaur.com>
2021-11-19 23:25:06 +01:00
Email = "test@bitwarden.com" ,
2021-06-11 17:33:32 +02:00
Name = "TEST" ,
UserId = Guid . NewGuid ( ) ,
2024-03-21 13:07:13 +01:00
HasMasterPassword = true
2022-08-29 22:06:55 +02:00
} ;
2021-06-11 17:33:32 +02:00
sutProvider . GetDependency < IOrganizationUserRepository > ( )
. GetManyDetailsByOrganizationAsync ( policy . OrganizationId )
. Returns ( new List < Core . Models . Data . Organizations . OrganizationUsers . OrganizationUserUserDetails >
2022-08-29 21:53:48 +02:00
{
2021-06-11 17:33:32 +02:00
orgUserDetail ,
} ) ;
2024-10-09 16:32:49 +02:00
sutProvider . GetDependency < ITwoFactorIsEnabledQuery > ( )
. TwoFactorIsEnabledAsync ( Arg . Is < IEnumerable < Guid > > ( ids = > ids . Contains ( orgUserDetail . UserId . Value ) ) )
. Returns ( new List < ( Guid userId , bool hasTwoFactor ) > ( )
{
( orgUserDetail . UserId . Value , false ) ,
} ) ;
2021-06-11 17:33:32 +02:00
var utcNow = DateTime . UtcNow ;
var savingUserId = Guid . NewGuid ( ) ;
2024-10-22 11:38:01 +02:00
await sutProvider . Sut . SaveAsync ( policy , savingUserId ) ;
2021-06-11 17:33:32 +02:00
await sutProvider . GetDependency < IEventService > ( ) . Received ( )
. LogPolicyEventAsync ( policy , EventType . Policy_Updated ) ;
await sutProvider . GetDependency < IPolicyRepository > ( ) . Received ( )
. UpsertAsync ( policy ) ;
Assert . True ( policy . CreationDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
Assert . True ( policy . RevisionDate - utcNow < TimeSpan . FromSeconds ( 1 ) ) ;
2022-08-29 21:53:48 +02:00
}
2023-06-07 10:56:31 +02:00
[Theory]
[BitAutoData(true, false)]
[BitAutoData(false, true)]
[BitAutoData(false, false)]
2023-08-17 22:03:06 +02:00
public async Task SaveAsync_ResetPasswordPolicyRequiredByTrustedDeviceEncryption_DisablePolicyOrDisableAutomaticEnrollment_ThrowsBadRequest (
2023-06-07 10:56:31 +02:00
bool policyEnabled ,
bool autoEnrollEnabled ,
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.ResetPassword)] Policy policy ,
2023-06-07 10:56:31 +02:00
SutProvider < PolicyService > sutProvider )
{
policy . Enabled = policyEnabled ;
policy . SetDataModel ( new ResetPasswordDataModel
{
AutoEnrollEnabled = autoEnrollEnabled
} ) ;
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
var ssoConfig = new SsoConfig { Enabled = true } ;
ssoConfig . SetData ( new SsoConfigurationData { MemberDecryptionType = MemberDecryptionType . TrustedDeviceEncryption } ) ;
2023-08-17 22:03:06 +02:00
sutProvider . GetDependency < ISsoConfigRepository > ( )
. GetByOrganizationIdAsync ( policy . OrganizationId )
. Returns ( ssoConfig ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Trusted device encryption is on and requires this policy." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
}
[Theory, BitAutoData]
public async Task SaveAsync_RequireSsoPolicyRequiredByTrustedDeviceEncryption_DisablePolicy_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.RequireSso)] Policy policy ,
2023-08-17 22:03:06 +02:00
SutProvider < PolicyService > sutProvider )
{
policy . Enabled = false ;
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
var ssoConfig = new SsoConfig { Enabled = true } ;
ssoConfig . SetData ( new SsoConfigurationData { MemberDecryptionType = MemberDecryptionType . TrustedDeviceEncryption } ) ;
2023-06-07 10:56:31 +02:00
sutProvider . GetDependency < ISsoConfigRepository > ( )
. GetByOrganizationIdAsync ( policy . OrganizationId )
. Returns ( ssoConfig ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Trusted device encryption is on and requires this policy." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
}
2023-07-18 17:00:49 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_PolicyRequiredForAccountRecovery_NotEnabled_ThrowsBadRequestAsync (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.ResetPassword)] Policy policy , SutProvider < PolicyService > sutProvider )
2023-07-18 17:00:49 +02:00
{
policy . Enabled = true ;
policy . SetDataModel ( new ResetPasswordDataModel ( ) ) ;
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
sutProvider . GetDependency < IPolicyRepository > ( )
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . SingleOrg )
. Returns ( Task . FromResult ( new Policy { Enabled = false } ) ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Single Organization policy not enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
await sutProvider . GetDependency < IEventService > ( )
. DidNotReceiveWithAnyArgs ( )
. LogPolicyEventAsync ( default , default , default ) ;
}
[Theory, BitAutoData]
public async Task SaveAsync_SingleOrg_AccountRecoveryEnabled_ThrowsBadRequest (
2023-11-22 22:07:37 +01:00
[AdminConsoleFixtures.Policy(PolicyType.SingleOrg)] Policy policy , SutProvider < PolicyService > sutProvider )
2023-07-18 17:00:49 +02:00
{
policy . Enabled = false ;
SetupOrg ( sutProvider , policy . OrganizationId , new Organization
{
Id = policy . OrganizationId ,
UsePolicies = true ,
} ) ;
sutProvider . GetDependency < IPolicyRepository > ( )
2023-11-22 22:07:37 +01:00
. GetByOrganizationIdTypeAsync ( policy . OrganizationId , PolicyType . ResetPassword )
2023-07-18 17:00:49 +02:00
. Returns ( new Policy { Enabled = true } ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy ,
Guid . NewGuid ( ) ) ) ;
Assert . Contains ( "Account recovery policy is enabled." , badRequestException . Message , StringComparison . OrdinalIgnoreCase ) ;
await sutProvider . GetDependency < IPolicyRepository > ( )
. DidNotReceiveWithAnyArgs ( )
. UpsertAsync ( default ) ;
}
2023-05-12 09:22:19 +02:00
[Theory, BitAutoData]
public async Task GetPoliciesApplicableToUserAsync_WithRequireSsoTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsNoPolicies ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. GetPoliciesApplicableToUserAsync ( userId , PolicyType . RequireSso ) ;
Assert . Empty ( result ) ;
}
[Theory, BitAutoData]
public async Task GetPoliciesApplicableToUserAsync_WithRequireSsoTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsOnePolicy ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
sutProvider . GetDependency < GlobalSettings > ( ) . Sso . EnforceSsoPolicyForAllUsers . Returns ( true ) ;
var result = await sutProvider . Sut
. GetPoliciesApplicableToUserAsync ( userId , PolicyType . RequireSso ) ;
Assert . Single ( result ) ;
Assert . True ( result . All ( details = > details . PolicyEnabled ) ) ;
Assert . True ( result . All ( details = > details . PolicyType = = PolicyType . RequireSso ) ) ;
Assert . True ( result . All ( details = > details . OrganizationUserType = = OrganizationUserType . Owner ) ) ;
Assert . True ( result . All ( details = > details . OrganizationUserStatus = = OrganizationUserStatusType . Confirmed ) ) ;
Assert . True ( result . All ( details = > ! details . IsProvider ) ) ;
}
[Theory, BitAutoData]
public async Task GetPoliciesApplicableToUserAsync_WithDisableTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsNoPolicies ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. GetPoliciesApplicableToUserAsync ( userId , PolicyType . DisableSend ) ;
Assert . Empty ( result ) ;
}
[Theory, BitAutoData]
public async Task GetPoliciesApplicableToUserAsync_WithDisableSendTypeFilter_WithInvitedUserStatusFilter_ReturnsOnePolicy ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. GetPoliciesApplicableToUserAsync ( userId , PolicyType . DisableSend , OrganizationUserStatusType . Invited ) ;
Assert . Single ( result ) ;
Assert . True ( result . All ( details = > details . PolicyEnabled ) ) ;
Assert . True ( result . All ( details = > details . PolicyType = = PolicyType . DisableSend ) ) ;
Assert . True ( result . All ( details = > details . OrganizationUserType = = OrganizationUserType . User ) ) ;
Assert . True ( result . All ( details = > details . OrganizationUserStatus = = OrganizationUserStatusType . Invited ) ) ;
Assert . True ( result . All ( details = > ! details . IsProvider ) ) ;
}
[Theory, BitAutoData]
public async Task AnyPoliciesApplicableToUserAsync_WithRequireSsoTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsFalse ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. AnyPoliciesApplicableToUserAsync ( userId , PolicyType . RequireSso ) ;
Assert . False ( result ) ;
}
[Theory, BitAutoData]
public async Task AnyPoliciesApplicableToUserAsync_WithRequireSsoTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsTrue ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
sutProvider . GetDependency < GlobalSettings > ( ) . Sso . EnforceSsoPolicyForAllUsers . Returns ( true ) ;
var result = await sutProvider . Sut
. AnyPoliciesApplicableToUserAsync ( userId , PolicyType . RequireSso ) ;
Assert . True ( result ) ;
}
[Theory, BitAutoData]
public async Task AnyPoliciesApplicableToUserAsync_WithDisableTypeFilter_WithDefaultOrganizationUserStatusFilter_ReturnsFalse ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. AnyPoliciesApplicableToUserAsync ( userId , PolicyType . DisableSend ) ;
Assert . False ( result ) ;
}
[Theory, BitAutoData]
public async Task AnyPoliciesApplicableToUserAsync_WithDisableSendTypeFilter_WithInvitedUserStatusFilter_ReturnsTrue ( Guid userId , SutProvider < PolicyService > sutProvider )
{
SetupUserPolicies ( userId , sutProvider ) ;
var result = await sutProvider . Sut
. AnyPoliciesApplicableToUserAsync ( userId , PolicyType . DisableSend , OrganizationUserStatusType . Invited ) ;
Assert . True ( result ) ;
}
2021-06-11 17:33:32 +02:00
private static void SetupOrg ( SutProvider < PolicyService > sutProvider , Guid organizationId , Organization organization )
{
sutProvider . GetDependency < IOrganizationRepository > ( )
. GetByIdAsync ( organizationId )
. Returns ( Task . FromResult ( organization ) ) ;
}
2023-05-12 09:22:19 +02:00
private static void SetupUserPolicies ( Guid userId , SutProvider < PolicyService > sutProvider )
{
sutProvider . GetDependency < IOrganizationUserRepository > ( )
2023-08-16 05:42:09 +02:00
. GetByUserIdWithPolicyDetailsAsync ( userId , PolicyType . RequireSso )
2023-05-12 09:22:19 +02:00
. Returns ( new List < OrganizationUserPolicyDetails >
{
new ( ) { OrganizationId = Guid . NewGuid ( ) , PolicyType = PolicyType . RequireSso , PolicyEnabled = false , OrganizationUserType = OrganizationUserType . Owner , OrganizationUserStatus = OrganizationUserStatusType . Confirmed , IsProvider = false } ,
new ( ) { OrganizationId = Guid . NewGuid ( ) , PolicyType = PolicyType . RequireSso , PolicyEnabled = true , OrganizationUserType = OrganizationUserType . Owner , OrganizationUserStatus = OrganizationUserStatusType . Confirmed , IsProvider = false } ,
2023-08-16 05:42:09 +02:00
new ( ) { OrganizationId = Guid . NewGuid ( ) , PolicyType = PolicyType . RequireSso , PolicyEnabled = true , OrganizationUserType = OrganizationUserType . Owner , OrganizationUserStatus = OrganizationUserStatusType . Confirmed , IsProvider = true }
} ) ;
sutProvider . GetDependency < IOrganizationUserRepository > ( )
. GetByUserIdWithPolicyDetailsAsync ( userId , PolicyType . DisableSend )
. Returns ( new List < OrganizationUserPolicyDetails >
{
2023-05-12 09:22:19 +02:00
new ( ) { OrganizationId = Guid . NewGuid ( ) , PolicyType = PolicyType . DisableSend , PolicyEnabled = true , OrganizationUserType = OrganizationUserType . User , OrganizationUserStatus = OrganizationUserStatusType . Invited , IsProvider = false } ,
new ( ) { OrganizationId = Guid . NewGuid ( ) , PolicyType = PolicyType . DisableSend , PolicyEnabled = true , OrganizationUserType = OrganizationUserType . User , OrganizationUserStatus = OrganizationUserStatusType . Invited , IsProvider = true }
} ) ;
}
2024-10-24 17:13:45 +02:00
[Theory, BitAutoData]
public async Task SaveAsync_GivenOrganizationUsingPoliciesAndHasVerifiedDomains_WhenSingleOrgPolicyIsDisabled_ThenAnErrorShouldBeThrownOrganizationHasVerifiedDomains (
[AdminConsoleFixtures.Policy(PolicyType.SingleOrg)] Policy policy , Organization org , SutProvider < PolicyService > sutProvider )
{
org . Id = policy . OrganizationId ;
org . UsePolicies = true ;
policy . Enabled = false ;
sutProvider . GetDependency < IFeatureService > ( )
. IsEnabled ( FeatureFlagKeys . AccountDeprovisioning )
. Returns ( true ) ;
sutProvider . GetDependency < IOrganizationRepository > ( )
. GetByIdAsync ( policy . OrganizationId )
. Returns ( org ) ;
sutProvider . GetDependency < IOrganizationHasVerifiedDomainsQuery > ( )
. HasVerifiedDomainsAsync ( org . Id )
. Returns ( true ) ;
var badRequestException = await Assert . ThrowsAsync < BadRequestException > (
( ) = > sutProvider . Sut . SaveAsync ( policy , null ) ) ;
Assert . Equal ( "Organization has verified domains." , badRequestException . Message ) ;
}
2021-06-11 17:33:32 +02:00
}