Skip to content

Commit

Permalink
fix(n2n): bpn can be null (#293)
Browse files Browse the repository at this point in the history
* fix(n2n): bpn can be null
* updates(osp email): update quick help section
Refs: CPLP-2637
---------
Co-authored-by: manojava-gk <[email protected]>
Reviewed-by: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 authored Oct 11, 2023
1 parent 562796f commit 2e776a0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ public Task RetriggerProcessStep(Guid externalId, ProcessStepTypeId processStepT

private async Task<(IEnumerable<UserRoleData> RoleData, IDictionary<Guid, string>? IdentityProviderIdAliase, (Guid IdentityProviderId, string Alias)? SingleIdentityProviderIdAlias, IEnumerable<Guid> AllIdentityProviderIds)> ValidatePartnerRegistrationData(PartnerRegistrationData data, INetworkRepository networkRepository, IIdentityProviderRepository identityProviderRepository, Guid ownerCompanyId)
{
if (string.IsNullOrWhiteSpace(data.Bpn) || !BpnRegex.IsMatch(data.Bpn))
if (data.Bpn != null)
{
throw new ControllerArgumentException("BPN must contain exactly 16 characters and must be prefixed with BPNL", nameof(data.Bpn));
}
if (!BpnRegex.IsMatch(data.Bpn))
{
throw new ControllerArgumentException("BPN must contain exactly 16 characters and must be prefixed with BPNL", nameof(data.Bpn));
}

if (await _portalRepositories.GetInstance<ICompanyRepository>().CheckBpnExists(data.Bpn).ConfigureAwait(false))
{
throw new ControllerArgumentException($"The Bpn {data.Bpn} already exists", nameof(data.Bpn));
if (await _portalRepositories.GetInstance<ICompanyRepository>().CheckBpnExists(data.Bpn).ConfigureAwait(false))
{
throw new ControllerArgumentException($"The Bpn {data.Bpn} already exists", nameof(data.Bpn));
}
}

if (!data.CompanyRoles.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.OnboardingServiceProvider.Library.
public record OnboardingServiceProviderCallbackData(
[property: JsonPropertyName("externalId")] Guid ExternalId,
[property: JsonPropertyName("applicationId")] Guid ApplicationId,
[property: JsonPropertyName("bpn")] string Bpn,
[property: JsonPropertyName("bpn")] string? Bpn,
[property: JsonPropertyName("status")] CompanyApplicationStatusId? Status,
[property: JsonPropertyName("message")] string? Message
);
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public OnboardingServiceProviderBusinessLogic(IOnboardingServiceProviderService
throw new UnexpectedConditionException("No external registration found");
}

if (string.IsNullOrWhiteSpace(data.Bpn))
{
throw new UnexpectedConditionException("Bpn must be set");
}

if (processStepTypeId == ProcessStepTypeId.TRIGGER_CALLBACK_OSP_DECLINED && data.Comments.Count() != 1)
{
throw new UnexpectedConditionException("Message for decline should be set");
Expand Down
44 changes: 38 additions & 6 deletions src/mailing/Mailing.Template/EmailTemplates/osp_welcome_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,16 @@
<tr>
<td
style="Margin:0;padding-top:20px;padding-bottom:20px;padding-left:30px;padding-right:30px;text-align: left;">
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;color:#333333;font-size:14px">
Dear {userName},<br /><br /> your registration at the Catena-X dataspace got based on your request successfully generated by {osp} for idps {idpAliasse}. <br /><br /> We have created your registration request. Before the registration validation is taking place, a final check from your side confirming your registration data and confirming the terms & conditions is needed. <br /><br /> Please follow the link below to access your registration data and to confirm the company role related terms & conditions. <br /> You may want to update the company roles by selecting additional roles.</p>
<p style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;color:#333333;font-size:14px">
Dear {userName},<br /><br /> your registration at the Catena-X dataspace got based on your request successfully generated by {osp}. <br /><br /> We have created your registration request. Before the registration validation is taking place, a final check from your side confirming your registration data and confirming the terms & conditions is needed. <br /><br /> Please follow the link below to access your registration data and to confirm the company role related terms & conditions. <br /> You may want to update the company roles by selecting additional roles.

<br /> Please note: you can login with your {osp} account by clicking on the company login path *
<br /> <br />
{idpalias}
<br /> <br /> * and entering your {osp} user credentials. In case the authentication runs on errors, please have a look at the
<a href="{hostname}/documentation/?path=docs%2F09.+Others%28s%29%2F01.+Login.md" rel="noopener" target="_blank">help</a>
or contact your onboarding service provider {osp}
</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -167,11 +174,16 @@
style="Margin:0;padding-top:15px;padding-bottom:15px;padding-left:30px;padding-right:30px;text-align: left;">
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;color:#030228;font-size:14px">
<strong>if the request was not triggered by you, you can close the application by clicking here</strong><br><a href="{hostname}/{closeApplicationUrl}"
style="-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;text-decoration:underline;color:#0f71cb;font-size:14px;text-align:center">{hostname}/{closeApplicationUrl}</a><a
href="{hostname}/{closeApplicationUrl}"
<strong>The above link does not work?</strong><br>Copy/Paste this URL into your
Browser:</strong><br><a href="{hostname}/registration/external"
style="-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;text-decoration:underline;color:#0f71cb;font-size:14px;text-align:center">{hostname}/registration/external</a><a
href="{hostname}/registration/external"
style="-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;text-decoration:underline;color:#0f71cb;font-size:14px;text-align:center"></a>
</p>
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:10px;color:#030228;font-size:14px">
<br>
</p>
<h5
style="Margin:0;line-height:120%;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;color:#030228">
I need more information and help?</h5>
Expand All @@ -183,6 +195,26 @@
</td>
</tr>
</table>
<table role="presentation" aria-hidden="true"
style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;width:100%">
<tr>
<td style="padding:15px;Margin:0;background-color: #edf0f4;">
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;color:#030228;font-size:14px">
<strong>if the request was not triggered by you, you can close the application by
clicking here</strong><br><a href="{hostname}/{closeApplicationUrl}"
style="-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;text-decoration:underline;color:#0f71cb;font-size:14px;text-align:center">{hostname}/{closeApplicationUrl}</a><a
href="{hostname}/{closeApplicationUrl}"
style="-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;text-decoration:underline;color:#0f71cb;font-size:14px;text-align:center"></a>
</p>
<p
style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:10px;color:#030228;font-size:14px">
</p>
</td>
</tr>
</table>
<br>
<br>
</td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private async Task SendMails(IEnumerable<UserMailInformation> companyUserWithRol
{ "hostname", _settings.BasePortalAddress },
{ "osp", ospName },
{ "url", _settings.BasePortalAddress },
{ "idpAliasse", string.Join(",", idpAliasse) }
{ "idpalias", string.Join(",", idpAliasse) }
};
await _mailingService.SendMails(receiver, mailParameters, templates).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public NetworkBusinessLogicTests()
#region HandlePartnerRegistration

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("TEST00000012")]
[InlineData("BPNL1234567899")]
Expand Down Expand Up @@ -532,8 +531,10 @@ public async Task HandlePartnerRegistration_WithIdpNotSetAndOnlyOneIdp_CallsExpe
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
}

[Fact]
public async Task HandlePartnerRegistration_WithValidData_CallsExpected()
[Theory]
[InlineData(Bpnl)]
[InlineData((string?)null)]
public async Task HandlePartnerRegistration_WithValidData_CallsExpected(string? bpnl)
{
// Arrange
var newCompanyId = Guid.NewGuid();
Expand All @@ -551,7 +552,7 @@ public async Task HandlePartnerRegistration_WithValidData_CallsExpected()
var data = new PartnerRegistrationData(
Guid.NewGuid(),
"Test N2N",
Bpnl,
bpnl,
"Munich",
"Street",
"DE",
Expand Down Expand Up @@ -656,7 +657,7 @@ public async Task HandlePartnerRegistration_WithValidData_CallsExpected()
x.ProcessId == newProcessId &&
x.ApplicationId == newApplicationId);

A.CallTo(() => _userProvisioningService.GetOrCreateCompanyUser(A<IUserRepository>._, "test-alias", A<UserCreationRoleDataIdpInfo>._, newCompanyId, IdpId, Bpnl))
A.CallTo(() => _userProvisioningService.GetOrCreateCompanyUser(A<IUserRepository>._, "test-alias", A<UserCreationRoleDataIdpInfo>._, newCompanyId, IdpId, bpnl))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _identityProviderRepository.CreateCompanyIdentityProviders(A<IEnumerable<(Guid, Guid)>>.That.IsSameSequenceAs(new[] { new ValueTuple<Guid, Guid>(newCompanyId, IdpId) })))
.MustHaveHappenedOnceExactly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,6 @@ public async Task TriggerProviderCallback_WithoutExternalId_ThrowsUnexpectedCond
ex.Message.Should().Be("No external registration found");
}

[Fact]
public async Task TriggerProviderCallback_WithoutBpn_ThrowsUnexpectedConditionException()
{
// Arrange
var networkRegistrationId = Guid.NewGuid();
var secret = Encoding.UTF8.GetBytes(_fixture.Create<string>());
var details = new OspDetails("https://callback.url", "https://auth.url", "test1", secret);
A.CallTo(() => _networkRepository.GetCallbackData(networkRegistrationId, ProcessStepTypeId.TRIGGER_CALLBACK_OSP_APPROVED))
.Returns((details, Guid.NewGuid(), null, Guid.NewGuid(), Enumerable.Empty<string>()));

// Act
async Task Act() => await _sut.TriggerProviderCallback(networkRegistrationId, ProcessStepTypeId.TRIGGER_CALLBACK_OSP_APPROVED, CancellationToken.None).ConfigureAwait(false);

// Assert
var ex = await Assert.ThrowsAsync<UnexpectedConditionException>(Act);
ex.Message.Should().Be("Bpn must be set");
}

[Fact]
public async Task TriggerProviderCallback_WithMultipleDeclineMessages_ThrowsUnexpectedConditionException()
{
Expand Down

0 comments on commit 2e776a0

Please sign in to comment.