Skip to content

Commit 43da6c1

Browse files
authored
Merge branch 'master' into NTBS-3177
2 parents d447d85 + 48c5ff9 commit 43da6c1

File tree

46 files changed

+2990
-6176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2990
-6176
lines changed

ntbs-integration-tests/ContactDetailsPages/ContactDetailsPageTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,33 @@ public async Task BreadcrumbForRegionPresentForRegionalUser()
5555
Assert.Contains("Permitted Phec", breadcrumbs);
5656
}
5757
}
58+
59+
[Fact]
60+
public async Task CurlyBracketsRemovedForUntrustedContent()
61+
{
62+
TestUser user = TestUser.UntrustedContentUser;
63+
var pageRoute = (RouteHelper.GetContactDetailsSubPath(user.Id, null));
64+
using (var client = Factory.WithUserAuth(user).CreateClientWithoutRedirects())
65+
{
66+
client.DefaultRequestHeaders.Authorization =
67+
new AuthenticationHeaderValue(UserAuthentication.SchemeName);
68+
// Arrange
69+
70+
var initialPage = await client.GetAsync(pageRoute);
71+
var pageContent = await GetDocumentAsync(initialPage);
72+
73+
// Assert
74+
var detailsContainer = pageContent.GetElementsByClassName("case-manager-details-container").Single().TextContent;
75+
76+
Assert.DoesNotContain("{", detailsContainer);
77+
Assert.DoesNotContain("}", detailsContainer);
78+
Assert.Contains("abc", detailsContainer);
79+
Assert.Contains("def", detailsContainer);
80+
Assert.Contains("ghi", detailsContainer);
81+
Assert.Contains("jkl", detailsContainer);
82+
Assert.Contains("mno", detailsContainer);
83+
}
84+
}
5885
}
5986
}
6087

ntbs-integration-tests/ContactDetailsPages/EditContactDetailsTests.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
using ntbs_service.Helpers;
99
using ntbs_service.Models.Validations;
1010
using Xunit;
11+
using System.Linq;
12+
using AngleSharp.Dom;
13+
using AngleSharp.Html.Dom;
1114

1215
namespace ntbs_integration_tests.ContactDetailsPages
1316
{
@@ -92,6 +95,50 @@ public async Task EditDetails_InvalidFields_DisplayErrors()
9295
}
9396
}
9497

