Skip to content

Commit

Permalink
feat(suspicious): add configuration for niscode validity
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal authored and ArneD committed Nov 4, 2024
1 parent c114731 commit b1bd850
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 51 deletions.
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ nuget Microsoft.EntityFrameworkCore.Design 8.0.3
// VBR STUFF
nuget Be.Vlaanderen.Basisregisters.Api 23.2.0

nuget Be.Vlaanderen.Basisregisters.Auth.AcmIdm 3.1.0
nuget Be.Vlaanderen.Basisregisters.Auth.AcmIdm 3.2.0
nuget Be.Vlaanderen.Basisregisters.Aws.DistributedMutex 4.0.1

nuget Be.Vlaanderen.Basisregisters.BlobStore 4.0.0
Expand All @@ -54,7 +54,7 @@ nuget Be.Vlaanderen.Basisregisters.Build.Pipeline 7.2.5
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 21.14.1
nuget Be.Vlaanderen.Basisregisters.GrAr.Notifications 21.14.1
nuget Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded 4.0.0
nuget Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded 5.0.0
nuget Be.Vlaanderen.Basisregisters.Shaperon 10.0.2

// TEST STUFF
Expand Down
8 changes: 4 additions & 4 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ NUGET
NSwag.CodeGeneration.CSharp (>= 14.1)
NSwag.CodeGeneration.TypeScript (>= 14.1)
Swashbuckle.AspNetCore (6.7.3)
Be.Vlaanderen.Basisregisters.Auth.AcmIdm (3.1)
Be.Vlaanderen.Basisregisters.NisCodeService.Abstractions (>= 4.0)
Be.Vlaanderen.Basisregisters.Auth.AcmIdm (3.2)
Be.Vlaanderen.Basisregisters.NisCodeService.Abstractions (>= 5.0)
IdentityModel.AspNetCore.OAuth2Introspection (>= 6.2)
Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.3)
Microsoft.Extensions.DependencyInjection (>= 8.0)
Expand Down Expand Up @@ -195,10 +195,10 @@ NUGET
AWSSDK.SimpleNotificationService (>= 3.7.301.3)
System.Text.Json (>= 8.0.3)
Be.Vlaanderen.Basisregisters.Middleware.AddProblemJsonHeader (3.0)
Be.Vlaanderen.Basisregisters.NisCodeService.Abstractions (4.0)
Be.Vlaanderen.Basisregisters.NisCodeService.Abstractions (5.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded (4.0)
Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded (5.0)
Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
Be.Vlaanderen.Basisregisters.ProblemDetails (9.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using NisCodeService.Abstractions;
using Swashbuckle.AspNetCore.Filters;

Expand All @@ -37,18 +38,23 @@ public class SuspiciousCasesController : ApiController
private readonly IOrganisationWhiteList _organisationWhiteList;
private readonly INisCodeService _nisCodeService;

private readonly DateTime? _nisCodeValidFrom;

public SuspiciousCasesController(
IMediator mediator,
IActionContextAccessor actionContextAccessor,
IOvoCodeWhiteList ovoCodeWhiteList,
IOrganisationWhiteList organisationWhiteList,
INisCodeService nisCodeService)
INisCodeService nisCodeService,
IConfiguration configuration)
{
_mediator = mediator;
_actionContextAccessor = actionContextAccessor;
_ovoCodeWhiteList = ovoCodeWhiteList;
_organisationWhiteList = organisationWhiteList;
_nisCodeService = nisCodeService;

_nisCodeValidFrom = configuration.GetValue<DateTime?>("NisCodeValidFrom");
}

/// <summary>
Expand Down Expand Up @@ -141,6 +147,7 @@ public async Task<IActionResult> Detail(
private async Task<string?> DetermineNisCode(string? nisCode, CancellationToken cancellationToken)
{
var ovoCode = _actionContextAccessor.ActionContext!.HttpContext.FindOvoCodeClaim();

if (!string.IsNullOrWhiteSpace(ovoCode))
{
if (_ovoCodeWhiteList.IsWhiteListed(ovoCode))
Expand All @@ -153,7 +160,9 @@ public async Task<IActionResult> Detail(
return nisCode;
}

return await _nisCodeService.Get(ovoCode, cancellationToken);
var validFrom = _nisCodeValidFrom ?? DateTime.Now;

return await _nisCodeService.Get(ovoCode, validFrom, cancellationToken);
}

var orgCode = _actionContextAccessor.ActionContext!.HttpContext.FindOrgCodeClaim();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases
{
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading;
Expand All @@ -11,7 +12,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Configuration;
using Moq;
using NisCodeService.Abstractions;
using Xunit;
Expand All @@ -21,8 +22,8 @@ public class GivenDecentraleBijwerkerWithKnownOvoCode
private readonly Mock<IMediator> _mediator = new();
private readonly IActionResult _response;

private const string OvoCode = "OVO003105";
private const string ExpectedNisCode = "11202";
private const string OvoCode = "OVO002037";
private const string ExpectedNisCode = "31005";

public GivenDecentraleBijwerkerWithKnownOvoCode()
{
Expand All @@ -42,22 +43,20 @@ public GivenDecentraleBijwerkerWithKnownOvoCode()

Mock<INisCodeService> nisCodeService = new();
nisCodeService
.Setup(x => x.Get(OvoCode, CancellationToken.None))
.Setup(x => x.Get(OvoCode, It.IsAny<DateTime>(), CancellationToken.None))
.ReturnsAsync(ExpectedNisCode);

var suspiciousCasesController = new SuspiciousCasesController(
_mediator.Object,
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string>()),
nisCodeService.Object)
nisCodeService.Object,
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext
{
Request = { Headers = { new KeyValuePair<string, StringValues>("X-Filtering", "{ \"nisCode\": \"11001\"}") } }
}
HttpContext = new DefaultHttpContext()
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases
{
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading;
Expand All @@ -10,7 +11,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.Configuration;
using Moq;
using NisCodeService.Abstractions;
using Xunit;
Expand All @@ -37,22 +38,20 @@ public GivenDecentraleBijwerkerWithUnknownOvoCode()

Mock<INisCodeService> nisCodeService = new();
nisCodeService
.Setup(x => x.Get("OVO003105", CancellationToken.None))
.Setup(x => x.Get("OVO003105", It.IsAny<DateTime>(), CancellationToken.None))
.ReturnsAsync(string.Empty);

var suspiciousCasesController = new SuspiciousCasesController(
new Mock<IMediator>().Object,
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string>()),
nisCodeService.Object)
nisCodeService.Object,
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext
{
Request = { Headers = { new KeyValuePair<string, StringValues>("X-Filtering", "{ \"nisCode\": \"11001\"}") } }
}
HttpContext = new DefaultHttpContext()
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -40,7 +41,8 @@ public GivenGlobaleBijwerkerWithNonWhiteListedOrgCode()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string>()),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -43,7 +44,8 @@ public GivenGlobaleBijwerkerWithWhiteListedOrgCode()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string> { "0643634986" }),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -42,7 +43,8 @@ public GivenGlobaleBijwerkerWithoutNisCodeHeader()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string> { "0643634986" }),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -40,7 +41,8 @@ public GivenInterneBijwerkerWithNonWhiteListedOvoCode()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string> { "OVO002949" }),
new OrganisationWhiteList(new List<string>()),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -43,7 +44,8 @@ public GivenInterneBijwerkerWithWhiteListedOvoCode()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string> { "OVO002949" }),
new OrganisationWhiteList(new List<string>()),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.HardCoded;
Expand Down Expand Up @@ -42,7 +43,8 @@ public GivenInterneBijwerkerWithoutNisCodeHeader()
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string> { "OVO002949" }),
new OrganisationWhiteList(new List<string>()),
new HardCodedNisCodeService())
new HardCodedNisCodeService(),
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
Expand All @@ -12,6 +13,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.Abstractions;
Expand All @@ -25,8 +27,8 @@ public class GivenInvalidType

