Skip to content

Commit a256881

Browse files
Merge pull request #330 from TransactionProcessing/task/#4_emailconfirmation
Email Confirmation added
2 parents 80553c5 + 4b0680e commit a256881

16 files changed

Lines changed: 677 additions & 505 deletions

File tree

SecurityService.BusinessLogic/ISecurityServiceManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ namespace SecurityService.BusinessLogic
1111

1212
public interface ISecurityServiceManager
1313
{
14+
Task<Boolean> ConfirmEmailAddress(String userName,
15+
String confirmEmailToken,
16+
CancellationToken cancellationToken);
17+
1418
Task<(Boolean, String)> ChangePassword(String userName,
1519
String currentPassword,
1620
String newPassword,
@@ -156,6 +160,7 @@ Task<Guid> CreateUser(String givenName,
156160
String phoneNumber,
157161
Dictionary<String, String> claims,
158162
List<String> roles,
163+
Boolean? requireRegistrationEmail,
159164
CancellationToken cancellationToken);
160165

161166
/// <summary>

SecurityService.BusinessLogic/SecurityServiceManager.cs

Lines changed: 395 additions & 413 deletions
Large diffs are not rendered by default.

SecurityService.BusinessLogic/TestMessagingServiceClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using MessagingService.Client;
77
using MessagingService.DataTransferObjects;
8+
using Shared.Logger;
89

910
public class TestMessagingServiceClient : IMessagingServiceClient
1011
{
@@ -14,6 +15,7 @@ public class TestMessagingServiceClient : IMessagingServiceClient
1415
public async Task<SendEmailResponse> SendEmail(String accessToken,
1516
SendEmailRequest request,
1617
CancellationToken cancellationToken) {
18+
Logger.LogWarning($"Sending Email {request.Subject}");
1719
this.LastEmailRequest = request;
1820
return new SendEmailResponse {
1921
MessageId = Guid.NewGuid()

SecurityService.DataTransferObjects/Requests/CreateUserRequest.cs

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,31 @@
99
[ExcludeFromCodeCoverage]
1010
public class CreateUserRequest
1111
{
12-
/// <summary>
13-
/// Gets or sets the email address.
14-
/// </summary>
15-
/// <value>
16-
/// The email address.
17-
/// </value>
1812
[JsonProperty("email_address")]
1913
public String EmailAddress { get; set; }
2014

21-
/// <summary>
22-
/// Gets or sets the phone number.
23-
/// </summary>
24-
/// <value>
25-
/// The phone number.
26-
/// </value>
2715
[JsonProperty("phone_number")]
2816
public String PhoneNumber { get; set; }
2917

30-
/// <summary>
31-
/// Gets or sets the password.
32-
/// </summary>
33-
/// <value>
34-
/// The password.
35-
/// </value>
3618
[JsonProperty("password")]
3719
public String Password { get; set; }
3820

39-
/// <summary>
40-
/// Gets or sets the claims.
41-
/// </summary>
42-
/// <value>
43-
/// The claims.
44-
/// </value>
4521
[JsonProperty("claims")]
4622
public Dictionary<String, String> Claims { get; set; }
4723

48-
/// <summary>
49-
/// Gets or sets the roles.
50-
/// </summary>
51-
/// <value>
52-
/// The roles.
53-
/// </value>
5424
[JsonProperty("roles")]
5525
public List<String> Roles { get; set; }
56-
57-
/// <summary>
58-
/// Gets or sets the name of the given.
59-
/// </summary>
60-
/// <value>
61-
/// The name of the given.
62-
/// </value>
26+
6327
[JsonProperty("given_name")]
6428
public String GivenName { get; set; }
65-
66-
/// <summary>
67-
/// Gets or sets the name of the middle.
68-
/// </summary>
69-
/// <value>
70-
/// The name of the middle.
71-
/// </value>
29+
7230
[JsonProperty("middle_name")]
7331
public String MiddleName { get; set; }
74-
75-
/// <summary>
76-
/// Gets or sets the name of the family.
77-
/// </summary>
78-
/// <value>
79-
/// The name of the family.
80-
/// </value>
32+
8133
[JsonProperty("family_name")]
8234
public String FamilyName { get; set; }
35+
36+
[JsonProperty("require_registration_email")]
37+
public Boolean? RequireRegistrationEmail { get; set; }
8338
}
8439
}

SecurityService.OpenIdConnect.IntegrationTests/Common/TestingContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TestingContext
2020
public TokenResponse TokenResponse;
2121

2222
public String ResetPasswordLink { get; set; }
23+
public String ConfirmEmailAddressLink { get; set; }
2324

2425
public TestingContext()
2526
{

SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ Background:
1818
| email | Email | Email and Email Verified Flags | email_verified,email |
1919

2020
Given I create the following clients
21-
| ClientId | Name | Secret | Scopes | GrantTypes | RedirectUris | PostLogoutRedirectUris | RequireConsent | AllowOfflineAccess |
22-
| estateUIClient | Merchant Client | Secret1 | estateManagement,openid,email,profile | hybrid | https://[url]:[port]/signin-oidc | https://[url]:[port]/signout-oidc | false | true |
21+
| ClientId | Name | Secret | Scopes | GrantTypes | RedirectUris | PostLogoutRedirectUris | RequireConsent | AllowOfflineAccess | ClientUri |
22+
| estateUIClient | Merchant Client | Secret1 | estateManagement,openid,email,profile | hybrid | https://[url]:[port]/signin-oidc | https://[url]:[port]/signout-oidc | false | true | https://[url]:[port] |
2323

24+
@PRTest
25+
Scenario: Create User and Login
2426
Given I create the following users
25-
| Email Address | Password | Phone Number | Given Name | Middle Name | Family Name | Claims | Roles |
27+
| Email Address | Password | Phone Number | Given Name | Middle Name | Family Name | Claims | Roles |
2628
| estateuser@testestate1.co.uk | 123456 | 123456789 | Test | | User 1 | EstateId:1 | Estate |
27-
28-
@PRTest
29-
Scenario: Access Secure Area In Application
29+
Then I get an email with a confirm email address link
30+
When I navigate to the confirm email address
31+
Then I am presented with the confirm email address successful screen
3032
Given I am on the application home page
3133
When I click the 'Privacy' link
3234
Then I am presented with a login screen
3335
When I login with the username 'estateuser@testestate1.co.uk' and password '123456'
3436
Then I am presented with the privacy screen
37+

SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLogin.feature.cs

Lines changed: 43 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SecurityService.OpenIdConnect.IntegrationTests/UserLogin/UserLoginSteps.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ namespace SecurityService.IntegrationTests.UserLogin
66
using System.Collections.Generic;
77
using System.Collections.ObjectModel;
88
using System.Linq;
9+
using System.Net;
10+
using System.Net.Http;
911
using System.Text;
12+
using System.Threading;
1013
using System.Threading.Tasks;
14+
using HtmlAgilityPack;
1115
using IntergrationTests.Common;
16+
using Newtonsoft.Json;
1217
using OpenQA.Selenium;
1318
using Shared.IntegrationTesting;
1419
using Shouldly;
@@ -91,6 +96,44 @@ await Retry.For(async () =>
9196

9297
}
9398

99+
[Then(@"I get an email with a confirm email address link")]
100+
public async Task ThenIGetAnEmailWithAConfirmEmailAddressLink()
101+
{
102+
String requestUri = $"{this.TestingContext.DockerHelper.securityServiceBaseAddressResolver("")}/api/developer/lastemail";
103+
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);
104+
105+
var response = await this.TestingContext.DockerHelper.httpClient.SendAsync(requestMessage, CancellationToken.None);
106+
107+
response.StatusCode.ShouldBe(HttpStatusCode.OK);
108+
109+
var emailMessage = new
110+
{
111+
MessageId = Guid.Empty,
112+
Body = String.Empty
113+
};
114+
var x = JsonConvert.DeserializeAnonymousType(await response.Content.ReadAsStringAsync(CancellationToken.None), emailMessage);
115+
116+
HtmlDocument doc = new HtmlDocument();
117+
doc.LoadHtml(x.Body);
118+
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//a[@href]");
119+
String confirmEmailAddressLink = nodes[0].GetAttributeValue("href", string.Empty);
120+
confirmEmailAddressLink.ShouldNotBeNullOrEmpty();
121+
122+
// Cache the link
123+
this.TestingContext.ConfirmEmailAddressLink = confirmEmailAddressLink;
124+
}
125+
126+
[When(@"I navigate to the confirm email address")]
127+
public void WhenINavigateToTheConfirmEmailAddress()
128+
{
129+
this.WebDriver.Navigate().GoToUrl(this.TestingContext.ConfirmEmailAddressLink);
130+
}
131+
132+
[Then(@"I am presented with the confirm email address successful screen")]
133+
public void ThenIAmPresentedWithTheConfirmEmailAddressSuccessfulScreen() {
134+
IWebElement webElement = this.WebDriver.FindElement(By.Id("userMessage"));
135+
webElement.Text.ShouldBe("Thanks for confirming your email address, you should receive a welcome email soon.");
136+
}
94137

95138
}
96139

@@ -139,5 +182,6 @@ public static async Task ClickButton(this IWebDriver webDriver,
139182
webElement.ShouldNotBeNull();
140183
webElement.Click();
141184
}
185+
142186
}
143187
}

0 commit comments

Comments
 (0)