98+
[Fact]
99+
public async Task EditDetails_InvalidFields_Curly_Brackets_DisplayErrors()
100+
{
101+
var user = TestUser.NationalTeamUser;
102+
var pageRoute = (RouteHelper.GetContactDetailsSubPath(user.Id, ContactDetailsSubPaths.Edit));
103+
using (var client = Factory.WithUserAuth(user).CreateClientWithoutRedirects())
104+
{
105+
// Arrange
106+
var initialPage = await client.GetAsync(pageRoute);
107+
var initialDocument = await GetDocumentAsync(initialPage);
108+
109+
var formData = new Dictionary<string, string>
110+
{
111+
["ContactDetails.Username"] = user.Username,
112+
["ContactDetails.JobTitle"] = "{Teacher}",
113+
["ContactDetails.PhoneNumberPrimary"] = "{0888192311}",
114+
["ContactDetails.PhoneNumberSecondary"] = "{0123871623}",
115+
["ContactDetails.EmailPrimary"] = "{primary@email}",
116+
["ContactDetails.EmailSecondary"] = "{secondary@email}",
117+
["ContactDetails.Notes"] = "{Notes}"
118+
};
119+
120+
// Act
121+
var result = await client.SendPostFormWithData(initialDocument, formData, pageRoute);
122+
123+
// Assert
124+
var resultDocument = await GetDocumentAsync(result);
125+
result.EnsureSuccessStatusCode();
126+
127+
resultDocument.AssertErrorMessage("job-title",
128+
string.Format(ValidationMessages.InvalidCharacter, "Job title"));
129+
resultDocument.AssertErrorMessage("phone-primary",
130+
string.Format(ValidationMessages.InvalidCharacter, "Phone number #1"));
131+
resultDocument.AssertErrorMessage("phone-secondary",
132+
string.Format(ValidationMessages.InvalidCharacter, "Phone number #2"));
133+
resultDocument.AssertErrorMessage("email-primary",
134+
string.Format(ValidationMessages.InvalidCharacter, "Email #1"));
135+
resultDocument.AssertErrorMessage("email-secondary",
136+
string.Format(ValidationMessages.InvalidCharacter, "Email #2"));
137+
resultDocument.AssertErrorMessage("notes",
138+
string.Format(ValidationMessages.InvalidCharacter, "Notes"));
139+
}
140+
}
141+
95142
[Fact]
96143
public async Task EditDetails_TabInNotes_DisplayErrors()
97144
{
@@ -185,5 +232,52 @@ public async Task EditDetails_EditingOtherUser_IsForbiddenForNonAdmin()
185232
Assert.Equal(HttpStatusCode.Forbidden, result.StatusCode);
186233
}
187234
}
235+
236+
[Fact]
237+
public async Task EditDetails_RemovesCurlyBracketsOnGet()
238+
{
239+
var user = TestUser.UntrustedContentUser;
240+
var pageRoute = (RouteHelper.GetContactDetailsSubPath(user.Id, ContactDetailsSubPaths.Edit));
241+
using (var client = Factory.WithUserAuth(user).CreateClientWithoutRedirects())
242+
{
243+
// Arrange
244+
var initialPage = await client.GetAsync(pageRoute);
245+
var pageContent = await GetDocumentAsync(initialPage);
246+
247+
// Act
248+
var jobTitle = pageContent.QuerySelector<IHtmlInputElement>("#ContactDetails_JobTitle").Value;
249+
var emailPrimary = pageContent.QuerySelector<IHtmlInputElement>("#ContactDetails_EmailPrimary").Value;
250+
var emailSecondary = pageContent.QuerySelector<IHtmlInputElement>("#ContactDetails_EmailSecondary").Value;
251+
var phoneNumberPrimary = pageContent.QuerySelector<IHtmlInputElement>("#ContactDetails_PhoneNumberPrimary").Value;
252+
var phoneNumberSecondary = pageContent.QuerySelector<IHtmlInputElement>("#ContactDetails_PhoneNumberSecondary").Value;
253+
var notes = pageContent.QuerySelector<IHtmlTextAreaElement>("#ContactDetails_Notes").Value;
254+
255+
// Assert
256+
Assert.DoesNotContain("{", jobTitle);
257+
Assert.DoesNotContain("}", jobTitle);
258+
Assert.Equal("abc", jobTitle);
259+
260+
Assert.DoesNotContain("{", emailPrimary);
261+
Assert.DoesNotContain("}", emailPrimary);
262+
Assert.Equal("def", emailPrimary);
263+
264+
Assert.DoesNotContain("{", emailSecondary);
265+
Assert.DoesNotContain("}", emailSecondary);
266+
Assert.Equal("ghi", emailSecondary);
267+
268+
Assert.DoesNotContain("{", phoneNumberPrimary);
269+
Assert.DoesNotContain("}", phoneNumberPrimary);
270+
Assert.Equal("jkl", phoneNumberPrimary);
271+
272+
Assert.DoesNotContain("{", phoneNumberSecondary);
273+
Assert.DoesNotContain("}", phoneNumberSecondary);
274+
Assert.Equal("", phoneNumberSecondary);
275+
276+
Assert.DoesNotContain("{", notes);
277+
Assert.DoesNotContain("}", notes);
278+
Assert.Equal("mno", notes);
279+
280+
}
281+
}
188282
}
189283
}

ntbs-integration-tests/Helpers/TestUser.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public class TestUser : ITestUser
2727
public IEnumerable<string> TbServiceCodes { get; }
2828
public bool IsReadOnly { get; }
2929
public bool IsActive { get; }
30+
public string JobTitle { get; set; }
31+
public string EmailPrimary { get; set; }
32+
public string EmailSecondary { get; set; }
33+
public string PhoneNumberPrimary { get; set; }
34+
public string PhoneNumberSecondary { get; set; }
35+
public string Notes { get; set; }
3036

3137
private TestUser(
3238
int id,
@@ -36,7 +42,13 @@ private TestUser(
3642
IEnumerable<string> adGroups,
3743
IEnumerable<string> tbServiceCodes = null,
3844
bool isReadOnly = false,
39-
bool isActive = true)
45+
bool isActive = true,
46+
string jobTitle = null,
47+
string emailPrimary = null,
48+
string emailSecondary = null,
49+
string phoneNumberPrimary = null,
50+
string phoneNumberSecondary = null,
51+
string notes = null)
4052
{
4153
Id = id;
4254
Username = username;
@@ -46,6 +58,12 @@ private TestUser(
4658
TbServiceCodes = tbServiceCodes ?? new List<string>();
4759
IsReadOnly = isReadOnly;
4860
IsActive = isActive;
61+
JobTitle = jobTitle;
62+
EmailPrimary = emailPrimary;
63+
EmailSecondary = emailSecondary;
64+
PhoneNumberPrimary = phoneNumberPrimary;
65+
PhoneNumberSecondary = phoneNumberSecondary;
66+
Notes = notes;
4967
}
5068

5169
public static IEnumerable<TestUser> GetAll() => new[]
@@ -61,7 +79,8 @@ public static IEnumerable<TestUser> GetAll() => new[]
6179
GatesheadCaseManager2,
6280
InactiveGatesheadCaseManager,
6381
Developer,
64-
ReadOnlyUser
82+
ReadOnlyUser,
83+
UntrustedContentUser
6584
};
6685

