Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMN-869: removed contentType' checks on download #1052

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions packages/backend-for-frontend/src/model/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const errorCodes = {
agreementNotFound: "0012",
eserviceDescriptorNotFound: "0013",
purposeDraftVersionNotFound: "0014",
invalidRiskAnalysisContentType: "0015",
dynamoReadingError: "0015",
missingInterface: "0016",
eserviceRiskNotFound: "0017",
noDescriptorInEservice: "0018",
Expand All @@ -35,15 +35,13 @@ export const errorCodes = {
invalidJwtClaim: "0026",
samlNotValid: "0027",
missingSelfcareId: "0028",
invalidContentType: "0029",
invalidZipStructure: "0029",
contractNotFound: "0030",
contractException: "0031",
notValidDescriptor: "0032",
dynamoReadingError: "0033",
privacyNoticeNotFoundInConfiguration: "0034",
privacyNoticeNotFound: "0035",
privacyNoticeVersionIsNotTheLatest: "0036",
invalidZipStructure: "0037",
privacyNoticeNotFoundInConfiguration: "0033",
privacyNoticeNotFound: "0034",
privacyNoticeVersionIsNotTheLatest: "0035",
};

export type ErrorCodes = keyof typeof errorCodes;
Expand Down Expand Up @@ -238,18 +236,6 @@ export function missingSelfcareId(tenantId: string): ApiError<ErrorCodes> {
});
}

export function invalidRiskAnalysisContentType(
contentType: string,
purposeId: string,
versionId: string,
documentId: string
): ApiError<ErrorCodes> {
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
Expand Down Expand Up @@ -359,18 +345,6 @@ export function contractException(agreementId: string): ApiError<ErrorCodes> {
});
}

export function invalidContentType(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove invalidRiskAnalysisContentType which is an error similar to this one, probably unused now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

contentType: string,
agreementId: string,
documentId: string
): ApiError<ErrorCodes> {
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<ErrorCodes> {
return new ApiError({
detail: `Invalid zip structure: ${description}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
activateAgreementErrorMapper,
emptyErrorMapper,
getAgreementByIdErrorMapper,
getAgreementConsumerDocumentErrorMapper,
getAgreementContractErrorMapper,
getAgreementsErrorMapper,
} from "../utilities/errorMappers.js";
Expand Down Expand Up @@ -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}`
);
Expand Down
13 changes: 0 additions & 13 deletions packages/backend-for-frontend/src/services/agreementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -197,8 +195,6 @@ export function agreementServiceBuilder(
headers,
});

assertContentMediaType(document.contentType, agreementId, documentId);

const documentBytes = await fileManager.get(
config.consumerDocumentsContainer,
document.path,
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions packages/backend-for-frontend/src/services/purposeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions packages/backend-for-frontend/src/utilities/errorMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ export const getAgreementContractErrorMapper = (
.with("contractNotFound", () => HTTP_STATUS_NOT_FOUND)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);

export const getAgreementConsumerDocumentErrorMapper = (
error: ApiError<ErrorCodes>
): number =>
match(error.code)
.with("invalidContentType", () => HTTP_STATUS_INTERNAL_SERVER_ERROR)
.otherwise(() => HTTP_STATUS_INTERNAL_SERVER_ERROR);

export const activateAgreementErrorMapper = (
error: ApiError<ErrorCodes>
): number =>
Expand Down
13 changes: 0 additions & 13 deletions packages/backend-for-frontend/src/utilities/mimeTypes.ts

This file was deleted.