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

fix(connector): only provider should update connector #1086

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -402,22 +402,22 @@ 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)
{
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
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Connector AttachAndModifyConnector(Guid connectorId, Action<Connector>? i
.Select(c => new ConnectorUpdateInformation(
c.StatusId,
c.TypeId,
c.HostId == companyId,
dhiren-singh-007 marked this conversation as resolved.
Show resolved Hide resolved
c.ProviderId == companyId,
c.ConnectorUrl,
c.Provider!.BusinessPartnerNumber,
c.SelfDescriptionDocumentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorUpdateInformation>()
.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);
Expand All @@ -1017,7 +1017,7 @@ public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenExc

// Assert
var ex = await Assert.ThrowsAsync<ForbiddenException>(Act);
ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY.ToString());
ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY.ToString());
}

[Fact]
Expand All @@ -1027,7 +1027,7 @@ public async Task UpdateConnectorUrl_WithInactiveConnector_ThrowsConflictExcepti
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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))
Expand All @@ -1048,7 +1048,7 @@ public async Task UpdateConnectorUrl_WithBpnNotSet_ThrowsConflictException()
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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?))
Expand All @@ -1071,7 +1071,7 @@ public async Task UpdateConnectorUrl_WithCompanyBpnNotSet_ThrowsConflictExceptio
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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")
Expand Down Expand Up @@ -1101,7 +1101,7 @@ public async Task UpdateConnectorUrl_WithValidData_CallsExpected()
.Create();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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")
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public async Task UpdateConnectorUrl_WithSelfDescriptionCompanyIdNotSet_ThrowsCo
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
{
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<ProcessStepTypeId> _processStepsToFilter = [
ProcessStepTypeId.CREATE_DIM_TECHNICAL_USER,
ProcessStepTypeId.RETRIGGER_CREATE_DIM_TECHNICAL_USER,
Expand Down Expand Up @@ -429,7 +430,35 @@
// Assert
result.Should().BeNull();
}

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning test

Variable
result
may be null at this access as suggested by
this
null check.
[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();
}

Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
[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
Expand Down
Loading