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): adjust sd doc validation for connector creation #894

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -105,18 +105,15 @@ private async Task<Guid> CreateConnectorInternalAsync(ConnectorInputModel connec
throw UnexpectedConditionException.Create(AdministrationConnectorErrors.CONNECTOR_UNEXPECTED_NO_BPN_ASSIGNED, new ErrorParameter[] { new("companyId", companyId.ToString()) });
}

if (result.SelfDescriptionDocumentId is null)
{
throw UnexpectedConditionException.Create(AdministrationConnectorErrors.CONNECTOR_UNEXPECTED_NO_DESCRIPTION, new ErrorParameter[] { new("companyId", companyId.ToString()) });
}
await ValidateTechnicalUser(technicalUserId, companyId).ConfigureAwait(ConfigureAwaitOptions.None);

var connectorRequestModel = new ConnectorRequestModel(name, connectorUrl, ConnectorTypeId.COMPANY_CONNECTOR, location, companyId, companyId, technicalUserId);
return await CreateAndRegisterConnectorAsync(
connectorRequestModel,
result.Bpn,
result.SelfDescriptionDocumentId.Value,
result.SelfDescriptionDocumentId,
null,
companyId,
cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
}

Expand Down Expand Up @@ -151,11 +148,6 @@ private async Task<Guid> CreateManagedConnectorInternalAsync(ManagedConnectorInp
throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_STATUS_ACTIVE_OR_PENDING, new ErrorParameter[] { new("offerSubscriptionStatusIdActive", OfferSubscriptionStatusId.ACTIVE.ToString()), new("offerSubscriptionStatusIdPending", OfferSubscriptionStatusId.PENDING.ToString()) });
}

if (result.SelfDescriptionDocumentId is null)
{
throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_NO_DESCRIPTION, new ErrorParameter[] { new("companyId", result.CompanyId.ToString()) });
}

if (string.IsNullOrWhiteSpace(result.ProviderBpn))
{
throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_SET_BPN, new ErrorParameter[] { new("companyId", result.CompanyId.ToString()) });
Expand All @@ -167,8 +159,9 @@ private async Task<Guid> CreateManagedConnectorInternalAsync(ManagedConnectorInp
return await CreateAndRegisterConnectorAsync(
connectorRequestModel,
result.ProviderBpn,
result.SelfDescriptionDocumentId!.Value,
result.SelfDescriptionDocumentId,
subscriptionId,
result.CompanyId,
cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
}

Expand Down Expand Up @@ -198,10 +191,16 @@ private async Task ValidateTechnicalUser(Guid? technicalUserId, Guid companyId)
private async Task<Guid> CreateAndRegisterConnectorAsync(
ConnectorRequestModel connectorInputModel,
string businessPartnerNumber,
Guid selfDescriptionDocumentId,
Guid? selfDescriptionDocumentId,
Guid? subscriptionId,
Guid companyId,
CancellationToken cancellationToken)
{
if (selfDescriptionDocumentId is null && !_settings.ClearinghouseConnectDisabled)
{
throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_NO_DESCRIPTION, [new("companyId", companyId.ToString())]);
}

var (name, connectorUrl, type, location, provider, host, technicalUserId) = connectorInputModel;

var connectorsRepository = portalRepositories.GetInstance<IConnectorsRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class AdministrationConnectorErrorMessageContainer : IErrorMessageContain
{ AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, "connector {connectorId} does not exist" },
{ AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY,"company {companyId} is not provider of connector {connectorId}"},
{ AdministrationConnectorErrors.CONNECTOR_UNEXPECTED_NO_BPN_ASSIGNED, "provider company {companyId} has no businessPartnerNumber assigned" },
{ AdministrationConnectorErrors.CONNECTOR_UNEXPECTED_NO_DESCRIPTION, "provider company {companyId} has no self description document" },
{ AdministrationConnectorErrors.CONNECTOR_NOT_OFFERSUBSCRIPTION_EXIST,"OfferSubscription {subscriptionId} does not exist"},
{ AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY_OFFER,"Company is not the provider of the offer"},
{ AdministrationConnectorErrors.CONNECTOR_CONFLICT_OFFERSUBSCRIPTION_LINKED,"OfferSubscription is already linked to a connector"},
Expand Down Expand Up @@ -56,7 +55,6 @@ public enum AdministrationConnectorErrors
CONNECTOR_NOT_FOUND,
CONNECTOR_NOT_PROVIDER_COMPANY,
CONNECTOR_UNEXPECTED_NO_BPN_ASSIGNED,
CONNECTOR_UNEXPECTED_NO_DESCRIPTION,
CONNECTOR_NOT_OFFERSUBSCRIPTION_EXIST,
CONNECTOR_NOT_PROVIDER_COMPANY_OFFER,
CONNECTOR_CONFLICT_OFFERSUBSCRIPTION_LINKED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,33 @@ public async Task CreateConnectorAsync_WithClientIdNull_DoesntSaveData()
_connectors.Should().HaveCount(1);
}

[Fact]
public async Task CreateConnectorAsync_WithoutSelfDescriptionDocumentAndSdConnectionDisabled_CallsExpected()
{
// Arrange
var sut = new ConnectorsBusinessLogic(_portalRepositories, Options.Create(new ConnectorsSettings
{
MaxPageSize = 15,
ValidCertificationContentTypes = new[]
{
"application/x-pem-file",
"application/x-x509-ca-cert",
"application/pkix-cert"
},
ClearinghouseConnectDisabled = true
}), _sdFactoryBusinessLogic, _identityService, A.Fake<ILogger<ConnectorsBusinessLogic>>());

var connectorInput = new ConnectorInputModel("connectorName", "https://test.de", "de", null);
A.CallTo(() => _identity.CompanyId).Returns(CompanyIdWithoutSdDocument);

// Act
await sut.CreateConnectorAsync(connectorInput, CancellationToken.None);

// Assert
A.CallTo(() => _connectorsRepository.CreateConnector(A<string>._, A<string>._, A<string>._, A<Action<Connector>>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _sdFactoryBusinessLogic.RegisterConnectorAsync(A<Guid>._, A<string>._, A<string>._, A<CancellationToken>._)).MustNotHaveHappened();
}

[Fact]
public async Task CreateConnectorAsync_WithoutSelfDescriptionDocument_ThrowsUnexpectedException()
{
Expand All @@ -212,8 +239,8 @@ public async Task CreateConnectorAsync_WithoutSelfDescriptionDocument_ThrowsUnex
async Task Act() => await _logic.CreateConnectorAsync(connectorInput, CancellationToken.None);

// Assert
var exception = await Assert.ThrowsAsync<UnexpectedConditionException>(Act);
exception.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_UNEXPECTED_NO_DESCRIPTION.ToString());
var exception = await Assert.ThrowsAsync<ConflictException>(Act);
exception.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_CONFLICT_NO_DESCRIPTION.ToString());
}

[Fact]
Expand Down
Loading