From 09b7684eb8b9bb5434bd7e25410f32786e456c44 Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:48:55 +0200 Subject: [PATCH 01/17] feat(company names): Increase company name length to align with front-end Length increase is required for many companies. There are also companies with special characters at the start. Back-end was already misaligned with frontend-registration. Refs: eclipse-tractusx/portal#360 --- src/framework/Framework.Models/ValidationExpressions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/Framework.Models/ValidationExpressions.cs b/src/framework/Framework.Models/ValidationExpressions.cs index 5755887180..c4d265d744 100644 --- a/src/framework/Framework.Models/ValidationExpressions.cs +++ b/src/framework/Framework.Models/ValidationExpressions.cs @@ -24,6 +24,6 @@ public static class ValidationExpressions public const string Name = @"^.+$"; public const string Bpn = @"^(BPNL|bpnl)[\w|\d]{12}$"; public const string Bpns = @"^(BPNS|bpns)[\w|\d]{12}$"; - public const string Company = @"^\d*?[A-Za-zÀ-ÿ]\d?([A-Za-z0-9À-ÿ-_+=.,:;!?'\x22&#@()]\s?){2,40}$"; + public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$"; public const string ExternalCertificateNumber = @"^[a-zA-Z0-9]{0,36}$"; } From cf5aedfc3e7a190a76b18efcc4d19dcebc0fdcff Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:23:36 +0200 Subject: [PATCH 02/17] Add generic error message and apply to all calls. --- .../BusinessLogic/InvitationBusinessLogic.cs | 2 +- .../BusinessLogic/NetworkBusinessLogic.cs | 2 +- .../BusinessLogic/RegistrationBusinessLogic.cs | 6 +++--- .../Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs | 4 ++-- .../Apps.Service/BusinessLogic/AppsBusinessLogic.cs | 2 +- .../Services.Service/BusinessLogic/ServiceBusinessLogic.cs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index 289b5ef6a6..e09b37d54d 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -57,7 +57,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName)) { - throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); } return ExecuteInvitationInternalAsync(invitationData); diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 91cbe4a288..84307832ae 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -56,7 +56,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data) { if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name)) { - throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); } var ownerCompanyId = _identityData.CompanyId; diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index df02c3c6b0..dae1ce20d7 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -87,7 +87,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name)) { - throw new ControllerArgumentException("OrganisationName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); } return new CompanyWithAddressData( @@ -126,7 +126,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); } var applications = portalRepositories.GetInstance() .GetCompanyApplicationsFilteredQuery( @@ -201,7 +201,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); } var applications = portalRepositories.GetInstance().GetAllCompanyApplicationsDetailsQuery(companyName); diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 2e5914d16f..3e34145f83 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -191,7 +191,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException("Provider length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); } return CreateAppAsync(appRequestModel); @@ -271,7 +271,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException("Provider length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the Organisation name", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); } if (appRequestModel.SalesManagerId.HasValue) diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index b33d9ccea0..04a1482463 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -160,7 +160,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) { if (!string.IsNullOrWhiteSpace(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index c3f87b85e0..609c7e119a 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -137,7 +137,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) { From 3ab45cdac7c420b7138fe42ed7105f0170b3c085 Mon Sep 17 00:00:00 2001 From: Karsten Thiems <150006841+typecastcloud@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:18:00 +0200 Subject: [PATCH 03/17] Reformatted error class usage --- .../BusinessLogic/InvitationBusinessLogic.cs | 2 +- .../BusinessLogic/NetworkBusinessLogic.cs | 2 +- .../RegistrationBusinessLogic.cs | 6 ++--- .../ValidationExpressionErrorMessages.cs | 26 +++++++++++++++++++ .../BusinessLogic/AppReleaseBusinessLogic.cs | 4 +-- .../BusinessLogic/AppsBusinessLogic.cs | 2 +- .../BusinessLogic/ServiceBusinessLogic.cs | 2 +- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/framework/Framework.Models/ValidationExpressionErrorMessages.cs diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index e09b37d54d..80f7c8ad70 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -57,7 +57,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } return ExecuteInvitationInternalAsync(invitationData); diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 84307832ae..5a8edeb69f 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -56,7 +56,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data) { if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } var ownerCompanyId = _identityData.CompanyId; diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index dae1ce20d7..f24702c860 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -87,7 +87,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressions.CompanyError}", "organisationName"); + throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } return new CompanyWithAddressData( @@ -126,7 +126,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } var applications = portalRepositories.GetInstance() .GetCompanyApplicationsFilteredQuery( @@ -201,7 +201,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}", nameof(companyName)); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } var applications = portalRepositories.GetInstance().GetAllCompanyApplicationsDetailsQuery(companyName); diff --git a/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs new file mode 100644 index 0000000000..7d5f185f7d --- /dev/null +++ b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; + +// This class contains error messages for validation expressions +public static class ValidationExpressionErrorMessages +{ + public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space"; +} diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 3e34145f83..cb00807b4e 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -191,7 +191,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } return CreateAppAsync(appRequestModel); @@ -271,7 +271,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressions.CompanyError}", nameof(appRequestModel.Provider)); + throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } if (appRequestModel.SalesManagerId.HasValue) diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index 04a1482463..83ca86a7d7 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -160,7 +160,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) { if (!string.IsNullOrWhiteSpace(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index 609c7e119a..bcacbc574e 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -137,7 +137,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData { if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressions.CompanyError}"); + throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) { From badb71f327ad91a6a282087817a747cac85dfddf Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Wed, 24 Jul 2024 11:39:46 +0200 Subject: [PATCH 04/17] optimized the company regex --- .../BusinessLogic/InvitationBusinessLogic.cs | 4 +- .../BusinessLogic/NetworkBusinessLogic.cs | 4 +- .../RegistrationBusinessLogic.cs | 6 +- .../Framework.Models/ValidationExpressions.cs | 3 + .../ValidationExpressionsValidator.cs | 30 +++++++++ .../BusinessLogic/AppReleaseBusinessLogic.cs | 6 +- .../BusinessLogic/AppsBusinessLogic.cs | 4 +- .../BusinessLogic/ServiceBusinessLogic.cs | 4 +- .../InvitationBusinessLogicTests.cs | 44 ++++++++++++ .../ValidationExpressionsTests.cs | 67 +++++++++++++++++++ 10 files changed, 153 insertions(+), 19 deletions(-) create mode 100644 src/framework/Framework.Models/ValidationExpressionsValidator.cs create mode 100644 tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index 80f7c8ad70..d53bb1004d 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -24,13 +24,11 @@ using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; using Org.Eclipse.TractusX.Portal.Backend.Processes.Library; -using System.Text.RegularExpressions; namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; public class InvitationBusinessLogic : IInvitationBusinessLogic { - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IPortalRepositories _portalRepositories; /// @@ -55,7 +53,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) throw new ControllerArgumentException("organisationName must not be empty", "organisationName"); } - if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !Company.IsMatch(invitationData.OrganisationName)) + if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !ValidationExpressionsValidator.IsValidCompanyName(invitationData.OrganisationName)) { throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 5a8edeb69f..6782b80c42 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -47,14 +47,12 @@ public class NetworkBusinessLogic( { private static readonly Regex Name = new(ValidationExpressions.Name, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private static readonly Regex ExternalId = new("^[A-Za-z0-9\\-+_/,.]{6,36}$", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - private readonly IIdentityData _identityData = identityService.IdentityData; private readonly PartnerRegistrationSettings _settings = options.Value; public async Task HandlePartnerRegistration(PartnerRegistrationData data) { - if (!string.IsNullOrEmpty(data.Name) && !Company.IsMatch(data.Name)) + if (!ValidationExpressionsValidator.IsValidCompanyName(data.Name)) { throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index f24702c860..7e2aa07d82 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -85,7 +85,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { throw NotFoundException.Create(AdministrationRegistrationErrors.APPLICATION_NOT_FOUND, [new("applicationId", applicationId.ToString())]); } - if (!string.IsNullOrEmpty(companyWithAddress.Name) && !Company.IsMatch(companyWithAddress.Name)) + if (!ValidationExpressionsValidator.IsValidCompanyName(companyWithAddress.Name)) { throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); } @@ -124,7 +124,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu public Task> GetCompanyApplicationDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName) { - if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) + if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } @@ -199,7 +199,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } public Task> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName) { - if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) + if (!ValidationExpressionsValidator.IsValidCompanyName(companyName)) { throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); } diff --git a/src/framework/Framework.Models/ValidationExpressions.cs b/src/framework/Framework.Models/ValidationExpressions.cs index c4d265d744..b996795acb 100644 --- a/src/framework/Framework.Models/ValidationExpressions.cs +++ b/src/framework/Framework.Models/ValidationExpressions.cs @@ -17,6 +17,8 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using System.Text.RegularExpressions; + namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; public static class ValidationExpressions @@ -26,4 +28,5 @@ public static class ValidationExpressions public const string Bpns = @"^(BPNS|bpns)[\w|\d]{12}$"; public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$"; public const string ExternalCertificateNumber = @"^[a-zA-Z0-9]{0,36}$"; + public static readonly Regex CompanyRegex = new(ValidationExpressions.Company, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(1)); } diff --git a/src/framework/Framework.Models/ValidationExpressionsValidator.cs b/src/framework/Framework.Models/ValidationExpressionsValidator.cs new file mode 100644 index 0000000000..c0f79ed0bd --- /dev/null +++ b/src/framework/Framework.Models/ValidationExpressionsValidator.cs @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using System.Text.RegularExpressions; + +namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; + +public static class ValidationExpressionsValidator +{ + public static bool IsValidCompanyName(string companyName) + { + return ValidationExpressions.CompanyRegex.IsMatch(companyName); + } +} diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index cb00807b4e..6bdb2d02b7 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -31,7 +31,6 @@ using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities; -using System.Text.RegularExpressions; namespace Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic; @@ -40,7 +39,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic; /// public class AppReleaseBusinessLogic : IAppReleaseBusinessLogic { - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IPortalRepositories _portalRepositories; private readonly AppsSettings _settings; private readonly IOfferService _offerService; @@ -189,7 +187,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) throw new ControllerArgumentException("Use Case Ids must not be null or empty", nameof(appRequestModel.UseCaseIds)); } - if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) + if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) { throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } @@ -269,7 +267,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo throw new ForbiddenException($"Company {companyId} is not the app provider."); } - if (!string.IsNullOrEmpty(appRequestModel.Provider) && !Company.IsMatch(appRequestModel.Provider)) + if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) { throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); } diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index 83ca86a7d7..1b5856406c 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -30,7 +30,6 @@ using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities; -using System.Text.RegularExpressions; namespace Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic; @@ -39,7 +38,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic; /// public class AppsBusinessLogic : IAppsBusinessLogic { - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IPortalRepositories _portalRepositories; private readonly IOfferSubscriptionService _offerSubscriptionService; private readonly AppsSettings _settings; @@ -158,7 +156,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) /// public async Task> GetCompanyProvidedAppSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName = null) { - if (!string.IsNullOrWhiteSpace(companyName) && !Company.IsMatch(companyName)) + if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index bcacbc574e..8e9a58a572 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -29,7 +29,6 @@ using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities; using Org.Eclipse.TractusX.Portal.Backend.Services.Service.ViewModels; -using System.Text.RegularExpressions; namespace Org.Eclipse.TractusX.Portal.Backend.Services.Service.BusinessLogic; @@ -38,7 +37,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Services.Service.BusinessLogic; /// public class ServiceBusinessLogic : IServiceBusinessLogic { - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IPortalRepositories _portalRepositories; private readonly IOfferService _offerService; private readonly IOfferSubscriptionService _offerSubscriptionService; @@ -135,7 +133,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData /// public async Task> GetCompanyProvidedServiceSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName = null) { - if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) + if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); } diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs index d36048f7d1..27d0214e5e 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs @@ -20,6 +20,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; @@ -112,6 +113,49 @@ public async Task ExecuteInvitation_WithValidData_CreatesExpected() invitations.Should().ContainSingle().And.Satisfy(x => x.ProcessId == processes.Single().Id && x.UserName == "testUserName"); } + [Theory] + [InlineData("ValidOrganisationName123")] + [InlineData("Organisation Name")] + [InlineData("Organisation$Name")] + [InlineData("Organisation\\Name")] + [InlineData("Organisation/Name")] + [InlineData("Organisation")] + [InlineData("Organisation Name!")] + [InlineData("7-ELEVEN INTERNATIONAL LLC")] + [InlineData("C")] + [InlineData("+SEN Inc.")] + [InlineData("Double \"Quote\" Company S.A.")] + [InlineData("Special Characters ^&%#@*/_-\\")] + [InlineData("German: ÄÖÜß")] + [InlineData("Icelandic: ÆÐÞ")] + [InlineData("C")] + public async Task ExecuteInvitation_WithValidOrganisationName_DoesNotThrowException(string validName) + { + var invitationData = _fixture.Build() + .With(x => x.OrganisationName, validName) + .Create(); + + Func Act = async () => await _sut.ExecuteInvitation(invitationData); + + await Act.Should().NotThrowAsync(); + } + + [Theory] + [InlineData("Organisation Name ")] // Ends with whitespace + [InlineData("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX")] // Exceeds 160 characters + public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsControllerArgumentException(string invalidName) + { + var invitationData = _fixture.Build() + .With(x => x.OrganisationName, invalidName) + .Create(); + + async Task Act() => await _sut.ExecuteInvitation(invitationData); + + var ex = await Assert.ThrowsAsync(Act); + ex.Message.Should().Be($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'organisationName')"); + ex.ParamName.Should().Be("organisationName"); + } + #endregion #region RetriggerCreateCentralIdp diff --git a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs new file mode 100644 index 0000000000..8c77d4986d --- /dev/null +++ b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs @@ -0,0 +1,67 @@ + +/******************************************************************************** + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using System.Text.RegularExpressions; + +namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Tests; + +public class ValidationExpressionsTests +{ + private static readonly Regex regex = new Regex(ValidationExpressions.Company); + + [Theory] + [InlineData("ValidCompanyName123", true)] // Valid company name + [InlineData("Company Name", true)] // Valid with space + [InlineData("Company$Name", true)] // Valid with special character + [InlineData("Company\\Name", true)] // Valid with backslash + [InlineData("Company/Name", true)] // Valid with forward slash + [InlineData("Company", true)] // Valid with angle brackets + [InlineData("Company Name!", true)] // Valid with exclamation mark + [InlineData("Company@Name", true)] // Valid with @ symbol + [InlineData("C", true)] // Minimum valid length + [InlineData("7-ELEVEN INTERNATIONAL LLC", true)] + [InlineData("Recht 24/7 Schröder Rechtsanwaltsgesellschaft mbH", true)] + [InlineData("Currency £$€¥¢", true)] + [InlineData("Brackets []()", true)] + [InlineData("Punctuation !?,.;:", true)] + [InlineData("Double \"Quote\" Company S.A.", true)] + [InlineData("Single 'Quote' Company LLC", true)] + [InlineData("Special Characters ^&%#@*/_-\\", true)] + [InlineData("German: ÄÖÜß", true)] + [InlineData("+SEN Inc.", true)] // leading special character + [InlineData("Danish: ÆØÅ", true)] + [InlineData("Bayerische Motoren Werke Aktiengesellschaft ", false)] // Ends with whitespace + [InlineData(" Bayerische Motoren Werke Aktiengesellschaft", false)] // starts with whitespace + [InlineData("Bayerische Motoren Werke Aktiengesellschaft", false)] // double whitespace + [InlineData(@"123456789012345678901234567890 + 123456789012345678901234567890 + 123456789012345678901234567890 + 123456789012345678901234567890 + 123456789012345678901234567890 + 12345678901234567890", false)] // Exceeds 160 characters + [InlineData("", false)] // Empty string + [InlineData(" ", false)] // Single space + [InlineData(" ", false)] // Multiple spaces + public void TestCompanyNameRegex(string companyName, bool expectedResult) + { + var result = ValidationExpressionsValidator.IsValidCompanyName(companyName); + Assert.Equal(expectedResult, result); + } +} \ No newline at end of file From ba55409a9f4823782006bca285468276f369fc25 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Wed, 24 Jul 2024 12:11:16 +0200 Subject: [PATCH 05/17] fixed the formatting --- .../BusinessLogic/InvitationBusinessLogicTests.cs | 1 - .../Framework.Models.Tests/ValidationExpressionsTests.cs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs index 27d0214e5e..4f7fef515f 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs @@ -128,7 +128,6 @@ public async Task ExecuteInvitation_WithValidData_CreatesExpected() [InlineData("Special Characters ^&%#@*/_-\\")] [InlineData("German: ÄÖÜß")] [InlineData("Icelandic: ÆÐÞ")] - [InlineData("C")] public async Task ExecuteInvitation_WithValidOrganisationName_DoesNotThrowException(string validName) { var invitationData = _fixture.Build() diff --git a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs index 8c77d4986d..916ba65ce3 100644 --- a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs +++ b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs @@ -24,8 +24,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Tests; public class ValidationExpressionsTests { - private static readonly Regex regex = new Regex(ValidationExpressions.Company); - [Theory] [InlineData("ValidCompanyName123", true)] // Valid company name [InlineData("Company Name", true)] // Valid with space @@ -64,4 +62,4 @@ public void TestCompanyNameRegex(string companyName, bool expectedResult) var result = ValidationExpressionsValidator.IsValidCompanyName(companyName); Assert.Equal(expectedResult, result); } -} \ No newline at end of file +} From f9e8da35fbddb325f5e981341b7d69224c3d54b5 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Wed, 24 Jul 2024 16:37:04 +0200 Subject: [PATCH 06/17] updated new code to adapt the validation of company regex --- .../BusinessLogic/CompanyDataBusinessLogic.cs | 4 ++-- .../BusinessLogic/CompanyDataBusinessLogicTests.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index fc8a9b769f..9643d2254f 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -267,9 +267,9 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data, throw new ControllerArgumentException("ValidTill date should be greater than current date"); } - if (data.Issuer != null && !Company.IsMatch(data.Issuer!)) + if (!string.IsNullOrEmpty(data.Issuer) && !ValidationExpressionsValidator.IsValidCompanyName(data.Issuer)) { - throw new ControllerArgumentException("Issuer length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name"); + throw new ControllerArgumentException($"Issuer: {ValidationExpressionErrorMessages.CompanyError}", nameof(data.Issuer)); } var documentContentType = data.Document.ContentType.ParseMediaTypeId(); diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs index f4e7fb44cb..fe6877a153 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs @@ -885,7 +885,7 @@ public async Task CheckCompanyCertificateType_WithInvalidCall_ThrowsControllerFo var file = FormFileHelper.GetFormFile("test content", "test.pdf", MediaTypeId.PDF.MapToMediaType()); var externalCertificateNumber = "2345678"; var sites = new[] { "BPNS00000003CRHK" }; - var data = new CompanyCertificateCreationData(CompanyCertificateTypeId.IATF, file, externalCertificateNumber, sites, _now.AddMicroseconds(-1), _now.AddMicroseconds(1), "+ACC"); + var data = new CompanyCertificateCreationData(CompanyCertificateTypeId.IATF, file, externalCertificateNumber, sites, _now.AddMicroseconds(-1), _now.AddMicroseconds(1), " +ACC"); A.CallTo(() => _companyCertificateRepository.CheckCompanyCertificateType(CompanyCertificateTypeId.IATF)) .Returns(false); @@ -895,7 +895,8 @@ public async Task CheckCompanyCertificateType_WithInvalidCall_ThrowsControllerFo // Assert var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be($"Issuer length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name"); + ex.Message.Should().Be($"Issuer: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'Issuer')"); + ex.ParamName.Should().Be("Issuer"); } #endregion From 28bc29c4d42deaf0fafd5f7a4127919624285984 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Wed, 24 Jul 2024 16:41:34 +0200 Subject: [PATCH 07/17] removed unused variable --- .../BusinessLogic/CompanyDataBusinessLogic.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index 9643d2254f..8d858b658f 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -45,7 +45,6 @@ public class CompanyDataBusinessLogic( { private static readonly Regex BpnsRegex = new(ValidationExpressions.Bpns, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private static readonly Regex EcmRegex = new(ValidationExpressions.ExternalCertificateNumber, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IIdentityData _identityData = identityService.IdentityData; private readonly CompanyDataSettings _settings = options.Value; From 6a32137968306b79ba52724dd8652139f1415137 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Fri, 26 Jul 2024 13:56:12 +0200 Subject: [PATCH 08/17] adapted the translatable error messages --- .../BusinessLogic/CompanyDataBusinessLogic.cs | 2 +- .../BusinessLogic/InvitationBusinessLogic.cs | 2 +- .../BusinessLogic/NetworkBusinessLogic.cs | 2 +- .../BusinessLogic/RegistrationBusinessLogic.cs | 6 +++--- .../Administration.Service/Program.cs | 4 +++- .../ValidationExpressionErrorMessages.cs | 18 ++++++++++++++++-- .../BusinessLogic/AppReleaseBusinessLogic.cs | 4 ++-- .../BusinessLogic/AppsBusinessLogic.cs | 2 +- src/marketplace/Apps.Service/Program.cs | 3 +++ .../BusinessLogic/ServiceBusinessLogic.cs | 2 +- src/marketplace/Services.Service/Program.cs | 3 +++ .../CompanyDataBusinessLogicTests.cs | 3 +-- .../InvitationBusinessLogicTests.cs | 3 +-- 13 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index 8d858b658f..7bdc636e3a 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -268,7 +268,7 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data, if (!string.IsNullOrEmpty(data.Issuer) && !ValidationExpressionsValidator.IsValidCompanyName(data.Issuer)) { - throw new ControllerArgumentException($"Issuer: {ValidationExpressionErrorMessages.CompanyError}", nameof(data.Issuer)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(data.Issuer))]); } var documentContentType = data.Document.ContentType.ParseMediaTypeId(); diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index d53bb1004d..a471949fa1 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -55,7 +55,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !ValidationExpressionsValidator.IsValidCompanyName(invitationData.OrganisationName)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(invitationData.OrganisationName))]); } return ExecuteInvitationInternalAsync(invitationData); diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 6782b80c42..706e5129ff 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -54,7 +54,7 @@ public async Task HandlePartnerRegistration(PartnerRegistrationData data) { if (!ValidationExpressionsValidator.IsValidCompanyName(data.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]); } var ownerCompanyId = _identityData.CompanyId; diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 7e2aa07d82..ef1e3bb236 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -87,7 +87,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } if (!ValidationExpressionsValidator.IsValidCompanyName(companyWithAddress.Name)) { - throw new ControllerArgumentException($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError}", "organisationName"); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]); } return new CompanyWithAddressData( @@ -126,7 +126,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } var applications = portalRepositories.GetInstance() .GetCompanyApplicationsFilteredQuery( @@ -201,7 +201,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { if (!ValidationExpressionsValidator.IsValidCompanyName(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}", nameof(companyName)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } var applications = portalRepositories.GetInstance().GetAllCompanyApplicationsDetailsQuery(companyName); diff --git a/src/administration/Administration.Service/Program.cs b/src/administration/Administration.Service/Program.cs index a6868d2408..3f366431c3 100644 --- a/src/administration/Administration.Service/Program.cs +++ b/src/administration/Administration.Service/Program.cs @@ -21,6 +21,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.ErrorHandling; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; @@ -94,7 +95,8 @@ await WebAppHelper .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); builder.Services.AddProvisioningDBAccess(builder.Configuration); }).ConfigureAwait(ConfigureAwaitOptions.None); diff --git a/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs index 7d5f185f7d..e06fe4fb98 100644 --- a/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs +++ b/src/framework/Framework.Models/ValidationExpressionErrorMessages.cs @@ -17,10 +17,24 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; +using System.Collections.Immutable; + namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; // This class contains error messages for validation expressions -public static class ValidationExpressionErrorMessages +public class ValidationExpressionErrorMessageContainer : IErrorMessageContainer +{ + private static readonly IReadOnlyDictionary _messageContainer = new Dictionary { + { ValidationExpressionErrors.INCORRECT_COMPANY_NAME, "{name}: length must be between 1 and 160 characters and not start or end with a white space" }, + + }.ToImmutableDictionary(x => (int)x.Key, x => x.Value); + + public Type Type { get => typeof(ValidationExpressionErrors); } + public IReadOnlyDictionary MessageContainer { get => _messageContainer; } +} + +public enum ValidationExpressionErrors { - public const string CompanyError = "length must be between 1 and 160 characters and not start or end with a white space"; + INCORRECT_COMPANY_NAME } diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 6bdb2d02b7..edb6acc054 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -189,7 +189,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]); } return CreateAppAsync(appRequestModel); @@ -269,7 +269,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) { - throw new ControllerArgumentException($"Provider: {ValidationExpressionErrorMessages.CompanyError}", nameof(appRequestModel.Provider)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]); } if (appRequestModel.SalesManagerId.HasValue) diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index 1b5856406c..62e5239438 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -158,7 +158,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) { if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) diff --git a/src/marketplace/Apps.Service/Program.cs b/src/marketplace/Apps.Service/Program.cs index 1ba4cf95e1..115a990021 100644 --- a/src/marketplace/Apps.Service/Program.cs +++ b/src/marketplace/Apps.Service/Program.cs @@ -19,6 +19,8 @@ using Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection; +using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Service; @@ -48,6 +50,7 @@ await WebAppHelper .AddTransient() .AddTransient() .AddTransient() + .AddSingleton() .AddTechnicalUserProfile() .ConfigureAppsSettings(builder.Configuration.GetSection("AppMarketPlace")) .AddOfferDocumentServices(); diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index 8e9a58a572..1bb240d4ef 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -135,7 +135,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData { if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { - throw new ControllerArgumentException($"CompanyName: {ValidationExpressionErrorMessages.CompanyError}"); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } async Task?> GetCompanyProvidedAppSubscriptionStatusData(int skip, int take) { diff --git a/src/marketplace/Services.Service/Program.cs b/src/marketplace/Services.Service/Program.cs index 43ca334e85..a3def391ee 100644 --- a/src/marketplace/Services.Service/Program.cs +++ b/src/marketplace/Services.Service/Program.cs @@ -18,6 +18,8 @@ ********************************************************************************/ using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection; +using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Web.DependencyInjection; @@ -48,6 +50,7 @@ await WebAppHelper .AddServiceBusinessLogic(builder.Configuration) .AddTransient() .AddTransient() + .AddSingleton() .AddTechnicalUserProfile() .AddOfferDocumentServices(); diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs index fe6877a153..4a88b22a2a 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/CompanyDataBusinessLogicTests.cs @@ -895,8 +895,7 @@ public async Task CheckCompanyCertificateType_WithInvalidCall_ThrowsControllerFo // Assert var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be($"Issuer: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'Issuer')"); - ex.ParamName.Should().Be("Issuer"); + ex.Message.Should().Be(ValidationExpressionErrors.INCORRECT_COMPANY_NAME.ToString()); } #endregion diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs index 4f7fef515f..d609cc3a58 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs @@ -151,8 +151,7 @@ public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsController async Task Act() => await _sut.ExecuteInvitation(invitationData); var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be($"OrganisationName: {ValidationExpressionErrorMessages.CompanyError} (Parameter 'organisationName')"); - ex.ParamName.Should().Be("organisationName"); + ex.Message.Should().Be(ValidationExpressionErrors.INCORRECT_COMPANY_NAME.ToString()); } #endregion From 18fba5f166aec430c8c4afd2e8465ca1f2df3949 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Fri, 26 Jul 2024 15:09:14 +0200 Subject: [PATCH 09/17] added Singleton Errormessage service to resolve the error details --- src/marketplace/Apps.Service/Program.cs | 1 + src/marketplace/Services.Service/Program.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/marketplace/Apps.Service/Program.cs b/src/marketplace/Apps.Service/Program.cs index 115a990021..a2be778650 100644 --- a/src/marketplace/Apps.Service/Program.cs +++ b/src/marketplace/Apps.Service/Program.cs @@ -50,6 +50,7 @@ await WebAppHelper .AddTransient() .AddTransient() .AddTransient() + .AddSingleton() .AddSingleton() .AddTechnicalUserProfile() .ConfigureAppsSettings(builder.Configuration.GetSection("AppMarketPlace")) diff --git a/src/marketplace/Services.Service/Program.cs b/src/marketplace/Services.Service/Program.cs index a3def391ee..3ed8f2ef65 100644 --- a/src/marketplace/Services.Service/Program.cs +++ b/src/marketplace/Services.Service/Program.cs @@ -50,6 +50,7 @@ await WebAppHelper .AddServiceBusinessLogic(builder.Configuration) .AddTransient() .AddTransient() + .AddSingleton() .AddSingleton() .AddTechnicalUserProfile() .AddOfferDocumentServices(); From be7c6928d64dc303fbef4ffd848b7636c497c970 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Mon, 5 Aug 2024 13:34:27 +0200 Subject: [PATCH 10/17] updated version of framework packages --- src/framework/Framework.Async/Directory.Build.props | 2 +- src/framework/Framework.Cors/Directory.Build.props | 2 +- src/framework/Framework.DBAccess/Directory.Build.props | 2 +- src/framework/Framework.DateTimeProvider/Directory.Build.props | 2 +- .../Framework.DependencyInjection/Directory.Build.props | 2 +- .../Framework.ErrorHandling.Controller/Directory.Build.props | 2 +- src/framework/Framework.ErrorHandling.Web/Directory.Build.props | 2 +- src/framework/Framework.ErrorHandling/Directory.Build.props | 2 +- .../Framework.HttpClientExtensions/Directory.Build.props | 2 +- src/framework/Framework.IO/Directory.Build.props | 2 +- src/framework/Framework.Linq/Directory.Build.props | 2 +- src/framework/Framework.Logging/Directory.Build.props | 2 +- src/framework/Framework.Models/Directory.Build.props | 2 +- src/framework/Framework.Seeding/Directory.Build.props | 2 +- src/framework/Framework.Swagger/Directory.Build.props | 2 +- src/framework/Framework.Token/Directory.Build.props | 2 +- src/framework/Framework.Web/Directory.Build.props | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/framework/Framework.Async/Directory.Build.props b/src/framework/Framework.Async/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Async/Directory.Build.props +++ b/src/framework/Framework.Async/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Cors/Directory.Build.props b/src/framework/Framework.Cors/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Cors/Directory.Build.props +++ b/src/framework/Framework.Cors/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.DBAccess/Directory.Build.props b/src/framework/Framework.DBAccess/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.DBAccess/Directory.Build.props +++ b/src/framework/Framework.DBAccess/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.DateTimeProvider/Directory.Build.props b/src/framework/Framework.DateTimeProvider/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.DateTimeProvider/Directory.Build.props +++ b/src/framework/Framework.DateTimeProvider/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.DependencyInjection/Directory.Build.props b/src/framework/Framework.DependencyInjection/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.DependencyInjection/Directory.Build.props +++ b/src/framework/Framework.DependencyInjection/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props b/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling.Controller/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.ErrorHandling.Web/Directory.Build.props b/src/framework/Framework.ErrorHandling.Web/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.ErrorHandling.Web/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling.Web/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.ErrorHandling/Directory.Build.props b/src/framework/Framework.ErrorHandling/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.ErrorHandling/Directory.Build.props +++ b/src/framework/Framework.ErrorHandling/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.HttpClientExtensions/Directory.Build.props b/src/framework/Framework.HttpClientExtensions/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.HttpClientExtensions/Directory.Build.props +++ b/src/framework/Framework.HttpClientExtensions/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.IO/Directory.Build.props b/src/framework/Framework.IO/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.IO/Directory.Build.props +++ b/src/framework/Framework.IO/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Linq/Directory.Build.props b/src/framework/Framework.Linq/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Linq/Directory.Build.props +++ b/src/framework/Framework.Linq/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Logging/Directory.Build.props b/src/framework/Framework.Logging/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Logging/Directory.Build.props +++ b/src/framework/Framework.Logging/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Models/Directory.Build.props b/src/framework/Framework.Models/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Models/Directory.Build.props +++ b/src/framework/Framework.Models/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Seeding/Directory.Build.props b/src/framework/Framework.Seeding/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Seeding/Directory.Build.props +++ b/src/framework/Framework.Seeding/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Swagger/Directory.Build.props b/src/framework/Framework.Swagger/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Swagger/Directory.Build.props +++ b/src/framework/Framework.Swagger/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Token/Directory.Build.props b/src/framework/Framework.Token/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Token/Directory.Build.props +++ b/src/framework/Framework.Token/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 diff --git a/src/framework/Framework.Web/Directory.Build.props b/src/framework/Framework.Web/Directory.Build.props index f53f08f151..416bf1cdf9 100644 --- a/src/framework/Framework.Web/Directory.Build.props +++ b/src/framework/Framework.Web/Directory.Build.props @@ -19,7 +19,7 @@ - 2.5.0 + 2.6.0 From 10e2bc2e89fc91bf9a9c4ebfe02a114da8e24bf1 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Mon, 5 Aug 2024 13:40:33 +0200 Subject: [PATCH 11/17] fix the validation from new code --- .../BusinessLogic/RegistrationBusinessLogic.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index ef1e3bb236..827a9b5d5e 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -164,9 +164,9 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu public Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName) { - if (!string.IsNullOrEmpty(companyName) && !Company.IsMatch(companyName)) + if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) { - throw new ControllerArgumentException("CompanyName length must be 3-40 characters and *+=#%\\s not used as one of the first three characters in the company name", nameof(companyName)); + throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } var applications = portalRepositories.GetInstance() .GetExternalCompanyApplicationsFilteredQuery(_identityData.CompanyId, From 1ae8b35fd210d8da3866741e0b706faabed81539 Mon Sep 17 00:00:00 2001 From: "Dhirender Singh (Cofinity-X)" <144212607+dhiren-singh-007@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:49:06 +0200 Subject: [PATCH 12/17] Update src/framework/Framework.Models/ValidationExpressionsValidator.cs Co-authored-by: Phil Schneider --- .../Framework.Models/ValidationExpressionsValidator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/Framework.Models/ValidationExpressionsValidator.cs b/src/framework/Framework.Models/ValidationExpressionsValidator.cs index c0f79ed0bd..92830c1204 100644 --- a/src/framework/Framework.Models/ValidationExpressionsValidator.cs +++ b/src/framework/Framework.Models/ValidationExpressionsValidator.cs @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From 1d26fda79a601c2900cb9a6e9b49f378ad1dce1e Mon Sep 17 00:00:00 2001 From: "Dhirender Singh (Cofinity-X)" <144212607+dhiren-singh-007@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:49:42 +0200 Subject: [PATCH 13/17] Update tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs Co-authored-by: Phil Schneider --- .../Framework.Models.Tests/ValidationExpressionsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs index 916ba65ce3..2c5b282d6d 100644 --- a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs +++ b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs @@ -1,6 +1,6 @@ /******************************************************************************** - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From a906833b49efc029cd88f3d498705198e879142a Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Thu, 8 Aug 2024 11:25:32 +0200 Subject: [PATCH 14/17] removed unused variable --- .../BusinessLogic/RegistrationBusinessLogic.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 827a9b5d5e..4ba37115a4 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -63,7 +63,6 @@ public sealed class RegistrationBusinessLogic( : IRegistrationBusinessLogic { private static readonly Regex BpnRegex = new(ValidationExpressions.Bpn, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); - private static readonly Regex Company = new(ValidationExpressions.Company, RegexOptions.Compiled, TimeSpan.FromSeconds(1)); private readonly IIdentityData _identityData = identityService.IdentityData; private readonly RegistrationSettings _settings = configuration.Value; From 2a4e2f9ff2319aa916742f49abaaad8de462acd6 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Tue, 13 Aug 2024 17:42:45 +0200 Subject: [PATCH 15/17] applied the suggestions --- .../BusinessLogic/CompanyDataBusinessLogic.cs | 2 +- .../BusinessLogic/InvitationBusinessLogic.cs | 7 +------ .../BusinessLogic/NetworkBusinessLogic.cs | 2 +- .../BusinessLogic/RegistrationBusinessLogic.cs | 8 ++++---- .../Framework.Models/ValidationExpressions.cs | 1 - .../ValidationExpressionsValidator.cs | 5 +++-- .../BusinessLogic/AppReleaseBusinessLogic.cs | 4 ++-- .../BusinessLogic/AppsBusinessLogic.cs | 2 +- .../BusinessLogic/ServiceBusinessLogic.cs | 2 +- .../InvitationBusinessLogicTests.cs | 18 +----------------- .../ValidationExpressionsTests.cs | 2 +- 11 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs index 7bdc636e3a..0cf42b585b 100644 --- a/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/CompanyDataBusinessLogic.cs @@ -266,7 +266,7 @@ public async Task CreateCompanyCertificate(CompanyCertificateCreationData data, throw new ControllerArgumentException("ValidTill date should be greater than current date"); } - if (!string.IsNullOrEmpty(data.Issuer) && !ValidationExpressionsValidator.IsValidCompanyName(data.Issuer)) + if (data.Issuer != null && !data.Issuer.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(data.Issuer))]); } diff --git a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs index a471949fa1..49bb0bca7d 100644 --- a/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/InvitationBusinessLogic.cs @@ -48,12 +48,7 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData) throw new ControllerArgumentException("email must not be empty", "email"); } - if (string.IsNullOrWhiteSpace(invitationData.OrganisationName)) - { - throw new ControllerArgumentException("organisationName must not be empty", "organisationName"); - } - - if (!string.IsNullOrEmpty(invitationData.OrganisationName) && !ValidationExpressionsValidator.IsValidCompanyName(invitationData.OrganisationName)) + if (invitationData.OrganisationName == null || !invitationData.OrganisationName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(invitationData.OrganisationName))]); } diff --git a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs index 706e5129ff..7550d8803d 100644 --- a/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/NetworkBusinessLogic.cs @@ -52,7 +52,7 @@ public class NetworkBusinessLogic( public async Task HandlePartnerRegistration(PartnerRegistrationData data) { - if (!ValidationExpressionsValidator.IsValidCompanyName(data.Name)) + if (!data.Name.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]); } diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index 4ba37115a4..ad4110e38a 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -84,7 +84,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu { throw NotFoundException.Create(AdministrationRegistrationErrors.APPLICATION_NOT_FOUND, [new("applicationId", applicationId.ToString())]); } - if (!ValidationExpressionsValidator.IsValidCompanyName(companyWithAddress.Name)) + if (!companyWithAddress.Name.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "OrganisationName")]); } @@ -123,7 +123,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu public Task> GetCompanyApplicationDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName) { - if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } @@ -163,7 +163,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu public Task> GetOspCompanyDetailsAsync(int page, int size, CompanyApplicationStatusFilter? companyApplicationStatusFilter, string? companyName) { - if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } @@ -198,7 +198,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } public Task> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName) { - if (!ValidationExpressionsValidator.IsValidCompanyName(companyName)) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } diff --git a/src/framework/Framework.Models/ValidationExpressions.cs b/src/framework/Framework.Models/ValidationExpressions.cs index b996795acb..b86338686f 100644 --- a/src/framework/Framework.Models/ValidationExpressions.cs +++ b/src/framework/Framework.Models/ValidationExpressions.cs @@ -28,5 +28,4 @@ public static class ValidationExpressions public const string Bpns = @"^(BPNS|bpns)[\w|\d]{12}$"; public const string Company = @"^(?!.*\s$)([\wÀ-ÿ£$€¥¢@%*+\-/\\,.:;=<>!?&^#'\x22()[\]]\s?){1,160}$"; public const string ExternalCertificateNumber = @"^[a-zA-Z0-9]{0,36}$"; - public static readonly Regex CompanyRegex = new(ValidationExpressions.Company, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(1)); } diff --git a/src/framework/Framework.Models/ValidationExpressionsValidator.cs b/src/framework/Framework.Models/ValidationExpressionsValidator.cs index 92830c1204..1e62a06aec 100644 --- a/src/framework/Framework.Models/ValidationExpressionsValidator.cs +++ b/src/framework/Framework.Models/ValidationExpressionsValidator.cs @@ -23,8 +23,9 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; public static class ValidationExpressionsValidator { - public static bool IsValidCompanyName(string companyName) + private static readonly Regex CompanyRegex = new(ValidationExpressions.Company, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(1)); + public static bool IsValidCompanyName(this string companyName) { - return ValidationExpressions.CompanyRegex.IsMatch(companyName); + return CompanyRegex.IsMatch(companyName); } } diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index edb6acc054..b61d226008 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -187,7 +187,7 @@ public Task AddAppAsync(AppRequestModel appRequestModel) throw new ControllerArgumentException("Use Case Ids must not be null or empty", nameof(appRequestModel.UseCaseIds)); } - if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) + if (appRequestModel.Provider != null && !appRequestModel.Provider.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]); } @@ -267,7 +267,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo throw new ForbiddenException($"Company {companyId} is not the app provider."); } - if (!string.IsNullOrEmpty(appRequestModel.Provider) && !ValidationExpressionsValidator.IsValidCompanyName(appRequestModel.Provider)) + if (appRequestModel.Provider != null && !appRequestModel.Provider.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", nameof(appRequestModel.Provider))]); } diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs index 62e5239438..4bbe253efc 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsBusinessLogic.cs @@ -156,7 +156,7 @@ public async Task AddFavouriteAppForUserAsync(Guid appId) /// public async Task> GetCompanyProvidedAppSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName = null) { - if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs index 1bb240d4ef..366cc59eea 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceBusinessLogic.cs @@ -133,7 +133,7 @@ public Task AutoSetupServiceAsync(OfferAutoSetupData /// public async Task> GetCompanyProvidedServiceSubscriptionStatusesForUserAsync(int page, int size, SubscriptionStatusSorting? sorting, OfferSubscriptionStatusId? statusId, Guid? offerId, string? companyName = null) { - if (!string.IsNullOrEmpty(companyName) && !ValidationExpressionsValidator.IsValidCompanyName(companyName)) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs index d609cc3a58..318d173067 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs @@ -72,23 +72,6 @@ public async Task ExecuteInvitation_WithoutEmail_ThrowsControllerArgumentExcepti ex.ParamName.Should().Be("email"); } - [Fact] - public async Task ExecuteInvitation_WithoutOrganisationName_ThrowsControllerArgumentException() - { - var invitationData = _fixture.Build() - .With(x => x.OrganisationName, (string?)null) - .WithNamePattern(x => x.FirstName) - .WithNamePattern(x => x.LastName) - .WithEmailPattern(x => x.Email) - .Create(); - - async Task Act() => await _sut.ExecuteInvitation(invitationData); - - var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be("organisationName must not be empty (Parameter 'organisationName')"); - ex.ParamName.Should().Be("organisationName"); - } - [Fact] public async Task ExecuteInvitation_WithValidData_CreatesExpected() { @@ -140,6 +123,7 @@ public async Task ExecuteInvitation_WithValidOrganisationName_DoesNotThrowExcept } [Theory] + [InlineData((string?)null)] // null value [InlineData("Organisation Name ")] // Ends with whitespace [InlineData("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX")] // Exceeds 160 characters public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsControllerArgumentException(string invalidName) diff --git a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs index 2c5b282d6d..2e8f9f0d50 100644 --- a/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs +++ b/tests/framework/Framework.Models.Tests/ValidationExpressionsTests.cs @@ -59,7 +59,7 @@ public class ValidationExpressionsTests [InlineData(" ", false)] // Multiple spaces public void TestCompanyNameRegex(string companyName, bool expectedResult) { - var result = ValidationExpressionsValidator.IsValidCompanyName(companyName); + var result = companyName.IsValidCompanyName(); Assert.Equal(expectedResult, result); } } From ddc4d738b827bb6c63d6237fac302c92b5196a17 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Tue, 13 Aug 2024 17:47:41 +0200 Subject: [PATCH 16/17] removed unused RegularExpressions --- src/framework/Framework.Models/ValidationExpressions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/framework/Framework.Models/ValidationExpressions.cs b/src/framework/Framework.Models/ValidationExpressions.cs index b86338686f..c4d265d744 100644 --- a/src/framework/Framework.Models/ValidationExpressions.cs +++ b/src/framework/Framework.Models/ValidationExpressions.cs @@ -17,8 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -using System.Text.RegularExpressions; - namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models; public static class ValidationExpressions From 897d00ece1b0b736d9cf41fcaa4f891d2c4dda4a Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Tue, 13 Aug 2024 21:14:45 +0200 Subject: [PATCH 17/17] fix the format --- .../BusinessLogic/RegistrationBusinessLogic.cs | 2 +- .../BusinessLogic/InvitationBusinessLogicTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs index ad4110e38a..9b1b59e811 100644 --- a/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/RegistrationBusinessLogic.cs @@ -198,7 +198,7 @@ private async Task GetCompanyWithAddressAsyncInternal(Gu } public Task> GetAllCompanyApplicationsDetailsAsync(int page, int size, string? companyName) { - if (companyName != null && !companyName.IsValidCompanyName()) + if (companyName != null && !companyName.IsValidCompanyName()) { throw ControllerArgumentException.Create(ValidationExpressionErrors.INCORRECT_COMPANY_NAME, [new("name", "CompanyName")]); } diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs index 318d173067..43c3c8d195 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/InvitationBusinessLogicTests.cs @@ -123,10 +123,10 @@ public async Task ExecuteInvitation_WithValidOrganisationName_DoesNotThrowExcept } [Theory] - [InlineData((string?)null)] // null value + [InlineData(null)] // null value [InlineData("Organisation Name ")] // Ends with whitespace [InlineData("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWX")] // Exceeds 160 characters - public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsControllerArgumentException(string invalidName) + public async Task ExecuteInvitation_WithInvalidOrganisationName_ThrowsControllerArgumentException(string? invalidName) { var invitationData = _fixture.Build() .With(x => x.OrganisationName, invalidName)