From 6db65a1354d47dda2fda8b2c9ed89908492da098 Mon Sep 17 00:00:00 2001 From: jvandaal Date: Mon, 4 Dec 2023 16:51:57 +0100 Subject: [PATCH] feat: niscode auth filtering --- Basisregisters.IntegrationDb.sln | 15 ++ paket.dependencies | 3 +- paket.lock | 152 +++++++++++++++++- .../Infrastructure/Modules/ApiModule.cs | 11 +- .../Infrastructure/Startup.cs | 4 +- .../SuspiciousCasesController.cs | 61 ++++++- .../appsettings.json | 4 + .../paket.references | 1 + .../appsettings.json | 4 + ...grationDb.SuspiciousCases.Api.Tests.csproj | 9 ++ ...ivenDecentraleBijwerkerWithKnownOvoCode.cs | 82 ++++++++++ ...enDecentraleBijwerkerWithUnknownOvoCode.cs | 67 ++++++++ ...terneBijwerkerWithNonWhiteListedOvoCode.cs | 62 +++++++ ...nInterneBijwerkerWithWhiteListedOvoCode.cs | 74 +++++++++ ...ivenDecentraleBijwerkerWithKnownOvoCode.cs | 80 +++++++++ ...enDecentraleBijwerkerWithUnknownOvoCode.cs | 67 ++++++++ ...terneBijwerkerWithNonWhiteListedOvoCode.cs | 62 +++++++ ...nInterneBijwerkerWithWhiteListedOvoCode.cs | 73 +++++++++ .../paket.references | 8 + 19 files changed, 829 insertions(+), 10 deletions(-) create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.csproj create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs create mode 100644 test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/paket.references diff --git a/Basisregisters.IntegrationDb.sln b/Basisregisters.IntegrationDb.sln index 5edb2d57..b4b220af 100644 --- a/Basisregisters.IntegrationDb.sln +++ b/Basisregisters.IntegrationDb.sln @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Basisregisters.IntegrationD EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Basisregisters.IntegrationDb.Consumer.BuildingUnit", "src\Basisregisters.IntegrationDb.Consumer.BuildingUnit\Basisregisters.IntegrationDb.Consumer.BuildingUnit.csproj", "{D3170071-1C14-4B17-99A2-96F718097AA1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests", "test\Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests\Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.csproj", "{2046F886-AA42-4EAD-A8FC-F8FC10A743F9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -86,6 +88,18 @@ Global {F3D39574-A172-40C5-A072-D33D19576419}.Release|x86.Build.0 = Release|Any CPU {012CD10E-1EDE-4014-B7CE-B870E62D1BEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {012CD10E-1EDE-4014-B7CE-B870E62D1BEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|x64.ActiveCfg = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|x64.Build.0 = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|x86.ActiveCfg = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Debug|x86.Build.0 = Debug|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|Any CPU.Build.0 = Release|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|x64.ActiveCfg = Release|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|x64.Build.0 = Release|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|x86.ActiveCfg = Release|Any CPU + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -93,6 +107,7 @@ Global GlobalSection(NestedProjects) = preSolution {F3D39574-A172-40C5-A072-D33D19576419} = {C2F8FF63-7A48-4179-A720-86206C42F496} {012CD10E-1EDE-4014-B7CE-B870E62D1BEC} = {A5E1149A-0437-4CD0-93A2-6E7E059C74BE} + {2046F886-AA42-4EAD-A8FC-F8FC10A743F9} = {A5E1149A-0437-4CD0-93A2-6E7E059C74BE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2EB87445-E263-4E1E-89CC-3839170028E5} diff --git a/paket.dependencies b/paket.dependencies index 098fa2f5..a72abbf5 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -56,12 +56,12 @@ nuget Be.Vlaanderen.Basisregisters.Build.Pipeline 6.0.5 nuget Be.Vlaanderen.Basisregisters.DataDog.Tracing.Autofac 5.1.0 nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 20.6.0 nuget Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Consumer 4.9.1 +nuget Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded 1.3.4 nuget Be.Vlaanderen.Basisregisters.Shaperon 9.0.1 // TEST STUFF nuget Microsoft.NET.Test.Sdk 17.3.1 nuget Microsoft.NET.StringTools 17.8.3 -//nuget Microsoft.TestPlatform.TestHost 17.3.1 nuget Microsoft.NETCore.Platforms 6.0.6 nuget Be.Vlaanderen.Basisregisters.DockerUtilities 1.0.1 nuget Microsoft.AspNetCore.Mvc.Testing 6.0.11 @@ -69,6 +69,7 @@ nuget Microsoft.AspNetCore.TestHost 6.0.11 nuget FluentAssertions 6.5.1 nuget xunit.runner.visualstudio 2.4.3 nuget xunit.categories 2.0.6 +nuget Moq 4.17.2 nuget Serilog 2.10.0 nuget Serilog.Settings.Configuration 3.3.0 diff --git a/paket.lock b/paket.lock index 53c466dc..ecfb6678 100644 --- a/paket.lock +++ b/paket.lock @@ -216,6 +216,9 @@ NUGET Be.Vlaanderen.Basisregisters.NisCodeService.Abstractions (1.3.4) Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0) Microsoft.Extensions.Logging.Abstractions (>= 6.0.3) + Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded (1.3.4) + Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0) + Microsoft.Extensions.Logging.Abstractions (>= 6.0.3) Be.Vlaanderen.Basisregisters.ProblemDetails (8.0.1) System.Reflection.Metadata (>= 6.0.1) Be.Vlaanderen.Basisregisters.Shaperon (9.0.1) @@ -227,6 +230,17 @@ NUGET BlackFox.VsWhere (1.1) FSharp.Core (>= 4.2.3) Microsoft.Win32.Registry (>= 4.7) + Castle.Core (4.4.1) + NETStandard.Library (>= 1.6.1) + System.Collections.Specialized (>= 4.3) + System.ComponentModel (>= 4.3) + System.ComponentModel.TypeConverter (>= 4.3) + System.Diagnostics.TraceSource (>= 4.3) + System.Dynamic.Runtime (>= 4.3) + System.Reflection (>= 4.3) + System.Reflection.Emit (>= 4.3) + System.Reflection.TypeExtensions (>= 4.3) + System.Xml.XmlDocument (>= 4.3) Confluent.Kafka (2.3) librdkafka.redist (>= 2.3) System.Memory (>= 4.5) @@ -690,6 +704,9 @@ NUGET Microsoft.Win32.SystemEvents (4.7) Microsoft.NETCore.Platforms (>= 3.1) Mono.Posix.NETStandard (1.0) + Moq (4.17.2) + Castle.Core (>= 4.4.1) + System.Threading.Tasks.Extensions (>= 4.5.4) MSBuild.StructuredLogger (2.1.545) Microsoft.Build (>= 16.10) Microsoft.Build.Framework (>= 16.10) @@ -780,6 +797,9 @@ NUGET NuGet.Versioning (6.7) Parlot (0.0.23) Polly (7.2.3) + runtime.native.System (4.3) + Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.NETCore.Targets (>= 1.1) Scrutor (3.0.1) Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1) Microsoft.Extensions.DependencyModel (>= 2.1) @@ -839,6 +859,43 @@ NUGET System.Runtime (>= 4.3) System.Collections.Immutable (6.0) System.Runtime.CompilerServices.Unsafe (>= 6.0) + System.Collections.NonGeneric (4.3) + System.Diagnostics.Debug (>= 4.3) + System.Globalization (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) + System.Collections.Specialized (4.3) + System.Collections.NonGeneric (>= 4.3) + System.Globalization (>= 4.3) + System.Globalization.Extensions (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) + System.ComponentModel (4.3) + System.Runtime (>= 4.3) + System.ComponentModel.Primitives (4.3) + System.ComponentModel (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.ComponentModel.TypeConverter (4.3) + System.Collections (>= 4.3) + System.Collections.NonGeneric (>= 4.3) + System.Collections.Specialized (>= 4.3) + System.ComponentModel (>= 4.3) + System.ComponentModel.Primitives (>= 4.3) + System.Globalization (>= 4.3) + System.Linq (>= 4.3) + System.Reflection (>= 4.3) + System.Reflection.Extensions (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Reflection.TypeExtensions (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) System.Configuration.ConfigurationManager (4.7) System.Security.Cryptography.ProtectedData (>= 4.7) System.Security.Permissions (>= 4.7) @@ -858,14 +915,46 @@ NUGET System.Diagnostics.DiagnosticSource (6.0.1) System.Runtime.CompilerServices.Unsafe (>= 6.0) System.Diagnostics.EventLog (6.0) + System.Diagnostics.TraceSource (4.3) + Microsoft.NETCore.Platforms (>= 1.1) + runtime.native.System (>= 4.3) + System.Collections (>= 4.3) + System.Diagnostics.Debug (>= 4.3) + System.Globalization (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) System.Drawing.Common (4.7) Microsoft.NETCore.Platforms (>= 3.1) Microsoft.Win32.SystemEvents (>= 4.7) + System.Dynamic.Runtime (4.3) + System.Collections (>= 4.3) + System.Diagnostics.Debug (>= 4.3) + System.Linq (>= 4.3) + System.Linq.Expressions (>= 4.3) + System.ObjectModel (>= 4.3) + System.Reflection (>= 4.3) + System.Reflection.Emit (>= 4.3) + System.Reflection.Emit.ILGeneration (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Reflection.TypeExtensions (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) System.Formats.Asn1 (6.0) System.Globalization (4.3) Microsoft.NETCore.Platforms (>= 1.1) Microsoft.NETCore.Targets (>= 1.1) System.Runtime (>= 4.3) + System.Globalization.Extensions (4.3) + Microsoft.NETCore.Platforms (>= 1.1) + System.Globalization (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Runtime.InteropServices (>= 4.3) System.IdentityModel.Tokens.Jwt (6.10) Microsoft.IdentityModel.JsonWebTokens (>= 6.10) Microsoft.IdentityModel.Tokens (>= 6.10) @@ -893,8 +982,32 @@ NUGET System.Resources.ResourceManager (>= 4.3) System.Runtime (>= 4.3) System.Runtime.Extensions (>= 4.3) + System.Linq.Expressions (4.3) + System.Collections (>= 4.3) + System.Diagnostics.Debug (>= 4.3) + System.Globalization (>= 4.3) + System.IO (>= 4.3) + System.Linq (>= 4.3) + System.ObjectModel (>= 4.3) + System.Reflection (>= 4.3) + System.Reflection.Emit (>= 4.3) + System.Reflection.Emit.ILGeneration (>= 4.3) + System.Reflection.Emit.Lightweight (>= 4.3) + System.Reflection.Extensions (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Reflection.TypeExtensions (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Threading (>= 4.3) System.Memory (4.5.5) System.Numerics.Vectors (4.5) + System.ObjectModel (4.3) + System.Collections (>= 4.3) + System.Diagnostics.Debug (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Threading (>= 4.3) System.Reactive (5.0) System.Reflection (4.3) Microsoft.NETCore.Platforms (>= 1.1) @@ -902,12 +1015,35 @@ NUGET System.IO (>= 4.3) System.Reflection.Primitives (>= 4.3) System.Runtime (>= 4.3) + System.Reflection.Emit (4.3) + System.IO (>= 4.3) + System.Reflection (>= 4.3) + System.Reflection.Emit.ILGeneration (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Runtime (>= 4.3) + System.Reflection.Emit.ILGeneration (4.3) + System.Reflection (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Runtime (>= 4.3) + System.Reflection.Emit.Lightweight (4.3) + System.Reflection (>= 4.3) + System.Reflection.Emit.ILGeneration (>= 4.3) + System.Reflection.Primitives (>= 4.3) + System.Runtime (>= 4.3) + System.Reflection.Extensions (4.3) + Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.NETCore.Targets (>= 1.1) + System.Reflection (>= 4.3) + System.Runtime (>= 4.3) System.Reflection.Metadata (6.0.1) System.Collections.Immutable (>= 6.0) System.Reflection.Primitives (4.3) Microsoft.NETCore.Platforms (>= 1.1) Microsoft.NETCore.Targets (>= 1.1) System.Runtime (>= 4.3) + System.Reflection.TypeExtensions (4.3) + System.Reflection (>= 4.3) + System.Runtime (>= 4.3) System.Resources.Extensions (4.6) System.Resources.ResourceManager (4.3) Microsoft.NETCore.Platforms (>= 1.1) @@ -968,12 +1104,15 @@ NUGET System.Text.Encodings.Web (>= 6.0) System.Text.RegularExpressions (4.3) System.Runtime (>= 4.3) + System.Threading (4.3) + System.Runtime (>= 4.3) + System.Threading.Tasks (>= 4.3) System.Threading.Tasks (4.3) Microsoft.NETCore.Platforms (>= 1.1) Microsoft.NETCore.Targets (>= 1.1) System.Runtime (>= 4.3) System.Threading.Tasks.Dataflow (6.0) - System.Threading.Tasks.Extensions (4.5.2) + System.Threading.Tasks.Extensions (4.5.4) System.Windows.Extensions (4.7) System.Drawing.Common (>= 4.7) System.Xml.ReaderWriter (4.3) @@ -992,6 +1131,17 @@ NUGET System.Text.RegularExpressions (>= 4.3) System.Threading.Tasks (>= 4.3) System.Threading.Tasks.Extensions (>= 4.3) + System.Xml.XmlDocument (4.3) + System.Collections (>= 4.3) + System.Diagnostics.Debug (>= 4.3) + System.Globalization (>= 4.3) + System.IO (>= 4.3) + System.Resources.ResourceManager (>= 4.3) + System.Runtime (>= 4.3) + System.Runtime.Extensions (>= 4.3) + System.Text.Encoding (>= 4.3) + System.Threading (>= 4.3) + System.Xml.ReaderWriter (>= 4.3) TimeZoneConverter (3.5) xunit (2.4.1) xunit.analyzers (>= 0.10) diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Modules/ApiModule.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Modules/ApiModule.cs index 9ce399a7..2ae9ea79 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Modules/ApiModule.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Modules/ApiModule.cs @@ -1,15 +1,17 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Infrastructure.Modules { + using System.Collections.Generic; using Autofac; using Autofac.Extensions.DependencyInjection; - using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; using Be.Vlaanderen.Basisregisters.Api.Exceptions; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; using Be.Vlaanderen.Basisregisters.DataDog.Tracing.Microsoft; using Be.Vlaanderen.Basisregisters.DependencyInjection; - using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; + using NisCodeService.HardCoded.Extensions; public class ApiModule : Module { @@ -40,6 +42,11 @@ protected override void Load(ContainerBuilder builder) _services.AddAcmIdmAuthorizationHandlers(); + var ovoCodeWhiteList = _configuration.GetSection("OvoCodeWhiteList").Get>(); + _services + .AddHardCodedNisCodeService() + .AddOvoCodeWhiteList(ovoCodeWhiteList); + builder.Populate(_services); } } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs index 259992b4..3091ecb4 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/Infrastructure/Startup.cs @@ -106,8 +106,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services) } } .EnableJsonErrorActionFilterOption()) - .Configure(_configuration.GetSection("ResponseOptions")); - //.AddSingleton(); + .Configure(_configuration.GetSection("ResponseOptions")) + .AddSingleton(); // Used to retrieve the authenticated user claims. var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new ApiModule(_configuration, services, _loggerFactory)); diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs index dd1f0051..069c29c6 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/SuspiciousCasesController.cs @@ -4,6 +4,7 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api using System.Threading.Tasks; using Be.Vlaanderen.Basisregisters.Api; using Be.Vlaanderen.Basisregisters.Api.Search.Filtering; + using Be.Vlaanderen.Basisregisters.Auth; using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; using Detail; using List; @@ -11,6 +12,8 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using NisCodeService.Abstractions; [ApiVersion("2.0")] [AdvertiseApiVersions("2.0")] @@ -19,17 +22,47 @@ namespace Basisregisters.IntegrationDb.SuspiciousCases.Api public class SuspiciousCasesController : ApiController { private readonly IMediator _mediator; + private readonly IActionContextAccessor _actionContextAccessor; + private readonly IOvoCodeWhiteList _ovoCodeWhiteList; + private readonly INisCodeService _nisCodeService; - public SuspiciousCasesController(IMediator mediator) + public SuspiciousCasesController( + IMediator mediator, + IActionContextAccessor actionContextAccessor, + IOvoCodeWhiteList ovoCodeWhiteList, + INisCodeService nisCodeService) { _mediator = mediator; + _actionContextAccessor = actionContextAccessor; + _ovoCodeWhiteList = ovoCodeWhiteList; + _nisCodeService = nisCodeService; } [HttpGet] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.Adres.DecentraleBijwerker)] - public async Task GetSuspiciousCases(CancellationToken cancellationToken) + public async Task List(CancellationToken cancellationToken) { + var ovoCode = _actionContextAccessor.ActionContext!.HttpContext.FindOvoCodeClaim(); + + if (string.IsNullOrWhiteSpace(ovoCode)) + { + return Forbid(); + } + var filtering = Request.ExtractFilteringRequest(); + + if (!_ovoCodeWhiteList.IsWhiteListed(ovoCode)) + { + var nisCode = await _nisCodeService.Get(ovoCode, cancellationToken); + + if (string.IsNullOrWhiteSpace(nisCode)) + { + return Forbid(); + } + + filtering.Filter.NisCode = nisCode; + } + var response = await _mediator.Send(new SuspiciousCasesListRequest(filtering), cancellationToken); return Ok(response); @@ -37,13 +70,33 @@ public async Task GetSuspiciousCases(CancellationToken cancellati [HttpGet("{type}")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.Adres.DecentraleBijwerker)] - public async Task GetSuspiciousCases( + public async Task Detail( [FromRoute] string type, CancellationToken cancellationToken) { + var ovoCode = _actionContextAccessor.ActionContext!.HttpContext.FindOvoCodeClaim(); + + if (string.IsNullOrWhiteSpace(ovoCode)) + { + return Forbid(); + } + var filtering = Request.ExtractFilteringRequest(); - var response = await _mediator.Send(new SuspiciousCasesDetailRequest(filtering, type), cancellationToken); + if (!_ovoCodeWhiteList.IsWhiteListed(ovoCode)) + { + var nisCode = await _nisCodeService.Get(ovoCode, cancellationToken); + + if (string.IsNullOrWhiteSpace(nisCode)) + { + return Forbid(); + } + + filtering.Filter.NisCode = nisCode; + } + + var response = await _mediator.Send(new SuspiciousCasesDetailRequest(filtering, type), cancellationToken); + return Ok(response); } } diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json index 7839482e..7ed4823b 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/appsettings.json @@ -26,6 +26,10 @@ "SuspiciousCasesTypeUrl": "https://api.basisregisters.vlaanderen.be/v2/verdachte-gevallen/{0}" }, + "OvoCodeWhiteList": [ + "OVO002949" + ], + "Serilog": { "MinimumLevel": { "Default": "Information" diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/paket.references b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/paket.references index 7b4b1894..4ca9b8ec 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/paket.references +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases.Api/paket.references @@ -4,6 +4,7 @@ Autofac Be.Vlaanderen.Basisregisters.Auth.AcmIdm Be.Vlaanderen.Basisregisters.Api +Be.Vlaanderen.Basisregisters.NisCodeService.HardCoded MediatR diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.IntegrationTests/appsettings.json b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.IntegrationTests/appsettings.json index a7e992ef..41c1a4a6 100644 --- a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.IntegrationTests/appsettings.json +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.IntegrationTests/appsettings.json @@ -22,6 +22,10 @@ "ServiceName": "building-registry-backoffice-api" }, + "OvoCodeWhiteList": [ + "OVO002949" + ], + "Cors": [ ] } diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.csproj b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.csproj new file mode 100644 index 00000000..33662d14 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.csproj @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs new file mode 100644 index 00000000..5fb5f512 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs @@ -0,0 +1,82 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using Detail; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.Abstractions; + using Xunit; + + public class GivenDecentraleBijwerkerWithKnownOvoCode + { + private readonly Mock _mediator = new(); + private readonly IActionResult _response; + + private const string OvoCode = "OVO003105"; + private const string ExpectedNisCode = "11202"; + + public GivenDecentraleBijwerkerWithKnownOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, OvoCode) }) + }), + } + }); + + Mock nisCodeService = new(); + nisCodeService + .Setup(x => x.Get(OvoCode, CancellationToken.None)) + .ReturnsAsync(ExpectedNisCode); + + var suspiciousCasesController = new SuspiciousCasesController( + _mediator.Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List()), + nisCodeService.Object) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.Detail("type", CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + + [Fact] + public void ThenNisCodeFromHeadersIsUsed() + { + _mediator.Verify(x => x.Send( + It.Is(y => + y.FilteringHeader.Filter.NisCode == ExpectedNisCode && + y.Type == "type"), + It.IsAny())); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs new file mode 100644 index 00000000..74b868e6 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs @@ -0,0 +1,67 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.Abstractions; + using Xunit; + + public class GivenDecentraleBijwerkerWithUnknownOvoCode + { + private readonly IActionResult _response; + + public GivenDecentraleBijwerkerWithUnknownOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO003105") }) + }), + } + }); + + Mock nisCodeService = new(); + nisCodeService + .Setup(x => x.Get("OVO003105", CancellationToken.None)) + .ReturnsAsync(string.Empty); + + var suspiciousCasesController = new SuspiciousCasesController( + new Mock().Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List()), + nisCodeService.Object) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.Detail("type", CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs new file mode 100644 index 00000000..f0d040c9 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs @@ -0,0 +1,62 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.HardCoded; + using Xunit; + + public class GivenInterneBijwerkerWithNonWhiteListedOvoCode + { + private readonly IActionResult _response; + + public GivenInterneBijwerkerWithNonWhiteListedOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO002950") }) + }), + } + }); + + var suspiciousCasesController = new SuspiciousCasesController( + new Mock().Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List { "OVO002949" }), + new HardCodedNisCodeService()) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.Detail(string.Empty, CancellationToken.None).Result; + } + + [Fact] + public void ThenForbid() + { + _response.Should().BeOfType(); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs new file mode 100644 index 00000000..39c7cf2c --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenDetailSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs @@ -0,0 +1,74 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenDetailSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using Detail; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.HardCoded; + using Xunit; + + public class GivenInterneBijwerkerWithWhiteListedOvoCode + { + private readonly Mock _mediator = new(); + + private readonly IActionResult _response; + + public GivenInterneBijwerkerWithWhiteListedOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO002949") }) + }), + } + }); + + var suspiciousCasesController = new SuspiciousCasesController( + _mediator.Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List { "OVO002949" }), + new HardCodedNisCodeService()) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.Detail("type", CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + + [Fact] + public void ThenNisCodeFromHeadersIsUsed() + { + _mediator.Verify(x => x.Send( + It.Is( + y => y.FilteringHeader.Filter.NisCode == "11001" && y.Type == "type"), + It.IsAny())); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs new file mode 100644 index 00000000..8ca21b6d --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithKnownOvoCode.cs @@ -0,0 +1,80 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenListSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using List; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.Abstractions; + using Xunit; + + public class GivenDecentraleBijwerkerWithKnownOvoCode + { + private readonly Mock _mediator = new(); + private readonly IActionResult _response; + + private const string OvoCode = "OVO003105"; + private const string ExpectedNisCode = "11202"; + + public GivenDecentraleBijwerkerWithKnownOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, OvoCode) }) + }), + } + }); + + Mock nisCodeService = new(); + nisCodeService + .Setup(x => x.Get(OvoCode, CancellationToken.None)) + .ReturnsAsync(ExpectedNisCode); + + var suspiciousCasesController = new SuspiciousCasesController( + _mediator.Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List()), + nisCodeService.Object) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.List(CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + + [Fact] + public void ThenNisCodeFromHeadersIsUsed() + { + _mediator.Verify(x => x.Send( + It.Is(y => y.FilteringHeader.Filter.NisCode == ExpectedNisCode), + It.IsAny())); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs new file mode 100644 index 00000000..666e2d01 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenDecentraleBijwerkerWithUnknownOvoCode.cs @@ -0,0 +1,67 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenListSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.Abstractions; + using Xunit; + + public class GivenDecentraleBijwerkerWithUnknownOvoCode + { + private readonly IActionResult _response; + + public GivenDecentraleBijwerkerWithUnknownOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO003105") }) + }), + } + }); + + Mock nisCodeService = new(); + nisCodeService + .Setup(x => x.Get("OVO003105", CancellationToken.None)) + .ReturnsAsync(string.Empty); + + var suspiciousCasesController = new SuspiciousCasesController( + new Mock().Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List()), + nisCodeService.Object) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.List(CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs new file mode 100644 index 00000000..cf4265a1 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithNonWhiteListedOvoCode.cs @@ -0,0 +1,62 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenListSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.HardCoded; + using Xunit; + + public class GivenInterneBijwerkerWithNonWhiteListedOvoCode + { + private readonly IActionResult _response; + + public GivenInterneBijwerkerWithNonWhiteListedOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO002950") }) + }), + } + }); + + var suspiciousCasesController = new SuspiciousCasesController( + new Mock().Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List { "OVO002949" }), + new HardCodedNisCodeService()) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.List(CancellationToken.None).Result; + } + + [Fact] + public void ThenForbid() + { + _response.Should().BeOfType(); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs new file mode 100644 index 00000000..56d7b12a --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/WhenListSuspiciousCases/GivenInterneBijwerkerWithWhiteListedOvoCode.cs @@ -0,0 +1,73 @@ +namespace Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests.WhenListSuspiciousCases +{ + using System.Collections.Generic; + using System.Security.Claims; + using System.Threading; + using Be.Vlaanderen.Basisregisters.Auth; + using Be.Vlaanderen.Basisregisters.Auth.AcmIdm; + using FluentAssertions; + using List; + using MediatR; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Infrastructure; + using Microsoft.Extensions.Primitives; + using Moq; + using NisCodeService.HardCoded; + using Xunit; + + public class GivenInterneBijwerkerWithWhiteListedOvoCode + { + private readonly Mock _mediator = new(); + + private readonly IActionResult _response; + + public GivenInterneBijwerkerWithWhiteListedOvoCode() + { + Mock actionContextAccessor = new(); + actionContextAccessor + .Setup(x => x.ActionContext) + .Returns(new ActionContext + { + HttpContext = new DefaultHttpContext + { + User = new ClaimsPrincipal(new[] + { + new ClaimsIdentity(new[] { new Claim(AcmIdmClaimTypes.VoOvoCode, "OVO002949") }) + }), + } + }); + + var suspiciousCasesController = new SuspiciousCasesController( + _mediator.Object, + actionContextAccessor.Object, + new OvoCodeWhiteList(new List { "OVO002949" }), + new HardCodedNisCodeService()) + { + ControllerContext = new ControllerContext + { + HttpContext = new DefaultHttpContext + { + Request = { Headers = { new KeyValuePair("X-Filtering", "{ \"nisCode\": \"11001\"}") } } + } + } + }; + + _response = suspiciousCasesController.List(CancellationToken.None).Result; + } + + [Fact] + public void ThenOkResponse() + { + _response.Should().BeOfType(); + } + + [Fact] + public void ThenNisCodeFromHeadersIsUsed() + { + _mediator.Verify(x => x.Send( + It.Is(y => y.FilteringHeader.Filter.NisCode == "11001"), + It.IsAny())); + } + } +} diff --git a/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/paket.references b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/paket.references new file mode 100644 index 00000000..25776925 --- /dev/null +++ b/test/Basisregisters.IntegrationDb.SuspiciousCases.Api.Tests/paket.references @@ -0,0 +1,8 @@ +Microsoft.NET.Test.Sdk +xunit.runner.visualstudio +xunit.categories +FluentAssertions +Microsoft.AspNetCore.Mvc.Testing +Microsoft.AspNetCore.TestHost + +Moq