Skip to content

Commit

Permalink
Ensure evidence file names don't exceed limit (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Dec 1, 2023
1 parent 457c0c8 commit 8d7b16d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IActionResult> OnPost()
var teacherDobChangeRequest = new TeacherDateOfBirthChangeRequest()
{
DateOfBirth = DateOfBirth!.Value,
EvidenceFileName = FileName!,
EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength),
EvidenceFileUrl = sasUri,
Trn = User.GetTrn()!
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<IActionResult> OnPost()
FirstName = FirstName!,
MiddleName = MiddleName,
LastName = LastName!,
EvidenceFileName = FileName!,
EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength),
EvidenceFileUrl = sasUri,
Trn = User.GetTrn()!
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 8d7b16d

Please sign in to comment.