-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-25652] Add endpoint to fetch key connector confirmation details #6635
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
Thomas-Avery
wants to merge
4
commits into
main
Choose a base branch
from
km/pm-25652
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions
24
src/Api/KeyManagement/Models/Responses/KeyConnectorConfirmationDetailsResponseModel.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,24 @@ | ||
| ๏ปฟusing Bit.Core.KeyManagement.Models.Data; | ||
| using Bit.Core.Models.Api; | ||
|
|
||
| namespace Bit.Api.KeyManagement.Models.Responses; | ||
|
|
||
| public class KeyConnectorConfirmationDetailsResponseModel : ResponseModel | ||
| { | ||
| private const string _objectName = "keyConnectorConfirmationDetails"; | ||
|
|
||
| public KeyConnectorConfirmationDetailsResponseModel(KeyConnectorConfirmationDetails details, | ||
| string obj = _objectName) : base(obj) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(details); | ||
|
|
||
| OrganizationName = details.OrganizationName; | ||
| } | ||
|
|
||
| public KeyConnectorConfirmationDetailsResponseModel() : base(_objectName) | ||
| { | ||
| OrganizationName = string.Empty; | ||
| } | ||
|
|
||
| public string OrganizationName { get; set; } | ||
| } | ||
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
6 changes: 6 additions & 0 deletions
6
src/Core/KeyManagement/Models/Data/KeyConnectorConfirmationDetails.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,6 @@ | ||
| ๏ปฟnamespace Bit.Core.KeyManagement.Models.Data; | ||
|
|
||
| public class KeyConnectorConfirmationDetails | ||
| { | ||
| public required string OrganizationName { get; set; } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/Core/KeyManagement/Queries/Interfaces/IKeyConnectorConfirmationDetailsQuery.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,8 @@ | ||
| ๏ปฟusing Bit.Core.KeyManagement.Models.Data; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries.Interfaces; | ||
|
|
||
| public interface IKeyConnectorConfirmationDetailsQuery | ||
| { | ||
| public Task<KeyConnectorConfirmationDetails> Run(string orgSsoIdentifier, Guid userId); | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/Core/KeyManagement/Queries/KeyConnectorConfirmationDetailsQuery.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,35 @@ | ||
| ๏ปฟusing Bit.Core.Exceptions; | ||
| using Bit.Core.KeyManagement.Models.Data; | ||
| using Bit.Core.KeyManagement.Queries.Interfaces; | ||
| using Bit.Core.Repositories; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries; | ||
|
|
||
| public class KeyConnectorConfirmationDetailsQuery : IKeyConnectorConfirmationDetailsQuery | ||
| { | ||
| private readonly IOrganizationRepository _organizationRepository; | ||
| private readonly IOrganizationUserRepository _organizationUserRepository; | ||
|
|
||
| public KeyConnectorConfirmationDetailsQuery(IOrganizationRepository organizationRepository, IOrganizationUserRepository organizationUserRepository) | ||
| { | ||
| _organizationRepository = organizationRepository; | ||
| _organizationUserRepository = organizationUserRepository; | ||
| } | ||
|
|
||
| public async Task<KeyConnectorConfirmationDetails> Run(string orgSsoIdentifier, Guid userId) | ||
| { | ||
| var org = await _organizationRepository.GetByIdentifierAsync(orgSsoIdentifier); | ||
| if (org is not { UseKeyConnector: true }) | ||
| { | ||
| throw new NotFoundException(); | ||
| } | ||
|
|
||
| var orgUser = await _organizationUserRepository.GetByOrganizationAsync(org.Id, userId); | ||
Thomas-Avery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (orgUser == null) | ||
| { | ||
| throw new NotFoundException(); | ||
quexten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return new KeyConnectorConfirmationDetails { OrganizationName = org.Name, }; | ||
| } | ||
| } | ||
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
86 changes: 86 additions & 0 deletions
86
test/Core.Test/KeyManagement/Queries/KeyConnectorConfirmationDetailsQueryTests.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,86 @@ | ||
| ๏ปฟusing Bit.Core.AdminConsole.Entities; | ||
| using Bit.Core.Entities; | ||
| using Bit.Core.Exceptions; | ||
| using Bit.Core.KeyManagement.Queries; | ||
| using Bit.Core.Repositories; | ||
| using Bit.Test.Common.AutoFixture; | ||
| using Bit.Test.Common.AutoFixture.Attributes; | ||
| using NSubstitute; | ||
| using Xunit; | ||
|
|
||
| namespace Bit.Core.Test.KeyManagement.Queries; | ||
|
|
||
| [SutProviderCustomize] | ||
| public class KeyConnectorConfirmationDetailsQueryTests | ||
| { | ||
| [Theory] | ||
| [BitAutoData] | ||
| public async Task Run_OrganizationNotFound_Throws(SutProvider<KeyConnectorConfirmationDetailsQuery> sutProvider, | ||
| Guid userId, string orgSsoIdentifier) | ||
| { | ||
| await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.Run(orgSsoIdentifier, userId)); | ||
|
|
||
| await sutProvider.GetDependency<IOrganizationUserRepository>() | ||
| .ReceivedWithAnyArgs(0) | ||
| .GetByOrganizationAsync(Arg.Any<Guid>(), Arg.Any<Guid>()); | ||
| } | ||
|
|
||
| [Theory] | ||
| [BitAutoData] | ||
| public async Task Run_OrganizationNotKeyConnector_Throws( | ||
| SutProvider<KeyConnectorConfirmationDetailsQuery> sutProvider, | ||
| Guid userId, string orgSsoIdentifier, Organization org) | ||
| { | ||
| org.Identifier = orgSsoIdentifier; | ||
| org.UseKeyConnector = false; | ||
| sutProvider.GetDependency<IOrganizationRepository>().GetByIdentifierAsync(orgSsoIdentifier).Returns(org); | ||
|
|
||
| await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.Run(orgSsoIdentifier, userId)); | ||
|
|
||
| await sutProvider.GetDependency<IOrganizationUserRepository>() | ||
| .ReceivedWithAnyArgs(0) | ||
| .GetByOrganizationAsync(Arg.Any<Guid>(), Arg.Any<Guid>()); | ||
| } | ||
|
|
||
| [Theory] | ||
| [BitAutoData] | ||
| public async Task Run_OrganizationUserNotFound_Throws(SutProvider<KeyConnectorConfirmationDetailsQuery> sutProvider, | ||
| Guid userId, string orgSsoIdentifier | ||
| , Organization org) | ||
| { | ||
| org.Identifier = orgSsoIdentifier; | ||
| org.UseKeyConnector = true; | ||
| sutProvider.GetDependency<IOrganizationRepository>().GetByIdentifierAsync(orgSsoIdentifier).Returns(org); | ||
| sutProvider.GetDependency<IOrganizationUserRepository>() | ||
| .GetByOrganizationAsync(Arg.Any<Guid>(), Arg.Any<Guid>()).Returns(Task.FromResult<OrganizationUser>(null)); | ||
|
|
||
| await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.Run(orgSsoIdentifier, userId)); | ||
|
|
||
| await sutProvider.GetDependency<IOrganizationUserRepository>() | ||
| .Received(1) | ||
| .GetByOrganizationAsync(org.Id, userId); | ||
| } | ||
|
|
||
| [Theory] | ||
| [BitAutoData] | ||
| public async Task Run_Success(SutProvider<KeyConnectorConfirmationDetailsQuery> sutProvider, Guid userId, | ||
| string orgSsoIdentifier | ||
| , Organization org, OrganizationUser orgUser) | ||
| { | ||
| org.Identifier = orgSsoIdentifier; | ||
| org.UseKeyConnector = true; | ||
| orgUser.OrganizationId = org.Id; | ||
| orgUser.UserId = userId; | ||
|
|
||
| sutProvider.GetDependency<IOrganizationRepository>().GetByIdentifierAsync(orgSsoIdentifier).Returns(org); | ||
| sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(org.Id, userId) | ||
| .Returns(orgUser); | ||
|
|
||
| var result = await sutProvider.Sut.Run(orgSsoIdentifier, userId); | ||
|
|
||
| Assert.Equal(org.Name, result.OrganizationName); | ||
| await sutProvider.GetDependency<IOrganizationUserRepository>() | ||
| .Received(1) | ||
| .GetByOrganizationAsync(org.Id, userId); | ||
| } | ||
| } |
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.