6786
public static TestUser ServiceUserForAbingdonAndPermitted = new TestUser(
@@ -159,5 +178,20 @@ public static IEnumerable<TestUser> GetAll() => new[]
159178
UserType.ServiceOrRegionalUser,
160179
new[] { Utilities.READ_ONLY_AD_GROUP },
161180
isReadOnly: true);
181+
182+
public static TestUser UntrustedContentUser = new TestUser
183+
(
184+
7893,
185+
"someone@ntbs.phe.com",
186+
"Someone",
187+
UserType.NationalTeam,
188+
new[] { Utilities.NATIONAL_AD_GROUP },
189+
jobTitle: "{abc}",
190+
emailPrimary: "{{def}}",
191+
emailSecondary: "g{{hi}}",
192+
phoneNumberPrimary: "j}{kl}",
193+
phoneNumberSecondary: "{{}}",
194+
notes: "}}mno"
195+
);
162196
}
163197
}

ntbs-integration-tests/Helpers/Utilities.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,23 @@ public static class Utilities
6060
public const int DRAFT_WITH_NO_START_DATES = 10075;
6161

6262
public const int CLINICAL_NOTIFICATION_EXTRA_PULMONARY_ID = 10080;
63-
63+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_ALERT = 10083;
64+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_TREATMENTEVENT = 10084;
65+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_TREATMENTEVENTS = 10085;
66+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_SOCIALCONTEXTVENUES = 10086;
67+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_SOCIALCONTEXTADDRESSES = 10087;
68+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_OVERVIEW = 10088;
69+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_SOCIALCONTEXTVENUE = 10089;
6470
public const int LATE_DOB_ID = 10090;
71+
public const int NOTIFIED_ID_WITH_TRANSFER_REQUEST_TO_REJECT = 10091;
72+
public const int NOTIFICATION_WITH_TRANSFER_REQUEST_TO_ACCEPT = 10092;
73+
public const int NOTIFICATION_WITH_TRANSFER = 10093;
74+
public const int NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_SOCIALCONTEXTADDRESS = 10094;
6575
public const int NOTIFICATION_DATE_TODAY = 10095;
6676
public const int NOTIFICATION_DATE_OVER_YEAR_AGO = 10096;
6777
public const int LINKED_NOTIFICATION_ABINGDON_TB_SERVICE = 10097;
6878
public const int LINK_NOTIFICATION_ROYAL_FREE_LONDON_TB_SERVICE = 10098;
6979

70-
public const int NOTIFIED_ID_WITH_TRANSFER_REQUEST_TO_REJECT = 10091;
71-
public const int NOTIFICATION_WITH_TRANSFER_REQUEST_TO_ACCEPT = 10092;
72-
public const int NOTIFICATION_WITH_TRANSFER = 10093;
7380

7481
public static int SPECIMEN_MATCHING_NOTIFICATION_ID1 = MockSpecimenService.MockSpecimenNotificationId1; // 10100
7582
public static int SPECIMEN_MATCHING_NOTIFICATION_ID2 = MockSpecimenService.MockSpecimenNotificationId2; // 10101
@@ -118,6 +125,8 @@ public static class Utilities
118125
public const int TRANSFER_REJECTED_ID = 20005;
119126
public const int TRANSFER_ALERT_ID_TO_ACCEPT_2 = 20006;
120127
public const int TRANSFER_ALERT_WITH_DATE = 20010;
128+
public const int TRANSFER_ALERT_DECLINED = 20011;
129+
121130

