-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[PM-39978] Add Item type Send support #8008
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
Open
mcamirault
wants to merge
8
commits into
main
Choose a base branch
from
tools/pm-39978/support-item-type-sends
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b4836c
[PM-39978] Add Item type Send support
mcamirault 5a364b6
Add Item type Send handling to SendAccessResponseModel, add test coveβ¦
mcamirault 480357d
Formatting
mcamirault 2f5633c
Use string.Empty instead of quotes
mcamirault bfd7ee7
Change Send request data to string to support field by field encryption
mcamirault 1f9e927
Correct access count logic for Item Sends
mcamirault d63cef3
Update src/Api/Tools/Models/Request/SendRequestModel.cs
mcamirault 8a7e5a7
Merge branch 'main' into tools/pm-39978/support-item-type-sends
mcamirault 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
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
|
harr1424 marked this conversation as resolved.
|
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 |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ | |
| public enum SendType : byte | ||
| { | ||
| Text = 0, | ||
| File = 1 | ||
| File = 1, | ||
| Item = 2 | ||
| } | ||
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
114 changes: 114 additions & 0 deletions
114
test/Api.Test/Tools/Models/Response/SendAccessResponseModelTests.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,114 @@ | ||
| ο»Ώusing System.Text.Json; | ||
| using Bit.Api.Tools.Models.Response; | ||
| using Bit.Core.Tools.Entities; | ||
| using Bit.Core.Tools.Enums; | ||
| using Bit.Core.Tools.Models.Data; | ||
| using Xunit; | ||
|
|
||
| namespace Bit.Api.Test.Models.Response; | ||
|
|
||
| public class SendAccessResponseModelTests | ||
| { | ||
| [Fact] | ||
| public void NullSend_Throws() | ||
| { | ||
| Send send = null; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<ArgumentNullException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextSend_NullData_Throws() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Type = SendType.Text, | ||
| Data = null | ||
| }; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<NullReferenceException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TextSend_NonDeserializableData_Throws() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Type = SendType.Text, | ||
| Data = "bad_data" | ||
| }; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<JsonException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FileSend_NullData_Throws() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Type = SendType.File, | ||
| Data = null | ||
| }; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<NullReferenceException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FileSend_NonDeserializableData_Throws() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Type = SendType.File, | ||
| Data = "bad_data" | ||
| }; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<JsonException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ItemSend_NullData_Throws() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Type = SendType.Item, | ||
| Data = null | ||
| }; | ||
| SendAccessResponseModel responseModel; | ||
| Assert.Throws<NullReferenceException>(() => responseModel = new SendAccessResponseModel(send)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FromSend_Success() | ||
| { | ||
| var send = new Send | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| AuthType = AuthType.None, | ||
| Key = "encrypted_key", | ||
| MaxAccessCount = 5, | ||
| AccessCount = 0, | ||
| RevisionDate = new DateTime(), | ||
| ExpirationDate = new DateTime(), | ||
| DeletionDate = new DateTime(), | ||
| Password = null, | ||
| Emails = null, | ||
| Disabled = false, | ||
| HideEmail = false, | ||
| Type = SendType.Text, | ||
| Data = JsonSerializer.Serialize(new SendTextData | ||
| { | ||
| Hidden = false, | ||
| Name = "encrypted_name", | ||
| Notes = null, | ||
| Text = "encrypted_text" | ||
| }) | ||
| }; | ||
| var responseModel = new SendAccessResponseModel(send); | ||
| Assert.Equal(send.Type, responseModel.Type); | ||
| Assert.Equal(send.AuthType, responseModel.AuthType); | ||
| Assert.Equal("encrypted_name", responseModel.Name); | ||
| Assert.Equal("encrypted_text", responseModel.Text.Text); | ||
| Assert.False(responseModel.Text.Hidden); | ||
| Assert.Equal(send.ExpirationDate, responseModel.ExpirationDate); | ||
| } | ||
| } |
Oops, something went wrong.
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.