From 6c2b55a59901cb35ce5af12bf6276c4f3ca8669d Mon Sep 17 00:00:00 2001 From: James Gunn Date: Fri, 1 Dec 2023 12:47:41 +0000 Subject: [PATCH] Ensure evidence file names don't exceed limit --- .../Pages/Account/OfficialDateOfBirth/Confirm.cshtml.cs | 2 +- .../Pages/Account/OfficialName/Confirm.cshtml.cs | 2 +- .../TeacherIdentity.AuthServer/Services/DqtApi/DqtApiClient.cs | 2 ++ .../src/TeacherIdentity.AuthServer/StringExtensions.cs | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialDateOfBirth/Confirm.cshtml.cs b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialDateOfBirth/Confirm.cshtml.cs index f3d74f720..1ebde14d0 100644 --- a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialDateOfBirth/Confirm.cshtml.cs +++ b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialDateOfBirth/Confirm.cshtml.cs @@ -48,7 +48,7 @@ public async Task OnPost() var teacherDobChangeRequest = new TeacherDateOfBirthChangeRequest() { DateOfBirth = DateOfBirth!.Value, - EvidenceFileName = FileName!, + EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength), EvidenceFileUrl = sasUri, Trn = User.GetTrn()! }; diff --git a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialName/Confirm.cshtml.cs b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialName/Confirm.cshtml.cs index ae394cd53..4bfc3f091 100644 --- a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialName/Confirm.cshtml.cs +++ b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialName/Confirm.cshtml.cs @@ -68,7 +68,7 @@ public async Task OnPost() FirstName = FirstName!, MiddleName = MiddleName, LastName = LastName!, - EvidenceFileName = FileName!, + EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength), EvidenceFileUrl = sasUri, Trn = User.GetTrn()! }; diff --git a/dotnet-authserver/src/TeacherIdentity.AuthServer/Services/DqtApi/DqtApiClient.cs b/dotnet-authserver/src/TeacherIdentity.AuthServer/Services/DqtApi/DqtApiClient.cs index 0638274c8..c43172567 100644 --- a/dotnet-authserver/src/TeacherIdentity.AuthServer/Services/DqtApi/DqtApiClient.cs +++ b/dotnet-authserver/src/TeacherIdentity.AuthServer/Services/DqtApi/DqtApiClient.cs @@ -7,6 +7,8 @@ namespace TeacherIdentity.AuthServer.Services.DqtApi; public class DqtApiClient : IDqtApiClient { + public const int MaxEvidenceFileNameLength = 100; + private readonly HttpClient _client; private static JsonSerializerOptions _serializerOptions { get; } = new JsonSerializerOptions(JsonSerializerDefaults.Web) diff --git a/dotnet-authserver/src/TeacherIdentity.AuthServer/StringExtensions.cs b/dotnet-authserver/src/TeacherIdentity.AuthServer/StringExtensions.cs index 59eb34352..667bc16d5 100644 --- a/dotnet-authserver/src/TeacherIdentity.AuthServer/StringExtensions.cs +++ b/dotnet-authserver/src/TeacherIdentity.AuthServer/StringExtensions.cs @@ -3,4 +3,6 @@ namespace TeacherIdentity.AuthServer; public static class StringExtensions { public static string? ToNullIfEmpty(this string? value) => string.IsNullOrWhiteSpace(value) ? null : value; + + public static string Truncate(this string value, int maxLength) => value.Length > maxLength ? value[..maxLength] : value; }