From 44120a2c3977736a5a9b5b560370a46cfaf2d072 Mon Sep 17 00:00:00 2001 From: AsterITA Date: Wed, 2 Oct 2024 17:36:25 +0200 Subject: [PATCH 1/2] removed contenTypes checks --- packages/backend-for-frontend/src/model/errors.ts | 15 +-------------- .../src/routers/agreementRouter.ts | 3 +-- .../src/services/agreementService.ts | 13 ------------- .../src/services/purposeService.ts | 11 ----------- .../src/utilities/errorMappers.ts | 7 ------- .../src/utilities/mimeTypes.ts | 13 ------------- 6 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 packages/backend-for-frontend/src/utilities/mimeTypes.ts diff --git a/packages/backend-for-frontend/src/model/errors.ts b/packages/backend-for-frontend/src/model/errors.ts index 314a5f3cf3..2681cbfe16 100644 --- a/packages/backend-for-frontend/src/model/errors.ts +++ b/packages/backend-for-frontend/src/model/errors.ts @@ -35,7 +35,7 @@ export const errorCodes = { invalidJwtClaim: "0026", samlNotValid: "0027", missingSelfcareId: "0028", - invalidContentType: "0029", + invalidZipStructure: "0029", contractNotFound: "0030", contractException: "0031", notValidDescriptor: "0032", @@ -43,7 +43,6 @@ export const errorCodes = { privacyNoticeNotFoundInConfiguration: "0034", privacyNoticeNotFound: "0035", privacyNoticeVersionIsNotTheLatest: "0036", - invalidZipStructure: "0037", }; export type ErrorCodes = keyof typeof errorCodes; @@ -359,18 +358,6 @@ export function contractException(agreementId: string): ApiError { }); } -export function invalidContentType( - contentType: string, - agreementId: string, - documentId: string -): ApiError { - return new ApiError({ - detail: `Invalid contentType ${contentType} for document ${documentId} from agreement ${agreementId}`, - code: "invalidContentType", - title: "Invalid content type", - }); -} - export function invalidZipStructure(description: string): ApiError { return new ApiError({ detail: `Invalid zip structure: ${description}`, diff --git a/packages/backend-for-frontend/src/routers/agreementRouter.ts b/packages/backend-for-frontend/src/routers/agreementRouter.ts index 8039ef6ef1..7c7f3c3571 100644 --- a/packages/backend-for-frontend/src/routers/agreementRouter.ts +++ b/packages/backend-for-frontend/src/routers/agreementRouter.ts @@ -14,7 +14,6 @@ import { activateAgreementErrorMapper, emptyErrorMapper, getAgreementByIdErrorMapper, - getAgreementConsumerDocumentErrorMapper, getAgreementContractErrorMapper, getAgreementsErrorMapper, } from "../utilities/errorMappers.js"; @@ -309,7 +308,7 @@ const agreementRouter = ( } catch (error) { const errorRes = makeApiProblem( error, - getAgreementConsumerDocumentErrorMapper, + emptyErrorMapper, ctx.logger, `Error downloading consumer document ${req.params.documentId} for agreement ${req.params.agreementId}` ); diff --git a/packages/backend-for-frontend/src/services/agreementService.ts b/packages/backend-for-frontend/src/services/agreementService.ts index cc5e325b11..9d59007ead 100644 --- a/packages/backend-for-frontend/src/services/agreementService.ts +++ b/packages/backend-for-frontend/src/services/agreementService.ts @@ -25,10 +25,8 @@ import { agreementDescriptorNotFound, contractException, contractNotFound, - invalidContentType, } from "../model/errors.js"; import { config } from "../config/config.js"; -import { contentTypes } from "../utilities/mimeTypes.js"; import { getLatestTenantContactEmail } from "../model/modelMappingUtils.js"; import { toCompactEservice, @@ -197,8 +195,6 @@ export function agreementServiceBuilder( headers, }); - assertContentMediaType(document.contentType, agreementId, documentId); - const documentBytes = await fileManager.get( config.consumerDocumentsContainer, document.path, @@ -788,15 +784,6 @@ export function getCurrentDescriptor( return descriptor; } -function assertContentMediaType( - contentType: string, - agreementId: string, - documentId: string -): void { - if (!contentTypes.includes(contentType)) { - throw invalidContentType(contentType, agreementId, documentId); - } -} const emptyPagination = (offset: number, limit: number) => ({ pagination: { limit, diff --git a/packages/backend-for-frontend/src/services/purposeService.ts b/packages/backend-for-frontend/src/services/purposeService.ts index 31e0650881..7aac5e1d02 100644 --- a/packages/backend-for-frontend/src/services/purposeService.ts +++ b/packages/backend-for-frontend/src/services/purposeService.ts @@ -28,14 +28,12 @@ import { agreementNotFound, eserviceDescriptorNotFound, eServiceNotFound, - invalidRiskAnalysisContentType, purposeDraftVersionNotFound, purposeNotFound, tenantNotFound, } from "../model/errors.js"; import { BffAppContext, Headers } from "../utilities/context.js"; import { config } from "../config/config.js"; -import { contentTypes } from "../utilities/mimeTypes.js"; import { toBffApiCompactClient } from "../api/authorizationApiConverter.js"; import { toBffApiPurposeVersion } from "../api/purposeApiConverter.js"; import { getLatestAgreement } from "./agreementService.js"; @@ -434,15 +432,6 @@ export function purposeServiceBuilder( headers, }); - if (!contentTypes.includes(document.contentType)) { - throw invalidRiskAnalysisContentType( - document.contentType, - purposeId, - versionId, - documentId - ); - } - return await fileManager.get( config.riskAnalysisDocumentsContainer, document.path, diff --git a/packages/backend-for-frontend/src/utilities/errorMappers.ts b/packages/backend-for-frontend/src/utilities/errorMappers.ts index 45510005a4..444644cb1a 100644 --- a/packages/backend-for-frontend/src/utilities/errorMappers.ts +++ b/packages/backend-for-frontend/src/utilities/errorMappers.ts @@ -108,13 +108,6 @@ export const getAgreementContractErrorMapper = ( .with("contractNotFound", () => HTTP_STATUS_NOT_FOUND) .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); -export const getAgreementConsumerDocumentErrorMapper = ( - error: ApiError -): number => - match(error.code) - .with("invalidContentType", () => HTTP_STATUS_INTERNAL_SERVER_ERROR) - .otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR); - export const activateAgreementErrorMapper = ( error: ApiError ): number => diff --git a/packages/backend-for-frontend/src/utilities/mimeTypes.ts b/packages/backend-for-frontend/src/utilities/mimeTypes.ts deleted file mode 100644 index b8e78e37e8..0000000000 --- a/packages/backend-for-frontend/src/utilities/mimeTypes.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Content types from: https://doc.akka.io/api/akka-http/current/akka/http/scaladsl/model/ContentTypes - -export const contentTypes = [ - "NoContentType", - "application/grpc+proto", - "application/json", - "application/octet-stream", - "application/x-www-form-urlencoded", - "text/csv(UTF-8)", - "text/html(UTF-8)", - "text/plain(UTF-8)", - "text/xml(UTF-8)", -]; From 18dd7f9e7ac8a427ec3aed0d9c6cc8c43be4f325 Mon Sep 17 00:00:00 2001 From: AsterITA Date: Wed, 2 Oct 2024 17:48:31 +0200 Subject: [PATCH 2/2] removed unused invalidRiskAnalysisContentType --- .../backend-for-frontend/src/model/errors.ts | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/packages/backend-for-frontend/src/model/errors.ts b/packages/backend-for-frontend/src/model/errors.ts index 2681cbfe16..7376f2505a 100644 --- a/packages/backend-for-frontend/src/model/errors.ts +++ b/packages/backend-for-frontend/src/model/errors.ts @@ -21,7 +21,7 @@ export const errorCodes = { agreementNotFound: "0012", eserviceDescriptorNotFound: "0013", purposeDraftVersionNotFound: "0014", - invalidRiskAnalysisContentType: "0015", + dynamoReadingError: "0015", missingInterface: "0016", eserviceRiskNotFound: "0017", noDescriptorInEservice: "0018", @@ -39,10 +39,9 @@ export const errorCodes = { contractNotFound: "0030", contractException: "0031", notValidDescriptor: "0032", - dynamoReadingError: "0033", - privacyNoticeNotFoundInConfiguration: "0034", - privacyNoticeNotFound: "0035", - privacyNoticeVersionIsNotTheLatest: "0036", + privacyNoticeNotFoundInConfiguration: "0033", + privacyNoticeNotFound: "0034", + privacyNoticeVersionIsNotTheLatest: "0035", }; export type ErrorCodes = keyof typeof errorCodes; @@ -237,18 +236,6 @@ export function missingSelfcareId(tenantId: string): ApiError { }); } -export function invalidRiskAnalysisContentType( - contentType: string, - purposeId: string, - versionId: string, - documentId: string -): ApiError { - return new ApiError({ - detail: `Invalid contentType ${contentType} for document ${documentId} from purpose ${purposeId} and version ${versionId}`, - code: "invalidRiskAnalysisContentType", - title: "Invalid Risk Analysis content type", - }); -} export function eserviceRiskNotFound( eserviceId: string, riskAnalysisId: string