public GivenInvalidType()
{
const string ovoCode = "OVO003105";
const string expectedNisCode = "11202";
const string ovoCode = "OVO002037";
const string expectedNisCode = "31005";

Mock<IActionContextAccessor> actionContextAccessor = new();
actionContextAccessor
Expand All @@ -44,15 +46,16 @@ public GivenInvalidType()

Mock<INisCodeService> nisCodeService = new();
nisCodeService
.Setup(x => x.Get(ovoCode, CancellationToken.None))
.Setup(x => x.Get(ovoCode, It.IsAny<DateTime>(), CancellationToken.None))
.ReturnsAsync(expectedNisCode);

_suspiciousCasesController = new SuspiciousCasesController(
_mediator.Object,
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string>()),
nisCodeService.Object)
nisCodeService.Object,
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases
{
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading;
Expand All @@ -11,6 +12,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspi
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using Moq;
using NisCodeService.Abstractions;
Expand All @@ -24,8 +26,8 @@ public class GivenValidType

public GivenValidType()
{
const string ovoCode = "OVO003105";
const string expectedNisCode = "11202";
const string ovoCode = "OVO002037";
const string expectedNisCode = "31005";

Mock<IActionContextAccessor> actionContextAccessor = new();
actionContextAccessor
Expand All @@ -43,15 +45,16 @@ public GivenValidType()

Mock<INisCodeService> nisCodeService = new();
nisCodeService
.Setup(x => x.Get(ovoCode, CancellationToken.None))
.Setup(x => x.Get(ovoCode, It.IsAny<DateTime>(), CancellationToken.None))
.ReturnsAsync(expectedNisCode);

var suspiciousCasesController = new SuspiciousCasesController(
_mediator.Object,
actionContextAccessor.Object,
new OvoCodeWhiteList(new List<string>()),
new OrganisationWhiteList(new List<string>()),
nisCodeService.Object)
nisCodeService.Object,
new ConfigurationBuilder().Build())
{
ControllerContext = new ControllerContext
{
Expand Down
Loading

0 comments on commit b1bd850

Please sign in to comment.