Skip to content
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

Ensure evidence file names don't exceed limit #770

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading