From 22f4b0790f334eb6c449101ab31cc49f6e370655 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Mon, 21 Oct 2024 16:10:46 +0200 Subject: [PATCH 1/5] fix(connector): only provider should update connector --- .../BusinessLogic/ConnectorsBusinessLogic.cs | 10 +++++----- .../Models/ConnectorUpdateInformation.cs | 2 +- .../Repositories/ConnectorsRepository.cs | 2 +- .../BusinessLogic/ConnectorsBusinessLogicTests.cs | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs index 0de31768de..4ce2c0684b 100644 --- a/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs @@ -402,7 +402,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR if (connector == null) { - throw NotFoundException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, new ErrorParameter[] { new("connectorId", connectorId.ToString()) }); + throw NotFoundException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, [new("connectorId", connectorId.ToString())]); } if (connector.ConnectorUrl == data.ConnectorUrl) @@ -410,14 +410,14 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR return; } - if (!connector.IsHostCompany) + if (!connector.IsProviderCompany) { - throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY, new ErrorParameter[] { new("companyId", _identityData.CompanyId.ToString()) }); + throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY, [new("companyId", _identityData.CompanyId.ToString()), new("connectorId", connectorId.ToString())]); } if (connector.Status == ConnectorStatusId.INACTIVE) { - throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_INACTIVE_STATE, new ErrorParameter[] { new("connectorId", connectorId.ToString()), new("connectorStatusId", ConnectorStatusId.INACTIVE.ToString()) }); + throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_INACTIVE_STATE, [new("connectorId", connectorId.ToString()), new("connectorStatusId", ConnectorStatusId.INACTIVE.ToString())]); } var bpn = connector.Type == ConnectorTypeId.CONNECTOR_AS_A_SERVICE @@ -427,7 +427,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR .ConfigureAwait(ConfigureAwaitOptions.None); if (string.IsNullOrWhiteSpace(bpn)) { - throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_SET_BPN, new ErrorParameter[] { new("companyId", _identityData.CompanyId.ToString()) }); + throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_SET_BPN, [new("companyId", _identityData.CompanyId.ToString())]); } connectorsRepository.AttachAndModifyConnector(connectorId, null, con => diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs b/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs index 4b01548453..4cfbcf012c 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs @@ -28,7 +28,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; public record ConnectorUpdateInformation( ConnectorStatusId Status, ConnectorTypeId Type, - bool IsHostCompany, + bool IsProviderCompany, string ConnectorUrl, string? Bpn, Guid? SelfDescriptionDocumentId, diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs index f18ab6817a..5243c83284 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs @@ -190,7 +190,7 @@ public Connector AttachAndModifyConnector(Guid connectorId, Action? i .Select(c => new ConnectorUpdateInformation( c.StatusId, c.TypeId, - c.HostId == companyId, + c.ProviderId == companyId, c.ConnectorUrl, c.Provider!.BusinessPartnerNumber, c.SelfDescriptionDocumentId, diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs index f285541d23..f6a33bc6d4 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs @@ -1001,13 +1001,13 @@ public async Task UpdateConnectorUrl_WithSameUrlAsStored_ReturnsWithoutDoing() } [Fact] - public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenException() + public async Task UpdateConnectorUrl_WithUserNotOfProviderCompany_ThrowsForbiddenException() { // Arrange var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, false) + .With(x => x.IsProviderCompany, false) .Create(); A.CallTo(() => _connectorsRepository.GetConnectorUpdateInformation(connectorId, _identity.CompanyId)) .Returns(data); @@ -1017,7 +1017,7 @@ public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenExc // Assert var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY.ToString()); + ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY.ToString()); } [Fact] @@ -1027,7 +1027,7 @@ public async Task UpdateConnectorUrl_WithInactiveConnector_ThrowsConflictExcepti var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.INACTIVE) .Create(); A.CallTo(() => _connectorsRepository.GetConnectorUpdateInformation(connectorId, _identity.CompanyId)) @@ -1048,7 +1048,7 @@ public async Task UpdateConnectorUrl_WithBpnNotSet_ThrowsConflictException() var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE) .With(x => x.Bpn, default(string?)) @@ -1071,7 +1071,7 @@ public async Task UpdateConnectorUrl_WithCompanyBpnNotSet_ThrowsConflictExceptio var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.COMPANY_CONNECTOR) .With(x => x.Bpn, "BPNL123456789") @@ -1101,7 +1101,7 @@ public async Task UpdateConnectorUrl_WithValidData_CallsExpected() .Create(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE) .With(x => x.Bpn, "BPNL123456789") From 152b2ec669d5ec1d6f104a2d5cc3312ec54e65e5 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Thu, 14 Nov 2024 10:56:36 +0100 Subject: [PATCH 2/5] fix the new changes from main --- .../BusinessLogic/ConnectorsBusinessLogicTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs index f6a33bc6d4..d1b570be69 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs @@ -1144,7 +1144,7 @@ public async Task UpdateConnectorUrl_WithSelfDescriptionCompanyIdNotSet_ThrowsCo var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE) .With(x => x.Bpn, "BPNL123456789") From be5e4365a698dafda2565120a4ab45ad2c0d7d5c Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Thu, 14 Nov 2024 16:44:38 +0100 Subject: [PATCH 3/5] added unit test to check is provider --- .../ConnectorRepositoryTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs index 518f03523a..73edce9d92 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs @@ -36,6 +36,7 @@ public class ConnectorRepositoryTests : IAssemblyFixture { private readonly TestDbFixture _dbTestDbFixture; private readonly Guid _userCompanyId = new("2dc4249f-b5ca-4d42-bef1-7a7a950a4f87"); + private readonly Guid _providerCompanyId = new("41fd2ab8-71cd-4546-9bef-a388d91b2542"); private readonly IEnumerable _processStepsToFilter = [ ProcessStepTypeId.CREATE_DIM_TECHNICAL_USER, ProcessStepTypeId.RETRIGGER_CREATE_DIM_TECHNICAL_USER, @@ -430,6 +431,34 @@ public async Task GetConnectorUpdateInformation_WithoutExistingConnector_Returns result.Should().BeNull(); } + [Fact] + public async Task GetConnectorUpdateInformation_ReturnIsProviderTrue() + { + // Arrange + var (sut, _) = await CreateSut(); + + // Act + var result = await sut.GetConnectorUpdateInformation(new Guid("7e86a0b8-6903-496b-96d1-0ef508206839"), _providerCompanyId); + + // Assert + result.Should().NotBeNull(); + result?.IsProviderCompany.Should().BeTrue(); + } + + [Fact] + public async Task GetConnectorUpdateInformation_ReturnIsProviderFalse() + { + // Arrange + var (sut, _) = await CreateSut(); + + // Act + var result = await sut.GetConnectorUpdateInformation(new Guid("7e86a0b8-6903-496b-96d1-0ef508206839"), _userCompanyId); + + // Assert + result.Should().NotBeNull(); + result?.IsProviderCompany.Should().BeFalse(); + } + #endregion #region GetConnectorEndPointDataAsync From d7936d6532732c408a29223df40039241e3b6d4f Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Thu, 14 Nov 2024 17:02:44 +0100 Subject: [PATCH 4/5] fix git codeql issue --- .../ConnectorRepositoryTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs index 73edce9d92..f81db0aa9b 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs @@ -442,7 +442,10 @@ public async Task GetConnectorUpdateInformation_ReturnIsProviderTrue() // Assert result.Should().NotBeNull(); - result?.IsProviderCompany.Should().BeTrue(); + if (result != null) + { + result.IsProviderCompany.Should().BeTrue(); + } } [Fact] @@ -456,7 +459,10 @@ public async Task GetConnectorUpdateInformation_ReturnIsProviderFalse() // Assert result.Should().NotBeNull(); - result?.IsProviderCompany.Should().BeFalse(); + if (result != null) + { + result.IsProviderCompany.Should().BeFalse(); + } } #endregion From e6e07df5a2a251c026484c6dc4d38a3a23c55a8f Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Fri, 15 Nov 2024 09:47:33 +0100 Subject: [PATCH 5/5] fix null ref issue --- .../ConnectorRepositoryTests.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs index f81db0aa9b..6a43761b6f 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/ConnectorRepositoryTests.cs @@ -442,10 +442,8 @@ public async Task GetConnectorUpdateInformation_ReturnIsProviderTrue() // Assert result.Should().NotBeNull(); - if (result != null) - { - result.IsProviderCompany.Should().BeTrue(); - } + result!.IsProviderCompany.Should().BeTrue(); + } [Fact] @@ -459,10 +457,8 @@ public async Task GetConnectorUpdateInformation_ReturnIsProviderFalse() // Assert result.Should().NotBeNull(); - if (result != null) - { - result.IsProviderCompany.Should().BeFalse(); - } + result!.IsProviderCompany.Should().BeFalse(); + } #endregion