From 50320b90c9e39a4acc40b90d0a8d734d20389844 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Thu, 25 Apr 2024 08:37:22 +0200 Subject: [PATCH] fix(technicalUser): fix callback url for technical user --- charts/dim/Chart.yaml | 4 +- charts/dim/README.md | 2 +- src/Directory.Build.props | 2 +- .../Callback/CallbackService.cs | 2 +- .../TechnicalUserProcessHandlerTests.cs | 92 +++++++++++++++++++ 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 tests/processes/DimProcess.Library.Tests/TechnicalUserProcessHandlerTests.cs diff --git a/charts/dim/Chart.yaml b/charts/dim/Chart.yaml index 1bc7940..fdccfe6 100644 --- a/charts/dim/Chart.yaml +++ b/charts/dim/Chart.yaml @@ -20,8 +20,8 @@ apiVersion: v2 name: dim type: application -version: 0.0.4 -appVersion: 0.0.4 +version: 0.0.5 +appVersion: 0.0.5 description: Helm chart for DIM Middle Layer home: https://github.com/catenax-ng/dim-repo dependencies: diff --git a/charts/dim/README.md b/charts/dim/README.md index fbe9398..a408ec0 100644 --- a/charts/dim/README.md +++ b/charts/dim/README.md @@ -27,7 +27,7 @@ To use the helm chart as a dependency: dependencies: - name: dim repository: https://phil91.github.io/dim-client - version: 0.0.3 + version: 0.0.5 ``` ## Requirements diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 34cdc14..e894dba 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -19,7 +19,7 @@ - 0.0.4 + 0.0.5 diff --git a/src/processes/DimProcess.Library/Callback/CallbackService.cs b/src/processes/DimProcess.Library/Callback/CallbackService.cs index a5d59d2..a92d49c 100644 --- a/src/processes/DimProcess.Library/Callback/CallbackService.cs +++ b/src/processes/DimProcess.Library/Callback/CallbackService.cs @@ -57,6 +57,6 @@ public async Task SendTechnicalUserCallback(Guid externalId, string tokenAddress tokenAddress, clientId, clientSecret); - await httpClient.PostAsJsonAsync($"/api/adminstration/serviceAccount/callback/{externalId}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); + await httpClient.PostAsJsonAsync($"/api/administration/serviceAccount/callback/{externalId}", data, JsonSerializerExtensions.Options, cancellationToken).ConfigureAwait(false); } } diff --git a/tests/processes/DimProcess.Library.Tests/TechnicalUserProcessHandlerTests.cs b/tests/processes/DimProcess.Library.Tests/TechnicalUserProcessHandlerTests.cs new file mode 100644 index 0000000..2e5fd88 --- /dev/null +++ b/tests/processes/DimProcess.Library.Tests/TechnicalUserProcessHandlerTests.cs @@ -0,0 +1,92 @@ +using Dim.Clients.Api.Cf; +using Dim.DbAccess; +using Dim.DbAccess.Repositories; +using Dim.Entities.Entities; +using Dim.Entities.Enums; +using DimProcess.Library.Callback; +using DimProcess.Library.DependencyInjection; +using Microsoft.Extensions.Options; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; +using System.Security.Cryptography; + +namespace DimProcess.Library.Tests; + +public class TechnicalUserProcessHandlerTests +{ + private readonly ICallbackService _callbackService; + private readonly IFixture _fixture; + private readonly IDimRepositories _repositories; + private readonly ITenantRepository _tenantRepositories; + private readonly IOptions _options; + private readonly ICfClient _cfClient; + private readonly TechnicalUserProcessHandler _sut; + + public TechnicalUserProcessHandlerTests() + { + _fixture = new Fixture().Customize(new AutoFakeItEasyCustomization { ConfigureMembers = true }); + _fixture.Behaviors.OfType().ToList() + .ForEach(b => _fixture.Behaviors.Remove(b)); + _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); + + _repositories = A.Fake(); + _tenantRepositories = A.Fake(); + + A.CallTo(() => _repositories.GetInstance()).Returns(_tenantRepositories); + + _cfClient = A.Fake(); + _callbackService = A.Fake(); + _options = Options.Create(new TechnicalUserSettings + { + EncryptionConfigIndex = 0, + EncryptionConfigs = new[] + { + new EncryptionModeConfig + { + Index = 0, + CipherMode = CipherMode.CBC, + PaddingMode = PaddingMode.PKCS7, + EncryptionKey = "2c68516f23467028602524534824437e417e253c29546c563c2f5e3d485e7667" + } + } + }); + + _sut = new TechnicalUserProcessHandler(_repositories, _cfClient, _callbackService, _options); + } + + #region CreateSubaccount + + [Fact] + public async Task CreateSubaccount_WithValidData_ReturnsExpected() + { + // Arrange + var technicalUserId = Guid.NewGuid(); + var serviceBindingId = Guid.NewGuid(); + var technicalUser = new TechnicalUser(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "test", Guid.NewGuid()); + A.CallTo(() => _tenantRepositories.GetSpaceIdAndTechnicalUserName(technicalUserId)) + .Returns(new ValueTuple(Guid.NewGuid(), "test")); + A.CallTo(() => _cfClient.GetServiceBinding("test", A._, A._, A._)) + .Returns(serviceBindingId); + A.CallTo(() => _cfClient.GetServiceBindingDetails(serviceBindingId, A._)) + .Returns(new ServiceCredentialBindingDetailResponse(new Credentials("https://example.org", new Uaa("cl1", "test123", "https://example.org/test", "https://example.org/api")))); + A.CallTo(() => _tenantRepositories.AttachAndModifyTechnicalUser(A._, A>._, A>._)) + .Invokes((Guid _, Action? initialize, Action modify) => + { + initialize?.Invoke(technicalUser); + modify(technicalUser); + }); + + // Act + var result = await _sut.GetTechnicalUserData("test", technicalUserId, CancellationToken.None); + + // Assert + result.modified.Should().BeFalse(); + result.processMessage.Should().BeNull(); + result.stepStatusId.Should().Be(ProcessStepStatusId.DONE); + result.nextStepTypeIds.Should().ContainSingle().Which.Should().Be(ProcessStepTypeId.SEND_TECHNICAL_USER_CALLBACK); + technicalUser.EncryptionMode.Should().NotBeNull().And.Be(0); + technicalUser.ClientId.Should().Be("cl1"); + } + + #endregion + +}