-
Notifications
You must be signed in to change notification settings - Fork 1
Heedls 681 Add LH SSO Account Linking Endpoint #832
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
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
573552d
HEEDLS-681 Add LH SSO callback endpoint
1437aca
Merge branch 'HEEDLS-680-sso-security-helper' into HEEDLS-681-SSO-Acc…
9045a43
HEEDLS-681 Fix merge 680 updates
6ebae15
HEEDLS-681 Add check for already linked
ea2f107
HEEDLS-681 Add Interation Tests
d22664f
HEEDLS-681 Update layout for transactions
b22be41
Merge branch 'master' into HEEDLS-681-SSO-Account-Linnking-Endpoint
11bd9ba
HEEDLS-681 Update xunit config - turn off parallel
e71e36f
HEEDLS-681 Add Signposting Feature Gate check
cabce86
HEEDLS-681 markups
bb69c0a
Merge branch 'master' into HEEDLS-681-SSO-Account-Linnking-Endpoint
b704aab
HEEDLS-681 fix merge conflict
0dae77c
HEEDLS-681 Markups
d45fbb5
Merge branch 'master' into HEEDLS-681-SSO-Account-Linnking-Endpoint
b967660
HEEDLS-681 markups refactor
edd04ce
HHEDLS-681 TLR additional markups
d80bdc3
HEEDLS-681 cleanup factories
4f78ca7
Merge branch 'master' into HEEDLS-681-SSO-Account-Linnking-Endpoint
ab298b1
HEEDLS-681 TLR Markups - Change layout
a726034
HEEDLS-681 TRL markups - nav menu fix
037c8a6
Merge branch 'master' into HEEDLS-681-SSO-Account-Linnking-Endpoint
5f79366
HEEDLS-681 merge conflict
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
261 changes: 261 additions & 0 deletions
261
DigitalLearningSolutions.Data.Tests/Services/LearningHubLinkServiceTests.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,261 @@ | ||
| namespace DigitalLearningSolutions.Data.Tests.Services | ||
| { | ||
| using System; | ||
| using DigitalLearningSolutions.Data.DataServices.UserDataService; | ||
| using DigitalLearningSolutions.Data.Exceptions; | ||
| using DigitalLearningSolutions.Data.Models.Signposting; | ||
| using DigitalLearningSolutions.Data.Services; | ||
| using FakeItEasy; | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
|
|
||
| public class LearningHubLinkServiceTests | ||
| { | ||
| private ILearningHubLinkService learningHubLinkService = null!; | ||
| private ILearningHubSsoSecurityService learningHubSsoSecurityService = null!; | ||
| private IUserDataService userDataService = null!; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| userDataService = A.Fake<IUserDataService>(); | ||
| learningHubSsoSecurityService = A.Fake<ILearningHubSsoSecurityService>(); | ||
| A.CallTo(() => learningHubSsoSecurityService.VerifyHash("56789", "invalid-hash")).Returns(false); | ||
| A.CallTo(() => learningHubSsoSecurityService.VerifyHash("12345", "valid-hash")).Returns(true); | ||
| learningHubLinkService = new LearningHubLinkService(learningHubSsoSecurityService, userDataService); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_throws_exception_when_stored_sessionIdentifier_is_invalid() | ||
| { | ||
| // Given | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = $"{Guid.NewGuid()}_refId:1234", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| Action act = () => | ||
| learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| "invalid-guid" | ||
| ); | ||
|
|
||
| // Then | ||
| act.Should().Throw<LearningHubLinkingRequestException>() | ||
| .WithMessage("Invalid Learning Hub linking request session identifier."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_throws_exception_when_verifyHash_returns_false() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "invalid-hash", | ||
| State = $"{storedSessionIdentifier}_refId:56789", | ||
| UserId = 56789, | ||
| }; | ||
|
|
||
| // When | ||
| Action act = () => learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| act.Should().Throw<LearningHubLinkingRequestException>().WithMessage("Invalid Learning Hub UserId hash."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_throws_exception_when_sessionIdentifier_does_not_match() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = $"{Guid.NewGuid()}_refId:1234", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| Action act = () => learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| act.Should().Throw<LearningHubLinkingRequestException>() | ||
| .WithMessage("Invalid Learning Hub linking session."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ValidateLinkingRequestAndExtractDestinationResourceId_throws_exception_when_state_is_incomplete() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = $"{storedSessionIdentifier}", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| Action act = () => learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| act.Should().Throw<LearningHubLinkingRequestException>().WithMessage("Invalid Learning Hub linking state."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_throws_exception_when_state_sessionIdentifier_is_not_guid() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = "not-a-guid_refId:1234", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| Action act = () => learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| act.Should().Throw<LearningHubLinkingRequestException>() | ||
| .WithMessage("Invalid Learning Hub linking session."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_returns_null_when_resource_id_could_not_be_parsed() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = $"{storedSessionIdentifier}_refId:badInteger", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| var result = learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| result.Should().BeNull(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| ValidateLinkingRequestAndExtractDestinationResourceId_returns_resourceId_when_request_parsed_successfully() | ||
| { | ||
| // Given | ||
| var storedSessionIdentifier = Guid.NewGuid(); | ||
| var linkLearningHubRequest = new LinkLearningHubRequest | ||
| { | ||
| Hash = "valid-hash", | ||
| State = $"{storedSessionIdentifier}_refId:1234", | ||
| UserId = 12345, | ||
| }; | ||
|
|
||
| // When | ||
| var result = learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId( | ||
| linkLearningHubRequest, | ||
| storedSessionIdentifier.ToString() | ||
| ); | ||
|
|
||
| // Then | ||
| result.Should().Be(1234); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsLearningHubAccountLinked_returns_true_when_user_has_authid() | ||
| { | ||
| // Given | ||
| const int delegateId = 3; | ||
| const int learningHubAuthId = 1; | ||
|
|
||
| A.CallTo(() => userDataService.GetDelegateUserLearningHubAuthId(delegateId)) | ||
| .Returns(learningHubAuthId); | ||
|
|
||
| // When | ||
| var result = learningHubLinkService.IsLearningHubAccountLinked(delegateId); | ||
|
|
||
| // Then | ||
| result.Should().BeTrue(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void DelegateUserLearningHubAccountIsLinked_returns_false_when_user_does_not_have_authid() | ||
| { | ||
| // Given | ||
| const int delegateId = 3; | ||
|
|
||
| A.CallTo(() => userDataService.GetDelegateUserLearningHubAuthId(delegateId)) | ||
| .Returns(null); | ||
|
|
||
| // When | ||
| var result = learningHubLinkService.IsLearningHubAccountLinked(delegateId); | ||
|
|
||
| // Then | ||
| result.Should().BeFalse(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void LinkLearningHubAccountIfNotLinked_calls_service_to_update_delegate_authId_when_not_linked() | ||
| { | ||
| // Given | ||
| const int delegateId = 3; | ||
| const int learningHubAuthId = 1; | ||
|
|
||
| A.CallTo(() => userDataService.GetDelegateUserLearningHubAuthId(delegateId)) | ||
| .Returns(null); | ||
|
|
||
| // When | ||
| learningHubLinkService.LinkLearningHubAccountIfNotLinked(delegateId, learningHubAuthId); | ||
|
|
||
| // Then | ||
| A.CallTo(() => userDataService.SetDelegateUserLearningHubAuthId(A<int>._, A<int>._)) | ||
| .MustHaveHappenedOnceExactly(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void | ||
| LinkLearningHubAccountIfNotLinked_does_not_call_service_to_update_delegate_authId_when_already_linked() | ||
| { | ||
| // Given | ||
| const int delegateId = 3; | ||
| const int learningHubAuthId = 1; | ||
|
|
||
| A.CallTo(() => userDataService.GetDelegateUserLearningHubAuthId(delegateId)) | ||
| .Returns(learningHubAuthId); | ||
|
|
||
| // When | ||
| learningHubLinkService.LinkLearningHubAccountIfNotLinked(delegateId, learningHubAuthId); | ||
|
|
||
| // Then | ||
| A.CallTo(() => userDataService.SetDelegateUserLearningHubAuthId(A<int>._, A<int>._)) | ||
| .MustNotHaveHappened(); | ||
| } | ||
| } | ||
| } |
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
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.