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

VIH-11093 Sonar fixes #1442

Merged
merged 9 commits into from
Nov 4, 2024
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 @@ -452,7 +452,7 @@ public async Task Should_return_booking_list_when_admin_search_by_multiple_crite
okResult.StatusCode.Should().Be(200);
}

private List<CaseTypeResponse> GetCaseTypesList()
private static List<CaseTypeResponse> GetCaseTypesList()
{
return new List<CaseTypeResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
using AdminWebsite.Models;
using AdminWebsite.Security;
using AdminWebsite.Services;
using AdminWebsite.UnitTests.Helper;
using FizzWare.NBuilder;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using AdminWebsite.Configuration;
using AdminWebsite.Contracts.Enums;
using AdminWebsite.Contracts.Requests;
using BookingsApi.Client;
using Autofac.Extras.Moq;
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V2.Requests;
using VideoApi.Contract.Responses;
using EndpointRequest = AdminWebsite.Contracts.Requests.EndpointRequest;
using LinkedParticipantRequest = AdminWebsite.Contracts.Requests.LinkedParticipantRequest;
using ParticipantRequest = AdminWebsite.Contracts.Requests.ParticipantRequest;
using V1 = BookingsApi.Contract.V1;

Expand Down Expand Up @@ -69,7 +64,7 @@ public void Should_throw_BookingsApiException()
BookingDetails = hearing
};

_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingAsync(It.IsAny<BookNewHearingRequest>()))
_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingWithCodeAsync(It.IsAny<BookNewHearingRequestV2>()))
.Throws(ClientException.ForBookingsAPI(HttpStatusCode.InternalServerError));

var response = _controller.Post(bookingRequest);
Expand All @@ -90,7 +85,7 @@ public void Should_throw_Exception()
BookingDetails = hearing
};

_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingAsync(It.IsAny<BookNewHearingRequest>()))
_mocker.Mock<IBookingsApiClient>().Setup(x => x.BookNewHearingWithCodeAsync(It.IsAny<BookNewHearingRequestV2>()))
.Throws(new Exception("Some internal error"));

var response = _controller.Post(bookingRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public async Task Should_process_participants()
&& x.LinkedParticipants == linkedParticipants)), Times.Once);
}

private HearingDetailsResponse InitHearing()
private static HearingDetailsResponse InitHearing()
{
var cases = new List<CaseResponse> { new CaseResponse { Name = "Test", Number = "123456" } };
var rep = Builder<ParticipantResponse>.CreateNew()
Expand Down
1 change: 1 addition & 0 deletions AdminWebsite/AdminWebsite/AdminWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<EmbeddedResource Remove="ClientApp\jasmine-tests\**" />
<Content Remove="ClientApp\jasmine-tests\**" />
<None Remove="ClientApp\jasmine-tests\**" />
<None Remove="Properties\ServiceDependencies\vh-admin-web-demo - Web Deploy\profile.arm.json" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace AdminWebsite.Attributes
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class HearingInputSanitizerAttribute : ActionFilterAttribute
public partial class HearingInputSanitizerAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (context.ActionArguments != null && context.ActionArguments.ContainsKey("request"))
if (context.ActionArguments.TryGetValue("request", out var argument))
{
switch (context.ActionArguments["request"])
switch (argument)
{
case BookNewHearingRequest newHearingRequest:
newHearingRequest.HearingRoomName = Sanitize(newHearingRequest.HearingRoomName);
Expand Down Expand Up @@ -74,9 +74,12 @@ private static string Sanitize(string input)
return input;
}

var regex = new Regex(@"<(.*?)>", RegexOptions.Compiled);
var regex = InputRegex();

return regex.Replace(input, string.Empty);
}

[GeneratedRegex(@"<(.*?)>", RegexOptions.Compiled)]
private static partial Regex InputRegex();
}
}
38 changes: 20 additions & 18 deletions AdminWebsite/AdminWebsite/ClientApp/acessability_lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,28 @@ async function runPa11y(filename) {
}

const run = () => {
return new Promise(async (resolve, reject) => {
try {
const result = [];
const files = await getHtmlFiles();
output(`detected ${files.length} html files to parse`);
for (let index = 0; index < files.length; index += 1) {
const lintErrors = await runPa11y(files[index]);
if (lintErrors.issues.length > 0) {
result.push({
file: lintErrors.pageUrl,
issues: lintErrors.issues
});
return new Promise((resolve, reject) => {
(async () => {
try {
const result = [];
const files = await getHtmlFiles();
output(`detected ${files.length} html files to parse`);
for (let index = 0; index < files.length; index += 1) {
const lintErrors = await runPa11y(files[index]);
if (lintErrors.issues.length > 0) {
result.push({
file: lintErrors.pageUrl,
issues: lintErrors.issues
});
}
const doneDegree = Math.round((index / files.length) * 100);
output(`${doneDegree}% done, completed ${files[index]}`);
}
const doneDegree = Math.round((index / files.length) * 100);
output(`${doneDegree}% done, completed ${files[index]}`);
resolve(result);
} catch (err) {
reject(err);
}
resolve(result);
} catch (err) {
reject(err);
}
})();
});
};

Expand Down
Loading
Loading