1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-07 14:08:13 -05:00

858 Commits

Author SHA1 Message Date
jrmccannon
ad3131f66e
Cleaned up DTO models. Moved some validation steps around. A few quick fixes to address CR concerns. Still need to move a few things yet. 2025-03-26 10:56:33 -05:00
jrmccannon
f3f2f41cfb
Merge branch 'refs/heads/main' into jmccannon/ac/pm-16811-scim-invite-optimization
# Conflicts:
#	test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs
2025-03-26 10:41:50 -05:00
Rui Tomé
f04a3d638b
[PM-18235] Add PersonalOwnershipPolicyRequirement (#5439)
* Add PersonalOwnershipPolicyRequirement for managing personal ownership policy

* Add tests for PersonalOwnershipPolicyRequirement

* Register PersonalOwnershipPolicyRequirement in policy requirement factory

* Update ImportCiphersCommand to check PersonalOwnershipPolicyRequirement if the PolicyRequirements flag is enabled

Update unit tests

* Update CipherService to support PersonalOwnershipPolicyRequirement with feature flag

- Add support for checking personal ownership policy using PolicyRequirementQuery when feature flag is enabled
- Update CipherService constructor to inject new dependencies
- Add tests for personal vault restrictions with and without feature flag

* Clean up redundant "Arrange", "Act", and "Assert" comments in test methods

* Refactor PersonalOwnershipPolicyRequirementTests method names for clarity

- Improve test method names to better describe their purpose and behavior
- Rename methods to follow a more descriptive naming convention
- No functional changes to the test logic

* Remove commented code explaining policy check

* Refactor PersonalOwnership Policy Requirement implementation

- Add PersonalOwnershipPolicyRequirementFactory to replace static Create method
- Simplify policy requirement creation logic
- Update PolicyServiceCollectionExtensions to register new factory
- Update ImportCiphersCommand to use correct user ID parameter
- Remove redundant PersonalOwnershipPolicyRequirementTests

* Remove redundant PersonalOwnershipPolicyRequirementTests

* Remove unnecessary tests from PersonalOwnershipPolicyRequirementFactoryTests
2025-03-26 09:40:13 +00:00
jrmccannon
9b8a15193d
Added groups and collection and users checks. 2025-03-25 12:45:11 -05:00
Bernd Schoolmann
55980e8038
[PM-16603] Add userkey rotation v2 (#5204)
* Implement userkey rotation v2

* Update request models

* Cleanup

* Update tests

* Improve test

* Add tests

* Fix formatting

* Fix test

* Remove whitespace

* Fix namespace

* Enable nullable on models

* Fix build

* Add tests and enable nullable on masterpasswordunlockdatamodel

* Fix test

* Remove rollback

* Add tests

* Make masterpassword hint optional

* Update user query

* Add EF test

* Improve test

* Cleanup

* Set masterpassword hint

* Remove connection close

* Add tests for invalid kdf types

* Update test/Core.Test/KeyManagement/UserKey/RotateUserAccountKeysCommandTests.cs

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Fix formatting

* Update src/Api/KeyManagement/Models/Requests/RotateAccountKeysAndDataRequestModel.cs

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Update src/Api/Auth/Models/Request/Accounts/MasterPasswordUnlockDataModel.cs

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Update src/Api/Auth/Models/Request/Accounts/MasterPasswordUnlockDataModel.cs

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Update src/Api/KeyManagement/Models/Requests/AccountKeysRequestModel.cs

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>

* Fix imports

* Fix tests

* Remove null check

* Add rollback

---------

Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>
2025-03-25 15:23:01 +01:00
jrmccannon
6c6ecfefdf
Fixing name. 2025-03-24 15:32:30 -05:00
jrmccannon
038c00d21f
PasswordManagerInviteUserValidation to PasswordManagerInviteUserValidator 2025-03-24 12:39:03 -05:00
jrmccannon
f0770eda93
Rename for InvitingUserOrganizationValidation to InvitingUserOrganizationValidator 2025-03-24 12:35:16 -05:00
jrmccannon
982611bd1b
Renamed InviteUsersValidation to InviteUsersValidator 2025-03-24 12:34:36 -05:00
jrmccannon
5f41d1eb23
Variable/Field/Property renames 2025-03-24 12:33:02 -05:00
Rui Tomé
24b63f2dcd
[PM-12493] Extract ConfirmUser methods from OrganizationService into commands (#5505)
* Add ConfirmOrganizationUserCommand and IConfirmOrganizationUserCommand interface for managing organization user confirmations

* Add unit tests for ConfirmOrganizationUserCommand to validate user confirmation scenarios

* Register ConfirmOrganizationUserCommand for dependency injection

* Refactor OrganizationUsersController to utilize IConfirmOrganizationUserCommand for user confirmation processes

* Remove ConfirmUserAsync and ConfirmUsersAsync methods from IOrganizationService and OrganizationService

* Rename test methods in ConfirmOrganizationUserCommandTests for clarity and consistency

* Update test method name in ConfirmOrganizationUserCommandTests for improved clarity
2025-03-24 17:05:46 +00:00
jrmccannon
7be2e2bd07
Removed test only constructor from InviteOrganization 2025-03-24 08:45:19 -05:00
jrmccannon
3f81e15169
fixed test 2025-03-21 15:54:03 -05:00
jrmccannon
87c181b662
Refactor validation parameter to improve clarity and consistency. Added XML doc 2025-03-21 15:18:05 -05:00
jrmccannon
d867b47705
Merge branch 'refs/heads/main' into jmccannon/ac/pm-16811-scim-invite-optimization
# Conflicts:
#	src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
2025-03-21 13:50:22 -05:00
Brandon Treston
c7c6528faa
Ac/pm 18240 implement policy requirement for reset password policy (#5521)
* wip

* fix test

* fix test

* refactor

* fix factory method and tests

* cleanup

* refactor

* update copy

* cleanup
2025-03-21 10:07:55 -04:00
jrmccannon
829e49c398
Fixed tests. 2025-03-20 09:11:09 -05:00
Jordan Aasen
21717ec71e
[PM-17733] - [Privilege Escalation] - Unauthorised access allows limited access user to change password of Items (#5452)
* prevent view-only users from updating passwords

* revert change to licensing service

* add tests

* check if organizationId is there

* move logic to private method

* move logic to private method

* move logic into method

* revert change to licensing service

* throw exception when cipher key is created by hidden password users

* fix tests

* don't allow totp or passkeys changes from hidden password users

* add tests

* revert change to licensing service
2025-03-19 11:13:38 -07:00
Todd Martin
d3f8a99fa6
[PM-18175] Remove flag check for 2FA recovery code login (#5513)
* Remove server-side flagging

* Linting

* Linting.
2025-03-17 16:20:51 -04:00
Jared McCannon
7f87922684
Merge branch 'main' into jmccannon/ac/pm-16811-scim-invite-optimization 2025-03-17 15:19:36 -05:00
jrmccannon
59b579f071
Refactored to use new ValidationResult pattern. added mapping method. 2025-03-17 13:27:37 -05:00
Ike
abfdf6f5cb
Revert "[PM-18944] Update error response from invalid OTP" (#5504)
* Revert "[PM-18944] Update error response from invalid OTP (#5485)"

This reverts commit 1b90bfe2a114e73b583100e955e57ac48b9733b9.
2025-03-17 12:37:34 -04:00
jrmccannon
813333e9bb
Merge branch 'main' into jmccannon/ac/pm-16811-scim-invite-optimization
# Conflicts:
#	src/Core/Models/Commands/CommandResult.cs
2025-03-17 08:59:17 -05:00
Jared McCannon
488a9847ea
Partial<T> for CommandResult<T> (#5482)
* Example of how a partial success/failure command result would look.

* Fixed code.

* Added Validator and ValidationResult

* Moved errors into their own files.

* Fixing tests

* fixed import.

* Forgot mock error.
2025-03-14 12:00:58 -05:00
Ike
1b90bfe2a1
[PM-18944] Update error response from invalid OTP (#5485)
* fix(newDeviceVerification): updated error response from invalid OTP
2025-03-11 17:01:50 -04:00
Rui Tomé
6510f2a3e8
[PM-18088] Add unit test coverage for admin methods on CiphersController and CipherService (#5460)
* Add comprehensive test coverage for CipherService restore, delete, and soft delete methods

* Add comprehensive admin cipher management tests for CiphersController

* Enhance CiphersController admin methods with comprehensive test coverage

- Add tests for provider user scenarios in admin cipher management methods
- Implement tests for custom user with edit any collection permissions
- Add test coverage for RestrictProviderAccess feature flag
- Improve test scenarios for delete, soft delete, and restore operations

* Refactor CiphersControllerTests to simplify and optimize test methods

* Optimize CiphersControllerTests with code cleanup and test method improvements

* Extend CiphersControllerTests to support Admin and Owner roles

* Add test cases for custom user cipher admin operations with EditAnyCollection permission checks

- Extend CiphersControllerTests with scenarios for custom users without EditAnyCollection permission
- Add test methods to verify NotFoundException is thrown when EditAnyCollection is false
- Cover delete, soft delete, and restore operations for single and bulk cipher admin actions

* Enhance CiphersControllerTests with granular access permission scenarios

- Add test methods for admin and owner roles with specific cipher access scenarios
- Implement tests for accessing specific and unassigned ciphers
- Extend test coverage for delete, soft delete, and restore operations
- Improve test method naming for clarity and precision

* Add bulk admin cipher delete and soft delete tests for specific and unassigned ciphers

- Implement test methods for DeleteManyAdmin and PutDeleteManyAdmin
- Cover scenarios for owner and admin roles with access to specific and unassigned ciphers
- Verify correct invocation of DeleteManyAsync and SoftDeleteManyAsync methods
- Enhance test coverage for bulk cipher admin operations
2025-03-11 10:10:20 +00:00
Thomas Rittson
224ef1272e
[PM-18876] Refine PolicyRequirements API (#5445)
* make the PolicyRequirements API more granular, e.g.
  replace factory methods with a factory interface
* update Send to use the new API
2025-03-11 10:46:09 +10:00
Jonas Hendrickx
ac25ec4519
[PM-19002] Extract billing code from AccountsController (#5477) 2025-03-10 18:14:22 +01:00
Rui Tomé
6e7c5b172c
[PM-18087] Add cipher permissions to response models (#5418)
* Add Manage permission to UserCipherDetails and CipherDetails_ReadByIdUserId

* Add Manage property to CipherDetails and UserCipherDetailsQuery

* Add integration test for CipherRepository Manage permission rules

* Update CipherDetails_ReadWithoutOrganizationsByUserId to include Manage permission

* Refactor UserCipherDetailsQuery to include detailed permission and organization properties

* Refactor CipherRepositoryTests to improve test organization and readability

- Split large test method into smaller, focused methods
- Added helper methods for creating test data and performing assertions
- Improved test coverage for cipher permissions in different scenarios
- Maintained existing test logic while enhancing code structure

* Refactor CipherRepositoryTests to consolidate cipher permission tests

- Removed redundant helper methods for permission assertions
- Simplified test methods for GetCipherPermissionsForOrganizationAsync, GetManyByUserIdAsync, and GetByIdAsync
- Maintained existing test coverage for cipher manage permissions
- Improved code readability and reduced code duplication

* Add integration test for CipherRepository group collection manage permissions

- Added new test method GetCipherPermissionsForOrganizationAsync_ManageProperty_RespectsCollectionGroupRules
- Implemented helper method CreateCipherInOrganizationCollectionWithGroup to support group-based collection permission testing
- Verified manage permissions are correctly applied based on group collection access settings

* Add @Manage parameter to Cipher stored procedures

- Updated CipherDetails_Create, CipherDetails_CreateWithCollections, and CipherDetails_Update stored procedures
- Added @Manage parameter with comment "-- not used"
- Included new stored procedure implementations in migration script
- Consistent with previous work on adding Manage property to cipher details

* Update UserCipherDetails functions to reorder Manage and ViewPassword columns

* [PM-18086] Add CanRestore and CanDelete authorization methods.

* [PM-18086] Address code review feedback.

* [PM-18086] Add missing part.

* [PM-18087] Add CipherPermissionsResponseModel for cipher permissions

* Add GetManyOrganizationAbilityAsync method to application cache service

* Add organization ability context to cipher response models

This change introduces organization ability context to various cipher response models across multiple controllers. The modifications include:

- Updating CipherResponseModel to include permissions based on user and organization ability
- Modifying CiphersController methods to fetch and pass organization abilities
- Updating SyncController to include organization abilities in sync response
- Adding organization ability context to EmergencyAccessController response generation

* Remove organization ability context from EmergencyAccessController

This change simplifies the EmergencyAccessController by removing unnecessary organization ability fetching and passing. Since emergency access only retrieves personal ciphers, the organization ability context is no longer needed in the response generation.

* Remove unused IApplicationCacheService from EmergencyAccessController

* Refactor EmergencyAccessViewResponseModel constructor

Remove unnecessary JsonConstructor attribute and simplify constructor initialization for EmergencyAccessViewResponseModel

* Refactor organization ability retrieval in CiphersController

Extract methods to simplify organization ability fetching for ciphers, reducing code duplication and improving readability. Added two private helper methods:
- GetOrganizationAbilityAsync: Retrieves organization ability for a single cipher
- GetManyOrganizationAbilitiesAsync: Retrieves organization abilities for multiple ciphers

* Update CiphersControllerTests to use GetUserByPrincipalAsync

Modify test methods to:
- Replace GetProperUserId with GetUserByPrincipalAsync
- Use User object instead of separate userId
- Update mocking to return User object
- Ensure user ID is correctly set in test scenarios

* Refactor CipherPermissionsResponseModel to use constructor-based initialization

* Refactor CipherPermissionsResponseModel to use record type and init-only properties

* [PM-18086] Undo files

* [PM-18086] Undo files

* Refactor organization abilities retrieval in cipher-related controllers and models

- Update CiphersController to use GetOrganizationAbilitiesAsync instead of individual methods
- Modify CipherResponseModel and CipherDetailsResponseModel to accept organization abilities dictionary
- Update CipherPermissionsResponseModel to handle organization abilities lookup
- Remove deprecated organization ability retrieval methods
- Simplify sync and emergency access response model handling of organization abilities

* Remove GetManyOrganizationAbilityAsync method

- Delete unused method from IApplicationCacheService interface
- Remove corresponding implementation in InMemoryApplicationCacheService
- Continues cleanup of organization ability retrieval methods

* Update CiphersControllerTests to include organization abilities retrieval

- Add organization abilities retrieval in test setup for PutCollections_vNext method
- Ensure consistent mocking of IApplicationCacheService in test scenarios

* Update error message for missing organization ability

---------

Co-authored-by: Jimmy Vo <huynhmaivo82@gmail.com>
2025-03-10 15:27:30 +00:00
cyprain-okeke
88e91734f1
[PM-17594]Remove feature flag self-host license refactor (#5372)
* Remove the feature flag

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Resolve the failing test

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

---------

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
Co-authored-by: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com>
2025-03-10 11:46:44 +01:00
jrmccannon
d8264a9085
Fixed some changes. 2025-03-07 14:43:12 -06:00
jrmccannon
e4aa740a28
Fixed some compilation errors. 2025-03-07 12:46:59 -06:00
jrmccannon
88923b5e6e
Merge branch 'main' into jmccannon/ac/pm-16811-scim-invite-optimization
# Conflicts:
#	src/Core/Models/Commands/CommandResult.cs
2025-03-07 12:33:31 -06:00
jrmccannon
4317276f5d
Dto rename. Moved from static methods to ctors 2025-03-07 10:03:47 -06:00
Daniel James Smith
34358acf61
Fix user context on importing into individual vaults (#5465)
Pass in the current userId instead of trying to infer it from the folders or ciphers passed into the ImportCiphersCommand

Kudos go to @MJebran who pointed this out on https://github.com/bitwarden/server/pull/4896

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
2025-03-07 15:09:54 +01:00
Jonas Hendrickx
c589f9a330
[BEEEP] [PM-18518] Cleanup StripePaymentService (#5435) 2025-03-07 09:52:04 +01:00
Maciej Zieniuk
8628206fa9
ArgumentNullException: Value cannot be null in POST /push/register (#5472) 2025-03-06 22:13:02 +01:00
Jimmy Vo
c82908f40b
[PM-15621] Add functionality to map command results to HTTP responses. (#5467) 2025-03-06 11:16:58 -05:00
jrmccannon
49e5e73d12
undoing this 2025-03-05 16:30:08 -06:00
jrmccannon
56c7cc8bf4
Rename of OrgDto 2025-03-05 16:21:40 -06:00
jrmccannon
53168717fb
Fixing bad merge. 2025-03-05 16:08:11 -06:00
jrmccannon
f8c08de2db
Merge branch 'main' into jmccannon/ac/pm-16811-scim-invite-optimization
# Conflicts:
#	src/Core/AdminConsole/Services/Implementations/OrganizationService.cs
#	test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs
2025-03-05 15:24:13 -06:00
jrmccannon
c7cc9527f4
Moved FromOrganization mapper method to a constructor 2025-03-05 15:04:50 -06:00
jrmccannon
611ad8c343
Moved to private method. Made ScimInvite inherit the single invite base model. Moved create methods to constructors. A few more CR changes included. 2025-03-05 14:55:41 -06:00
jrmccannon
4ff27fd668
created response model and split interface out. 2025-03-05 07:42:09 -06:00
Jimmy Vo
63f1c3cee3
[PM-18086] Add CanRestore and CanDelete authorization methods. (#5407) 2025-02-27 16:30:25 -05:00
Kyle Spearrin
8354929ff1
[PM-18608] Don't require new device verification on newly created accounts (#5440)
* Limit new device verification to aged accounts

* set user creation date context for test

* formatting
2025-02-27 11:01:40 -05:00
Graham Walker
3533f82d0f
Tools/import cipher controller tests (#5436)
* initial commit

* PM-17954 adding unit tests for ImportCiphersController.PostImport
2025-02-27 09:53:26 -06:00
Brandon Treston
546b5a0849
[pm-17804] Fix deferred execution issue in EF CreateManyAsync (#5425)
* Add failing repository tests

* test

* clean up comments

---------

Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
2025-02-27 10:21:01 -05:00
renovate[bot]
4c5bf495f3
[deps] Auth: Update Duende.IdentityServer to 7.1.0 (#5293)
* [deps] Auth: Update Duende.IdentityServer to 7.1.0

* fix(identity): fixing name space for Identity 7.1.0 update

* fix: formatting

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Ike Kottlowski <ikottlowski@bitwarden.com>
2025-02-27 09:54:28 -05:00