-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[PM-30584] Add support for key-connector-migration setting key #7136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+291
β9
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
23aaddb
Add key-connector enrollment
quexten 5055b8c
Fix tests
quexten d5c4ab4
Merge branch 'main' into km/key-connector-set-key
quexten 6107731
Update src/Api/KeyManagement/Controllers/AccountsKeyManagementControlβ¦
quexten 728543e
Move validation to request model
quexten 65c86f4
Add tests
quexten a86a259
Merge branch 'km/key-connector-set-key' of github.com:bitwarden/serveβ¦
quexten a47a9c9
Merge branch 'main' into km/key-connector-set-key
quexten b864fa6
Fix build
quexten d94b45e
Merge branch 'km/key-connector-set-key' of github.com:bitwarden/serveβ¦
quexten f4dd1e3
Attempt to fix build
quexten 8400a6e
Attempt to fix remaining tests
quexten 69d6593
Fix tests
quexten c08c8dc
Format
quexten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Api/KeyManagement/Models/Requests/KeyConnectorEnrollmentRequestModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ο»Ώusing System.ComponentModel.DataAnnotations; | ||
| using Bit.Core.Utilities; | ||
|
|
||
| namespace Bit.Api.KeyManagement.Models.Requests; | ||
|
|
||
| public class KeyConnectorEnrollmentRequestModel : IValidatableObject | ||
| { | ||
| [EncryptedString] | ||
| public required string KeyConnectorKeyWrappedUserKey { get; set; } | ||
|
|
||
| public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(KeyConnectorKeyWrappedUserKey)) | ||
| { | ||
| yield return new ValidationResult( | ||
| "KeyConnectorKeyWrappedUserKey must be supplied when request body is provided.", | ||
| [nameof(KeyConnectorKeyWrappedUserKey)]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/Api.Test/KeyManagement/Models/Request/KeyConnectorEnrollmentRequestModelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ο»Ώusing System.ComponentModel.DataAnnotations; | ||
| using Bit.Api.KeyManagement.Models.Requests; | ||
| using Xunit; | ||
|
|
||
| namespace Bit.Api.Test.KeyManagement.Models.Request; | ||
|
|
||
| public class KeyConnectorEnrollmentRequestModelTests | ||
| { | ||
| private const string _wrappedUserKey = "2.AOs41Hd8OQiCPXjyJKCiDA==|O6OHgt2U2hJGBSNGnimJmg==|iD33s8B69C8JhYYhSa4V1tArjvLr8eEaGqOV7BRo5Jk="; | ||
|
|
||
| [Fact] | ||
| public void Validate_KeyConnectorKeyWrappedUserKeyNull_Invalid() | ||
| { | ||
| var model = new KeyConnectorEnrollmentRequestModel | ||
| { | ||
| KeyConnectorKeyWrappedUserKey = null! | ||
| }; | ||
|
|
||
| var results = Validate(model); | ||
|
|
||
| Assert.Contains(results, | ||
| r => r.ErrorMessage == "KeyConnectorKeyWrappedUserKey must be supplied when request body is provided."); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Validate_KeyConnectorKeyWrappedUserKeyWhitespace_Invalid() | ||
| { | ||
| var model = new KeyConnectorEnrollmentRequestModel | ||
| { | ||
| KeyConnectorKeyWrappedUserKey = " " | ||
| }; | ||
|
|
||
| var results = Validate(model); | ||
|
|
||
| Assert.Contains(results, | ||
| r => r.ErrorMessage == "KeyConnectorKeyWrappedUserKey is not a valid encrypted string."); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Validate_KeyConnectorKeyWrappedUserKeyValid_Success() | ||
| { | ||
| var model = new KeyConnectorEnrollmentRequestModel | ||
| { | ||
| KeyConnectorKeyWrappedUserKey = _wrappedUserKey | ||
| }; | ||
|
|
||
| var results = Validate(model); | ||
|
|
||
| Assert.Empty(results); | ||
| } | ||
|
|
||
| private static List<ValidationResult> Validate(KeyConnectorEnrollmentRequestModel model) | ||
| { | ||
| var results = new List<ValidationResult>(); | ||
| Validator.TryValidateObject(model, new ValidationContext(model), results, true); | ||
| return results; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.