122131
public const int DRAFT_DATA_QUALITY_ALERT = 20007;
123132
public const int ALERT_TO_DISMISS_ID = 20008;
@@ -231,7 +240,10 @@ public static void SeedDatabase(NtbsContext context)
231240
context.Notification.AddRange(StopShareWithServicePageTests.GetSeedingNotifications());
232241
context.Notification.AddRange(ManualTestResultEditPagesTests.GetSeedingNotifications());
233242
context.Notification.AddRange(SocialContextVenueEditPageTests.GetSeedingNotifications());
243+
context.Notification.AddRange(SocialContextVenuesEditPageTests.GetSeedingNotifications());
234244
context.Notification.AddRange(SocialContextAddressEditPageTests.GetSeedingNotifications());
245+
context.Notification.AddRange(SocialContextAddressesEditPageTests.GetSeedingNotifications());
246+
context.Notification.AddRange(TreatmentEventsEditPageTests.GetSeedingNotifications());
235247
context.Notification.AddRange(TreatmentEventEditPageTests.GetSeedingNotifications());
236248
context.Notification.AddRange(ClinicalDetailsPageTests.GetSeedingNotifications());
237249
context.Notification.AddRange(ActionTransferPageTests.GetSeedingNotifications());
@@ -241,11 +253,12 @@ public static void SeedDatabase(NtbsContext context)
241253
context.Notification.AddRange(MBovisOccupationExposurePageTests.GetSeedingNotifications());
242254
context.Notification.AddRange(MBovisAnimalExposurePageTests.GetSeedingNotifications());
243255
context.Notification.AddRange(DraftEditPageTests.GetSeedingNotifications());
256+
context.Notification.AddRange(RejectTransferPageTests.GetSeedingNotifications());
244257

245-
context.TreatmentOutcome.AddRange(TreatmentEventEditPageTests.GetSeedingOutcomes());
258+
context.TreatmentOutcome.AddRange(TreatmentEventsEditPageTests.GetSeedingOutcomes());
246259

247260
context.Alert.AddRange(DraftEditPageTests.GetSeedingAlerts());
248-
261+
context.Alert.AddRange(RejectTransferPageTests.GetSeedingAlerts());
249262
context.SaveChanges();
250263
}
251264

@@ -268,7 +281,13 @@ private static IEnumerable<User> GetCaseManagers()
268281
AdGroups = string.Join(',', user.AdGroups),
269282
IsCaseManager = true,
270283
IsReadOnly = user.IsReadOnly,
271-
IsActive = user.IsActive
284+
IsActive = user.IsActive,
285+
JobTitle = user.JobTitle,
286+
PhoneNumberPrimary = user.PhoneNumberPrimary,
287+
PhoneNumberSecondary = user.PhoneNumberSecondary,
288+
EmailPrimary = user.EmailPrimary,
289+
EmailSecondary = user.EmailSecondary,
290+
Notes = user.Notes
272291
});
273292
}
274293

ntbs-integration-tests/NotificationPages/OverviewPageTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ public static IList<Notification> GetSeedingNotifications()
9393
TbServiceCode = Utilities.TBSERVICE_ABINGDON_COMMUNITY_HOSPITAL_ID
9494
}
9595
}
96+
},
97+
new Notification
98+
{
99+
NotificationId = Utilities.NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_OVERVIEW,
100+
NotificationStatus = NotificationStatus.Notified,
101+
SocialContextAddresses = new List<SocialContextAddress>
102+
{
103+
new SocialContextAddress
104+
{
105+
Details = "{{abc}}"
106+
},
107+
},
108+
SocialContextVenues = new List<SocialContextVenue>
109+
{
110+
new SocialContextVenue
111+
{
112+
Details = "{{def}}",
113+
Name = "{{ghi}}"
114+
}
115+
}
96116
}
97117
};
98118
}
@@ -458,6 +478,25 @@ public async Task OverviewPageContainsAnchorId_ForNotificationSubPath()
458478
});
459479
}
460480

481+
[Fact]
482+
public async Task OverviewPageRemovesCurlyBracketsFromComment()
483+
{
484+
// Arrange
485+
var url = GetCurrentPathForId(Utilities.NOTIFICATION_ID_WITH_CURLY_BRACKETS_IN_OVERVIEW);
486+
487+
// Act
488+
var document = await GetDocumentForUrlAsync(url);
489+
490+
// Asset
491+
var detailsContainer = document.GetElementById("maincontent").TextContent;
492+
493+
Assert.DoesNotContain("{", detailsContainer);
494+
Assert.DoesNotContain("}", detailsContainer);
495+
Assert.Contains("abc", detailsContainer);
496+
Assert.Contains("def", detailsContainer);
497+
Assert.Contains("ghi", detailsContainer);
498+
}
499+
461500
private void AssertEditOverview(IHtmlDocument document)
462501
{
463502
AssertSectionTitlesInDocument(document);

0 commit comments

Comments
 (0)