From 97fb8848c742a2d3eb4f61ca6fa2a4ca734d1ff4 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Mon, 30 Sep 2024 10:45:41 +0200 Subject: [PATCH 01/14] Refactor --- .../catalog-platformstate-writer/src/utils.ts | 21 +++--- .../test/consumerServiceV2.test.ts | 11 +-- .../test/utils.test.ts | 2 +- .../test/utils.ts | 67 +++++++++++++++++++ 4 files changed, 85 insertions(+), 16 deletions(-) diff --git a/packages/catalog-platformstate-writer/src/utils.ts b/packages/catalog-platformstate-writer/src/utils.ts index 7ac11652cc..e01e9d572c 100644 --- a/packages/catalog-platformstate-writer/src/utils.ts +++ b/packages/catalog-platformstate-writer/src/utils.ts @@ -148,8 +148,9 @@ export const updateDescriptorStateInPlatformStatesEntry = async ( await dynamoDBClient.send(command); }; -export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( +export const updateDescriptorStateInTokenGenerationStatesTable = async ( eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, + descriptorState: ItemState, dynamoDBClient: DynamoDBClient ): Promise => { const runPaginatedQuery = async ( @@ -188,6 +189,12 @@ export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( ); } + await updateDescriptorStateEntriesInTokenGenerationStatesTable( + descriptorState, + dynamoDBClient, + tokenStateEntries.data + ); + if (!data.LastEvaluatedKey) { return tokenStateEntries.data; } else { @@ -210,17 +217,11 @@ export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( ); }; -export const updateDescriptorStateInTokenGenerationStatesTable = async ( - eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, +const updateDescriptorStateEntriesInTokenGenerationStatesTable = async ( descriptorState: ItemState, - dynamoDBClient: DynamoDBClient + dynamoDBClient: DynamoDBClient, + entriesToUpdate: TokenGenerationStatesClientPurposeEntry[] ): Promise => { - const entriesToUpdate = - await readTokenStateEntriesByEserviceIdAndDescriptorId( - eserviceId_descriptorId, - dynamoDBClient - ); - for (const entry of entriesToUpdate) { const input: UpdateItemInput = { ConditionExpression: "attribute_exists(GSIPK_eserviceId_descriptorId)", diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts index 46b6781fb3..445ff1c209 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts @@ -37,13 +37,14 @@ import { buildDynamoDBTables, deleteDynamoDBTables, } from "pagopa-interop-commons-test"; +import { readCatalogEntry, writeCatalogEntry } from "../src/utils.js"; +import { handleMessageV2 } from "../src/consumerServiceV2.js"; import { - readCatalogEntry, + config, readTokenStateEntriesByEserviceIdAndDescriptorId, - writeCatalogEntry, -} from "../src/utils.js"; -import { handleMessageV2 } from "../src/consumerServiceV2.js"; -import { config, sleep, writeTokenStateEntry } from "./utils.js"; + sleep, + writeTokenStateEntry, +} from "./utils.js"; describe("integration tests V2 events", async () => { if (!config) { diff --git a/packages/catalog-platformstate-writer/test/utils.test.ts b/packages/catalog-platformstate-writer/test/utils.test.ts index bc52274657..ee130264ec 100644 --- a/packages/catalog-platformstate-writer/test/utils.test.ts +++ b/packages/catalog-platformstate-writer/test/utils.test.ts @@ -33,7 +33,6 @@ import { deleteCatalogEntry, descriptorStateToItemState, readCatalogEntry, - readTokenStateEntriesByEserviceIdAndDescriptorId, updateDescriptorStateInPlatformStatesEntry, updateDescriptorStateInTokenGenerationStatesTable, writeCatalogEntry, @@ -41,6 +40,7 @@ import { import { config, readAllTokenStateItems, + readTokenStateEntriesByEserviceIdAndDescriptorId, writeTokenStateEntry, } from "./utils.js"; diff --git a/packages/catalog-platformstate-writer/test/utils.ts b/packages/catalog-platformstate-writer/test/utils.ts index 883c912bc6..90f4be0914 100644 --- a/packages/catalog-platformstate-writer/test/utils.ts +++ b/packages/catalog-platformstate-writer/test/utils.ts @@ -2,15 +2,20 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { fail } from "assert"; import { + AttributeValue, DynamoDBClient, PutItemCommand, PutItemInput, + QueryCommand, + QueryCommandOutput, + QueryInput, ScanCommand, ScanCommandOutput, ScanInput, } from "@aws-sdk/client-dynamodb"; import { genericInternalError, + GSIPKEServiceIdDescriptorId, TokenGenerationStatesClientPurposeEntry, } from "pagopa-interop-models"; import { inject, vi } from "vitest"; @@ -133,3 +138,65 @@ export const readAllTokenStateItems = async ( return tokenStateEntries.data; } }; + +export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( + eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, + dynamoDBClient: DynamoDBClient +): Promise => { + const runPaginatedQuery = async ( + eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, + dynamoDBClient: DynamoDBClient, + exclusiveStartKey?: Record + ): Promise => { + const input: QueryInput = { + TableName: config!.tokenGenerationReadModelTableNameTokenGeneration, + IndexName: "Descriptor", + KeyConditionExpression: `GSIPK_eserviceId_descriptorId = :gsiValue`, + ExpressionAttributeValues: { + ":gsiValue": { S: eserviceId_descriptorId }, + }, + ExclusiveStartKey: exclusiveStartKey, + }; + const command = new QueryCommand(input); + const data: QueryCommandOutput = await dynamoDBClient.send(command); + + if (!data.Items) { + throw genericInternalError( + `Unable to read token state entries: result ${JSON.stringify(data)} ` + ); + } else { + const unmarshalledItems = data.Items.map((item) => unmarshall(item)); + + const tokenStateEntries = z + .array(TokenGenerationStatesClientPurposeEntry) + .safeParse(unmarshalledItems); + + if (!tokenStateEntries.success) { + throw genericInternalError( + `Unable to parse token state entry item: result ${JSON.stringify( + tokenStateEntries + )} - data ${JSON.stringify(data)} ` + ); + } + + if (!data.LastEvaluatedKey) { + return tokenStateEntries.data; + } else { + return [ + ...tokenStateEntries.data, + ...(await runPaginatedQuery( + eserviceId_descriptorId, + dynamoDBClient, + data.LastEvaluatedKey + )), + ]; + } + } + }; + + return await runPaginatedQuery( + eserviceId_descriptorId, + dynamoDBClient, + undefined + ); +}; From 0cfd319794a599734950eaf49878246abfd183cc Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 09:46:39 +0200 Subject: [PATCH 02/14] Fix --- .../test/consumerServiceV1.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts index a4985bdba0..a2382a500a 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts @@ -35,12 +35,13 @@ import { } from "pagopa-interop-commons-test"; import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { handleMessageV1 } from "../src/consumerServiceV1.js"; +import { readCatalogEntry, writeCatalogEntry } from "../src/utils.js"; import { - readCatalogEntry, + config, readTokenStateEntriesByEserviceIdAndDescriptorId, - writeCatalogEntry, -} from "../src/utils.js"; -import { config, sleep, writeTokenStateEntry } from "./utils.js"; + sleep, + writeTokenStateEntry, +} from "./utils.js"; describe("V1 events", async () => { if (!config) { From 4e3b3383d68609cf99c6b62dfcc3e63b1478d7f7 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 10:22:46 +0200 Subject: [PATCH 03/14] Remove env vars --- packages/catalog-platformstate-writer/.env | 4 ---- packages/catalog-platformstate-writer/aws.config.local | 5 +++++ packages/catalog-platformstate-writer/src/index.ts | 9 +-------- .../src/config/tokenGenerationReadmodelDbConfig.ts | 4 ---- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/catalog-platformstate-writer/.env b/packages/catalog-platformstate-writer/.env index 1c5ad22067..8cf2111be7 100644 --- a/packages/catalog-platformstate-writer/.env +++ b/packages/catalog-platformstate-writer/.env @@ -6,11 +6,7 @@ KAFKA_BROKERS="localhost:9092" KAFKA_DISABLE_AWS_IAM_AUTH="true" CATALOG_TOPIC="event-store.catalog.events" AWS_CONFIG_FILE=aws.config.local -TOKEN_GENERATION_READMODEL_HOST="localhost" -TOKEN_GENERATION_READMODEL_PORT=8085 TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM="platform-states" TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION="token-generation-states" AWS_REGION="eu-south-1" -AWS_ACCESS_KEY_ID="key" -AWS_SECRET_ACCESS_KEY="secret" diff --git a/packages/catalog-platformstate-writer/aws.config.local b/packages/catalog-platformstate-writer/aws.config.local index 811d9c951e..f3016f81d6 100644 --- a/packages/catalog-platformstate-writer/aws.config.local +++ b/packages/catalog-platformstate-writer/aws.config.local @@ -2,3 +2,8 @@ aws_access_key_id=key aws_secret_access_key=secret region=eu-south-1 +services=local + +[services local] +dynamodb= + endpoint_url=http://localhost:8085 diff --git a/packages/catalog-platformstate-writer/src/index.ts b/packages/catalog-platformstate-writer/src/index.ts index a9875fa099..8ac4fff55e 100644 --- a/packages/catalog-platformstate-writer/src/index.ts +++ b/packages/catalog-platformstate-writer/src/index.ts @@ -8,14 +8,7 @@ import { handleMessageV1 } from "./consumerServiceV1.js"; import { handleMessageV2 } from "./consumerServiceV2.js"; import { config } from "./config/config.js"; -const dynamoDBClient = new DynamoDBClient({ - credentials: { - accessKeyId: config.awsAccessKeyId, - secretAccessKey: config.awsSecretAccessKey, - }, - region: config.awsRegion, - endpoint: `http://${config.tokenGenerationReadModelDbHost}:${config.tokenGenerationReadModelDbPort}`, -}); +const dynamoDBClient = new DynamoDBClient(); async function processMessage({ message, diff --git a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts index 7c30841aef..6ad8699555 100644 --- a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts +++ b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts @@ -6,8 +6,6 @@ export const TokenGenerationReadModelDbConfig = z TOKEN_GENERATION_READMODEL_PORT: z.coerce.number().min(1001), TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM: z.string(), TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION: z.string(), - AWS_ACCESS_KEY_ID: z.string(), - AWS_SECRET_ACCESS_KEY: z.string(), }) .transform((c) => ({ tokenGenerationReadModelDbHost: c.TOKEN_GENERATION_READMODEL_HOST, @@ -16,8 +14,6 @@ export const TokenGenerationReadModelDbConfig = z c.TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM, tokenGenerationReadModelTableNameTokenGeneration: c.TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION, - awsAccessKeyId: c.AWS_ACCESS_KEY_ID, - awsSecretAccessKey: c.AWS_SECRET_ACCESS_KEY, })); export type TokenGenerationReadModelDbConfig = z.infer< From 613598080bbd5d094be7e86c5e4d64c4b2bcd2a2 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 10:26:30 +0200 Subject: [PATCH 04/14] Fix --- .../commons/src/config/tokenGenerationReadmodelDbConfig.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts index 6ad8699555..0b75478e70 100644 --- a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts +++ b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts @@ -2,8 +2,8 @@ import { z } from "zod"; export const TokenGenerationReadModelDbConfig = z .object({ - TOKEN_GENERATION_READMODEL_HOST: z.string(), - TOKEN_GENERATION_READMODEL_PORT: z.coerce.number().min(1001), + TOKEN_GENERATION_READMODEL_HOST: z.string().optional(), + TOKEN_GENERATION_READMODEL_PORT: z.coerce.number().min(1001).optional(), TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM: z.string(), TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION: z.string(), }) From e6bbca3b9e4fd0269e269eda2e639c1f7018dd68 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 10:33:20 +0200 Subject: [PATCH 05/14] Fix --- packages/commons-test/src/setupTestContainersVitestGlobal.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/commons-test/src/setupTestContainersVitestGlobal.ts b/packages/commons-test/src/setupTestContainersVitestGlobal.ts index a31dd0619f..cb3d22e9ea 100644 --- a/packages/commons-test/src/setupTestContainersVitestGlobal.ts +++ b/packages/commons-test/src/setupTestContainersVitestGlobal.ts @@ -142,6 +142,8 @@ export function setupTestContainersVitestGlobal() { startedDynamoDbContainer = await dynamoDBContainer().start(); tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbPort = startedDynamoDbContainer.getMappedPort(TEST_DYNAMODB_PORT); + tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbHost = + startedDynamoDbContainer.getHost(); provide( "tokenGenerationReadModelConfig", From 6c3d1285682dbd11c2448444942f73d0a14199b6 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 10:33:56 +0200 Subject: [PATCH 06/14] Fix --- packages/commons-test/src/setupTestContainersVitestGlobal.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/commons-test/src/setupTestContainersVitestGlobal.ts b/packages/commons-test/src/setupTestContainersVitestGlobal.ts index a31dd0619f..cb3d22e9ea 100644 --- a/packages/commons-test/src/setupTestContainersVitestGlobal.ts +++ b/packages/commons-test/src/setupTestContainersVitestGlobal.ts @@ -142,6 +142,8 @@ export function setupTestContainersVitestGlobal() { startedDynamoDbContainer = await dynamoDBContainer().start(); tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbPort = startedDynamoDbContainer.getMappedPort(TEST_DYNAMODB_PORT); + tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbHost = + startedDynamoDbContainer.getHost(); provide( "tokenGenerationReadModelConfig", From f4e3ca040e7e32562d1170fefdd6200eb8609df8 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 10:41:27 +0200 Subject: [PATCH 07/14] Remove not needed params --- .../catalog-platformstate-writer/test/consumerServiceV2.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts index 445ff1c209..836dcef64b 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts @@ -51,8 +51,6 @@ describe("integration tests V2 events", async () => { fail(); } const dynamoDBClient = new DynamoDBClient({ - credentials: { accessKeyId: "key", secretAccessKey: "secret" }, - region: "eu-south-1", endpoint: `http://${config.tokenGenerationReadModelDbHost}:${config.tokenGenerationReadModelDbPort}`, }); beforeEach(async () => { From 6b2643e8ff9298bfb1e4965346e3afea73c2bf6c Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 14:16:22 +0200 Subject: [PATCH 08/14] Rename container --- docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e72711f9f1..c0f4cda7c0 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -94,7 +94,7 @@ services: dynamodb-admin: image: "aaronshaf/dynamodb-admin" - container_name: dynamodb-admin + container_name: dynamodb-admin_token-generation-readmodel depends_on: - token-generation-readmodel restart: always From 573ed397227d855e2ff3e579958d38b4352481ea Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 15:26:32 +0200 Subject: [PATCH 09/14] Refactor --- .../test/consumerServiceV2.test.ts | 9 +- .../test/utils.test.ts | 10 +- .../test/utils.ts | 189 ------------------ packages/commons-test/package.json | 1 + packages/commons-test/src/index.ts | 1 + .../src/tokenGenerationReadmodelUtils.ts | 183 +++++++++++++++++ pnpm-lock.yaml | 137 +++++++------ 7 files changed, 267 insertions(+), 263 deletions(-) create mode 100644 packages/commons-test/src/tokenGenerationReadmodelUtils.ts diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts index 836dcef64b..2de1deed54 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts @@ -36,15 +36,12 @@ import { getMockTokenStatesClientPurposeEntry, buildDynamoDBTables, deleteDynamoDBTables, + readTokenStateEntriesByEserviceIdAndDescriptorId, + writeTokenStateEntry, } from "pagopa-interop-commons-test"; import { readCatalogEntry, writeCatalogEntry } from "../src/utils.js"; import { handleMessageV2 } from "../src/consumerServiceV2.js"; -import { - config, - readTokenStateEntriesByEserviceIdAndDescriptorId, - sleep, - writeTokenStateEntry, -} from "./utils.js"; +import { config, sleep } from "./utils.js"; describe("integration tests V2 events", async () => { if (!config) { diff --git a/packages/catalog-platformstate-writer/test/utils.test.ts b/packages/catalog-platformstate-writer/test/utils.test.ts index ee130264ec..9491d34e17 100644 --- a/packages/catalog-platformstate-writer/test/utils.test.ts +++ b/packages/catalog-platformstate-writer/test/utils.test.ts @@ -28,6 +28,9 @@ import { getMockTokenStatesClientPurposeEntry, buildDynamoDBTables, deleteDynamoDBTables, + readTokenStateEntriesByEserviceIdAndDescriptorId, + readAllTokenStateItems, + writeTokenStateEntry, } from "pagopa-interop-commons-test"; import { deleteCatalogEntry, @@ -37,12 +40,7 @@ import { updateDescriptorStateInTokenGenerationStatesTable, writeCatalogEntry, } from "../src/utils.js"; -import { - config, - readAllTokenStateItems, - readTokenStateEntriesByEserviceIdAndDescriptorId, - writeTokenStateEntry, -} from "./utils.js"; +import { config } from "./utils.js"; describe("utils tests", async () => { if (!config) { diff --git a/packages/catalog-platformstate-writer/test/utils.ts b/packages/catalog-platformstate-writer/test/utils.ts index 90f4be0914..3c4071f28a 100644 --- a/packages/catalog-platformstate-writer/test/utils.ts +++ b/packages/catalog-platformstate-writer/test/utils.ts @@ -1,26 +1,6 @@ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { fail } from "assert"; -import { - AttributeValue, - DynamoDBClient, - PutItemCommand, - PutItemInput, - QueryCommand, - QueryCommandOutput, - QueryInput, - ScanCommand, - ScanCommandOutput, - ScanInput, -} from "@aws-sdk/client-dynamodb"; -import { - genericInternalError, - GSIPKEServiceIdDescriptorId, - TokenGenerationStatesClientPurposeEntry, -} from "pagopa-interop-models"; import { inject, vi } from "vitest"; -import { unmarshall } from "@aws-sdk/util-dynamodb"; -import { z } from "zod"; export const config = inject("tokenGenerationReadModelConfig"); @@ -31,172 +11,3 @@ export const sleep = (ms: number, mockDate = new Date()): Promise => vi.useFakeTimers(); vi.setSystemTime(mockDate); }); - -export const writeTokenStateEntry = async ( - tokenStateEntry: TokenGenerationStatesClientPurposeEntry, - dynamoDBClient: DynamoDBClient -): Promise => { - if (!config) { - fail(); - } - const input: PutItemInput = { - ConditionExpression: "attribute_not_exists(PK)", - Item: { - PK: { - S: tokenStateEntry.PK, - }, - descriptorState: { - S: tokenStateEntry.descriptorState!, - }, - descriptorAudience: { - L: tokenStateEntry.descriptorAudience - ? tokenStateEntry.descriptorAudience.map((item) => ({ - S: item, - })) - : [], - }, - updatedAt: { - S: tokenStateEntry.updatedAt, - }, - consumerId: { - S: tokenStateEntry.consumerId, - }, - agreementId: { - S: tokenStateEntry.agreementId!, - }, - purposeVersionId: { - S: tokenStateEntry.purposeVersionId!, - }, - GSIPK_consumerId_eserviceId: { - S: tokenStateEntry.GSIPK_consumerId_eserviceId!, - }, - clientKind: { - S: tokenStateEntry.clientKind, - }, - publicKey: { - S: tokenStateEntry.publicKey, - }, - GSIPK_clientId: { - S: tokenStateEntry.GSIPK_clientId, - }, - GSIPK_kid: { - S: tokenStateEntry.GSIPK_kid, - }, - GSIPK_clientId_purposeId: { - S: tokenStateEntry.GSIPK_clientId_purposeId!, - }, - agreementState: { - S: tokenStateEntry.agreementState!, - }, - GSIPK_eserviceId_descriptorId: { - S: tokenStateEntry.GSIPK_eserviceId_descriptorId!, - }, - GSIPK_purposeId: { - S: tokenStateEntry.GSIPK_purposeId!, - }, - purposeState: { - S: tokenStateEntry.purposeState!, - }, - }, - TableName: config.tokenGenerationReadModelTableNameTokenGeneration, - }; - const command = new PutItemCommand(input); - await dynamoDBClient.send(command); -}; - -export const readAllTokenStateItems = async ( - dynamoDBClient: DynamoDBClient -): Promise => { - if (!config) { - fail(); - } - - const readInput: ScanInput = { - TableName: config.tokenGenerationReadModelTableNameTokenGeneration, - }; - const commandQuery = new ScanCommand(readInput); - const data: ScanCommandOutput = await dynamoDBClient.send(commandQuery); - - if (!data.Items) { - throw genericInternalError( - `Unable to read token state entries: result ${JSON.stringify(data)} ` - ); - } else { - const unmarshalledItems = data.Items.map((item) => unmarshall(item)); - - const tokenStateEntries = z - .array(TokenGenerationStatesClientPurposeEntry) - .safeParse(unmarshalledItems); - - if (!tokenStateEntries.success) { - throw genericInternalError( - `Unable to parse token state entry item: result ${JSON.stringify( - tokenStateEntries - )} - data ${JSON.stringify(data)} ` - ); - } - return tokenStateEntries.data; - } -}; - -export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( - eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, - dynamoDBClient: DynamoDBClient -): Promise => { - const runPaginatedQuery = async ( - eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, - dynamoDBClient: DynamoDBClient, - exclusiveStartKey?: Record - ): Promise => { - const input: QueryInput = { - TableName: config!.tokenGenerationReadModelTableNameTokenGeneration, - IndexName: "Descriptor", - KeyConditionExpression: `GSIPK_eserviceId_descriptorId = :gsiValue`, - ExpressionAttributeValues: { - ":gsiValue": { S: eserviceId_descriptorId }, - }, - ExclusiveStartKey: exclusiveStartKey, - }; - const command = new QueryCommand(input); - const data: QueryCommandOutput = await dynamoDBClient.send(command); - - if (!data.Items) { - throw genericInternalError( - `Unable to read token state entries: result ${JSON.stringify(data)} ` - ); - } else { - const unmarshalledItems = data.Items.map((item) => unmarshall(item)); - - const tokenStateEntries = z - .array(TokenGenerationStatesClientPurposeEntry) - .safeParse(unmarshalledItems); - - if (!tokenStateEntries.success) { - throw genericInternalError( - `Unable to parse token state entry item: result ${JSON.stringify( - tokenStateEntries - )} - data ${JSON.stringify(data)} ` - ); - } - - if (!data.LastEvaluatedKey) { - return tokenStateEntries.data; - } else { - return [ - ...tokenStateEntries.data, - ...(await runPaginatedQuery( - eserviceId_descriptorId, - dynamoDBClient, - data.LastEvaluatedKey - )), - ]; - } - } - }; - - return await runPaginatedQuery( - eserviceId_descriptorId, - dynamoDBClient, - undefined - ); -}; diff --git a/packages/commons-test/package.json b/packages/commons-test/package.json index 08b3557bb3..dde6a915e0 100644 --- a/packages/commons-test/package.json +++ b/packages/commons-test/package.json @@ -21,6 +21,7 @@ "@anatine/zod-mock": "3.13.4", "@aws-sdk/client-dynamodb": "3.637.0", "@aws-sdk/client-sesv2": "3.620.1", + "@aws-sdk/util-dynamodb": "3.658.1", "@pagopa/eslint-config": "3.0.0", "@protobuf-ts/runtime": "2.9.4", "@testcontainers/postgresql": "10.9.0", diff --git a/packages/commons-test/src/index.ts b/packages/commons-test/src/index.ts index 1ad03def43..332cfc56c9 100644 --- a/packages/commons-test/src/index.ts +++ b/packages/commons-test/src/index.ts @@ -7,3 +7,4 @@ export * from "./setupTestContainersVitest.js"; export * from "./setupTestContainersVitestGlobal.js"; export * from "./protobufConvertersToV1/catalogProtobufConverterToV1.js"; export * from "./setupDynamoDBtables.js"; +export * from "./tokenGenerationReadmodelUtils.js"; diff --git a/packages/commons-test/src/tokenGenerationReadmodelUtils.ts b/packages/commons-test/src/tokenGenerationReadmodelUtils.ts new file mode 100644 index 0000000000..4a27dcd8c1 --- /dev/null +++ b/packages/commons-test/src/tokenGenerationReadmodelUtils.ts @@ -0,0 +1,183 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { + AttributeValue, + DynamoDBClient, + PutItemCommand, + PutItemInput, + QueryCommand, + QueryCommandOutput, + QueryInput, + ScanCommand, + ScanCommandOutput, + ScanInput, +} from "@aws-sdk/client-dynamodb"; +import { + genericInternalError, + GSIPKEServiceIdDescriptorId, + TokenGenerationStatesClientPurposeEntry, +} from "pagopa-interop-models"; +import { unmarshall } from "@aws-sdk/util-dynamodb"; +import { z } from "zod"; + +export const writeTokenStateEntry = async ( + tokenStateEntry: TokenGenerationStatesClientPurposeEntry, + dynamoDBClient: DynamoDBClient +): Promise => { + const input: PutItemInput = { + ConditionExpression: "attribute_not_exists(PK)", + Item: { + PK: { + S: tokenStateEntry.PK, + }, + descriptorState: { + S: tokenStateEntry.descriptorState!, + }, + descriptorAudience: { + L: tokenStateEntry.descriptorAudience + ? tokenStateEntry.descriptorAudience.map((item) => ({ + S: item, + })) + : [], + }, + updatedAt: { + S: tokenStateEntry.updatedAt, + }, + consumerId: { + S: tokenStateEntry.consumerId, + }, + agreementId: { + S: tokenStateEntry.agreementId!, + }, + purposeVersionId: { + S: tokenStateEntry.purposeVersionId!, + }, + GSIPK_consumerId_eserviceId: { + S: tokenStateEntry.GSIPK_consumerId_eserviceId!, + }, + clientKind: { + S: tokenStateEntry.clientKind, + }, + publicKey: { + S: tokenStateEntry.publicKey, + }, + GSIPK_clientId: { + S: tokenStateEntry.GSIPK_clientId, + }, + GSIPK_kid: { + S: tokenStateEntry.GSIPK_kid, + }, + GSIPK_clientId_purposeId: { + S: tokenStateEntry.GSIPK_clientId_purposeId!, + }, + agreementState: { + S: tokenStateEntry.agreementState!, + }, + GSIPK_eserviceId_descriptorId: { + S: tokenStateEntry.GSIPK_eserviceId_descriptorId!, + }, + GSIPK_purposeId: { + S: tokenStateEntry.GSIPK_purposeId!, + }, + purposeState: { + S: tokenStateEntry.purposeState!, + }, + }, + TableName: "token-generation-states", + }; + const command = new PutItemCommand(input); + await dynamoDBClient.send(command); +}; + +export const readAllTokenStateItems = async ( + dynamoDBClient: DynamoDBClient +): Promise => { + const readInput: ScanInput = { + TableName: "token-generation-states", + }; + const commandQuery = new ScanCommand(readInput); + const data: ScanCommandOutput = await dynamoDBClient.send(commandQuery); + + if (!data.Items) { + throw genericInternalError( + `Unable to read token state entries: result ${JSON.stringify(data)} ` + ); + } else { + const unmarshalledItems = data.Items.map((item) => unmarshall(item)); + + const tokenStateEntries = z + .array(TokenGenerationStatesClientPurposeEntry) + .safeParse(unmarshalledItems); + + if (!tokenStateEntries.success) { + throw genericInternalError( + `Unable to parse token state entry item: result ${JSON.stringify( + tokenStateEntries + )} - data ${JSON.stringify(data)} ` + ); + } + return tokenStateEntries.data; + } +}; + +export const readTokenStateEntriesByEserviceIdAndDescriptorId = async ( + eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, + dynamoDBClient: DynamoDBClient +): Promise => { + const runPaginatedQuery = async ( + eserviceId_descriptorId: GSIPKEServiceIdDescriptorId, + dynamoDBClient: DynamoDBClient, + exclusiveStartKey?: Record + ): Promise => { + const input: QueryInput = { + TableName: "token-generation-states", + IndexName: "Descriptor", + KeyConditionExpression: `GSIPK_eserviceId_descriptorId = :gsiValue`, + ExpressionAttributeValues: { + ":gsiValue": { S: eserviceId_descriptorId }, + }, + ExclusiveStartKey: exclusiveStartKey, + }; + const command = new QueryCommand(input); + const data: QueryCommandOutput = await dynamoDBClient.send(command); + + if (!data.Items) { + throw genericInternalError( + `Unable to read token state entries: result ${JSON.stringify(data)} ` + ); + } else { + const unmarshalledItems = data.Items.map((item) => unmarshall(item)); + + const tokenStateEntries = z + .array(TokenGenerationStatesClientPurposeEntry) + .safeParse(unmarshalledItems); + + if (!tokenStateEntries.success) { + throw genericInternalError( + `Unable to parse token state entry item: result ${JSON.stringify( + tokenStateEntries + )} - data ${JSON.stringify(data)} ` + ); + } + + if (!data.LastEvaluatedKey) { + return tokenStateEntries.data; + } else { + return [ + ...tokenStateEntries.data, + ...(await runPaginatedQuery( + eserviceId_descriptorId, + dynamoDBClient, + data.LastEvaluatedKey + )), + ]; + } + } + }; + + return await runPaginatedQuery( + eserviceId_descriptorId, + dynamoDBClient, + undefined + ); +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 535025a0a0..5f405fecef 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1292,6 +1292,9 @@ importers: '@aws-sdk/client-sesv2': specifier: 3.620.1 version: 3.620.1 + '@aws-sdk/util-dynamodb': + specifier: 3.658.1 + version: 3.658.1(@aws-sdk/client-dynamodb@3.637.0) '@pagopa/eslint-config': specifier: 3.0.0 version: 3.0.0(typescript@5.4.5) @@ -2839,10 +2842,10 @@ packages: dependencies: '@aws-crypto/sha256-browser': 5.2.0 '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sso-oidc': 3.620.1(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/client-sso-oidc': 3.620.1(@aws-sdk/client-sts@3.620.1) '@aws-sdk/client-sts': 3.620.1 '@aws-sdk/core': 3.620.1 - '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1) '@aws-sdk/middleware-host-header': 3.620.0 '@aws-sdk/middleware-logger': 3.609.0 '@aws-sdk/middleware-recursion-detection': 3.620.0 @@ -3029,6 +3032,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sso-oidc@3.620.1(@aws-sdk/client-sts@3.620.1): resolution: {integrity: sha512-gm69ttbkr7Kbg/Zzr3SczyLWkLgmK3bEZtkvbM/40ZW5ItYhDzJE48Ovs2lyA64h2YsOftDqqwcbJirAAdTgSg==} @@ -3040,56 +3044,7 @@ packages: '@aws-crypto/sha256-js': 5.2.0 '@aws-sdk/client-sts': 3.620.1 '@aws-sdk/core': 3.620.1 - '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0) - '@aws-sdk/middleware-host-header': 3.620.0 - '@aws-sdk/middleware-logger': 3.609.0 - '@aws-sdk/middleware-recursion-detection': 3.620.0 - '@aws-sdk/middleware-user-agent': 3.620.0 - '@aws-sdk/region-config-resolver': 3.614.0 - '@aws-sdk/types': 3.609.0 - '@aws-sdk/util-endpoints': 3.614.0 - '@aws-sdk/util-user-agent-browser': 3.609.0 - '@aws-sdk/util-user-agent-node': 3.614.0 - '@smithy/config-resolver': 3.0.5 - '@smithy/core': 2.4.0 - '@smithy/fetch-http-handler': 3.2.4 - '@smithy/hash-node': 3.0.3 - '@smithy/invalid-dependency': 3.0.3 - '@smithy/middleware-content-length': 3.0.5 - '@smithy/middleware-endpoint': 3.1.0 - '@smithy/middleware-retry': 3.0.15 - '@smithy/middleware-serde': 3.0.3 - '@smithy/middleware-stack': 3.0.3 - '@smithy/node-config-provider': 3.1.4 - '@smithy/node-http-handler': 3.1.4 - '@smithy/protocol-http': 4.1.0 - '@smithy/smithy-client': 3.2.0 - '@smithy/types': 3.3.0 - '@smithy/url-parser': 3.0.3 - '@smithy/util-base64': 3.0.0 - '@smithy/util-body-length-browser': 3.0.0 - '@smithy/util-body-length-node': 3.0.0 - '@smithy/util-defaults-mode-browser': 3.0.15 - '@smithy/util-defaults-mode-node': 3.0.15 - '@smithy/util-endpoints': 2.0.5 - '@smithy/util-middleware': 3.0.3 - '@smithy/util-retry': 3.0.3 - '@smithy/util-utf8': 3.0.0 - tslib: 2.6.3 - transitivePeerDependencies: - - aws-crt - - /@aws-sdk/client-sso-oidc@3.620.1(@aws-sdk/client-sts@3.645.0): - resolution: {integrity: sha512-gm69ttbkr7Kbg/Zzr3SczyLWkLgmK3bEZtkvbM/40ZW5ItYhDzJE48Ovs2lyA64h2YsOftDqqwcbJirAAdTgSg==} - engines: {node: '>=16.0.0'} - peerDependencies: - '@aws-sdk/client-sts': ^3.620.1 - dependencies: - '@aws-crypto/sha256-browser': 5.2.0 - '@aws-crypto/sha256-js': 5.2.0 - '@aws-sdk/client-sts': 3.645.0 - '@aws-sdk/core': 3.620.1 - '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1) '@aws-sdk/middleware-host-header': 3.620.0 '@aws-sdk/middleware-logger': 3.609.0 '@aws-sdk/middleware-recursion-detection': 3.620.0 @@ -3225,6 +3180,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sso-oidc@3.645.0(@aws-sdk/client-sts@3.645.0): resolution: {integrity: sha512-X9ULtdk3cO+1ysurEkJ1MSnu6U00qodXx+IVual+1jXX4RYY1WmQmfo7uDKf6FFkz7wW1DAqU+GJIBNQr0YH8A==} @@ -3274,6 +3230,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sso@3.598.0: resolution: {integrity: sha512-nOI5lqPYa+YZlrrzwAJywJSw3MKVjvu6Ge2fCqQUNYMfxFB0NAaDFnl0EPjXi+sEbtCuz/uWE77poHbqiZ+7Iw==} @@ -3365,6 +3322,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sso@3.620.1: resolution: {integrity: sha512-4Ox0BSs+atrAhLvjNHN2uiYvSTdpMv//IS4l4XRoQG0cJKIPLs3OU3PL5H0X1NfZehz9/8FTWl5Lv81uw4j1eA==} @@ -3500,6 +3458,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sts@3.600.0: resolution: {integrity: sha512-KQG97B7LvTtTiGmjlrG1LRAY8wUvCQzrmZVV5bjrJ/1oXAU7DITYwVbSJeX9NWg6hDuSk0VE3MFwIXS2SvfLIA==} @@ -3595,6 +3554,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/client-sts@3.620.1: resolution: {integrity: sha512-d+ECGFDg0IsDdmfKU2O0VeMYKZcmbfBaA9HkZnZ39wu1BlXGI73xJe8cfmzbobvu+Ly+bAfHdLCpgIY+pD4D7g==} @@ -3604,7 +3564,7 @@ packages: '@aws-crypto/sha256-js': 5.2.0 '@aws-sdk/client-sso-oidc': 3.620.1(@aws-sdk/client-sts@3.620.1) '@aws-sdk/core': 3.620.1 - '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-node': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1) '@aws-sdk/middleware-host-header': 3.620.0 '@aws-sdk/middleware-logger': 3.609.0 '@aws-sdk/middleware-recursion-detection': 3.620.0 @@ -3736,6 +3696,7 @@ packages: tslib: 2.6.3 transitivePeerDependencies: - aws-crt + dev: false /@aws-sdk/core@3.598.0: resolution: {integrity: sha512-HaSjt7puO5Cc7cOlrXFCW0rtA0BM9lvzjl56x0A20Pt+0wxXGeTOZZOkXQIepbrFkV2e/HYukuT9e99vXDm59g==} @@ -3761,6 +3722,7 @@ packages: '@smithy/types': 3.3.0 fast-xml-parser: 4.2.5 tslib: 2.6.3 + dev: false /@aws-sdk/core@3.620.1: resolution: {integrity: sha512-6Ejce93dDlDnovl6oYtxj3I/SJMOQoFdmmtM4+4W/cgMWH+l00T5aszVxDLjjPfu3Ryt7dNhrXaYeK2Ue1ZBmg==} @@ -3822,6 +3784,7 @@ packages: '@smithy/property-provider': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/credential-provider-env@3.620.1: resolution: {integrity: sha512-ExuILJ2qLW5ZO+rgkNRj0xiAipKT16Rk77buvPP8csR7kkCflT/gXTyzRe/uzIiETTxM7tr8xuO9MP/DQXqkfg==} @@ -3860,6 +3823,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-stream': 3.1.3 tslib: 2.6.3 + dev: false /@aws-sdk/credential-provider-http@3.620.0: resolution: {integrity: sha512-BI2BdrSKDmB/2ouB/NJR0PT0x/+5fmoF6XOE78hFBb4F5w/yynGgcJY936dF+oREfpME6ehjB2b0okGg78Scpw==} @@ -3933,6 +3897,7 @@ packages: transitivePeerDependencies: - '@aws-sdk/client-sso-oidc' - aws-crt + dev: false /@aws-sdk/credential-provider-ini@3.609.0(@aws-sdk/client-sso-oidc@3.645.0)(@aws-sdk/client-sts@3.609.0): resolution: {integrity: sha512-hwaBfXuBTv6/eAdEsDfGcteYUW6Km7lvvubbxEdxIuJNF3vswR7RMGIXaEC37hhPkTTgd3H0TONammhwZIfkog==} @@ -3957,18 +3922,18 @@ packages: - aws-crt dev: false - /@aws-sdk/credential-provider-ini@3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0): + /@aws-sdk/credential-provider-ini@3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1): resolution: {integrity: sha512-m9jwigMPRlRRhoPxCQZMOwQUd6imEJbksF6tSMYNae76DIvrCi4z2Jhp6RJ9Mij8cnewUZCAmvu2FlK9+n9M7A==} engines: {node: '>=16.0.0'} peerDependencies: '@aws-sdk/client-sts': ^3.620.1 dependencies: - '@aws-sdk/client-sts': 3.645.0 + '@aws-sdk/client-sts': 3.620.1 '@aws-sdk/credential-provider-env': 3.620.1 '@aws-sdk/credential-provider-http': 3.620.0 '@aws-sdk/credential-provider-process': 3.620.1 '@aws-sdk/credential-provider-sso': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1) - '@aws-sdk/credential-provider-web-identity': 3.609.0(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-web-identity': 3.609.0(@aws-sdk/client-sts@3.620.1) '@aws-sdk/types': 3.609.0 '@smithy/credential-provider-imds': 3.2.0 '@smithy/property-provider': 3.1.3 @@ -4022,6 +3987,7 @@ packages: transitivePeerDependencies: - '@aws-sdk/client-sso-oidc' - aws-crt + dev: false /@aws-sdk/credential-provider-ini@3.645.0(@aws-sdk/client-sso-oidc@3.645.0)(@aws-sdk/client-sts@3.645.0): resolution: {integrity: sha512-LlZW0qwUwNlTaAIDCNpLbPsyXvS42pRIwF92fgtCQedmdnpN3XRUC6hcwSYI7Xru3GGKp3RnceOvsdOaRJORsw==} @@ -4044,6 +4010,7 @@ packages: transitivePeerDependencies: - '@aws-sdk/client-sso-oidc' - aws-crt + dev: false /@aws-sdk/credential-provider-node@3.600.0(@aws-sdk/client-sso-oidc@3.600.0)(@aws-sdk/client-sts@3.600.0): resolution: {integrity: sha512-1pC7MPMYD45J7yFjA90SxpR0yaSvy+yZiq23aXhAPZLYgJBAxHLu0s0mDCk/piWGPh8+UGur5K0bVdx4B1D5hw==} @@ -4087,6 +4054,7 @@ packages: - '@aws-sdk/client-sso-oidc' - '@aws-sdk/client-sts' - aws-crt + dev: false /@aws-sdk/credential-provider-node@3.609.0(@aws-sdk/client-sso-oidc@3.645.0)(@aws-sdk/client-sts@3.609.0): resolution: {integrity: sha512-4J8/JRuqfxJDGD9jTHVCBxCvYt7/Vgj2Stlhj930mrjFPO/yRw8ilAAZxBWe0JHPX3QwepCmh4ErZe53F5ysxQ==} @@ -4110,16 +4078,16 @@ packages: - aws-crt dev: false - /@aws-sdk/credential-provider-node@3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0): + /@aws-sdk/credential-provider-node@3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1): resolution: {integrity: sha512-KaprIJW2azM+oTIHi7S1ayJ3oQqoFwpMBWFpZM1nvSzaPucrZIUmX2m4uVrMM4LfXsfUsgMkrme2rBI1fGAjCg==} engines: {node: '>=16.0.0'} dependencies: '@aws-sdk/credential-provider-env': 3.620.1 '@aws-sdk/credential-provider-http': 3.620.0 - '@aws-sdk/credential-provider-ini': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-ini': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1)(@aws-sdk/client-sts@3.620.1) '@aws-sdk/credential-provider-process': 3.620.1 '@aws-sdk/credential-provider-sso': 3.620.1(@aws-sdk/client-sso-oidc@3.620.1) - '@aws-sdk/credential-provider-web-identity': 3.609.0(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/credential-provider-web-identity': 3.609.0(@aws-sdk/client-sts@3.620.1) '@aws-sdk/types': 3.609.0 '@smithy/credential-provider-imds': 3.2.0 '@smithy/property-provider': 3.1.3 @@ -4172,6 +4140,7 @@ packages: - '@aws-sdk/client-sso-oidc' - '@aws-sdk/client-sts' - aws-crt + dev: false /@aws-sdk/credential-provider-node@3.645.0(@aws-sdk/client-sso-oidc@3.645.0)(@aws-sdk/client-sts@3.645.0): resolution: {integrity: sha512-eGFFuNvLeXjCJf5OCIuSEflxUowmK+bCS+lK4M8ofsYOEGAivdx7C0UPxNjHpvM8wKd8vpMl5phTeS9BWX5jMQ==} @@ -4193,6 +4162,7 @@ packages: - '@aws-sdk/client-sso-oidc' - '@aws-sdk/client-sts' - aws-crt + dev: false /@aws-sdk/credential-provider-process@3.598.0: resolution: {integrity: sha512-rM707XbLW8huMk722AgjVyxu2tMZee++fNA8TJVNgs1Ma02Wx6bBrfIvlyK0rCcIRb0WdQYP6fe3Xhiu4e8IBA==} @@ -4214,6 +4184,7 @@ packages: '@smithy/shared-ini-file-loader': 3.1.4 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/credential-provider-process@3.620.1: resolution: {integrity: sha512-hWqFMidqLAkaV9G460+1at6qa9vySbjQKKc04p59OT7lZ5cO5VH5S4aI05e+m4j364MBROjjk2ugNvfNf/8ILg==} @@ -4255,6 +4226,7 @@ packages: transitivePeerDependencies: - '@aws-sdk/client-sso-oidc' - aws-crt + dev: false /@aws-sdk/credential-provider-sso@3.609.0(@aws-sdk/client-sso-oidc@3.645.0): resolution: {integrity: sha512-oQPGDKMMIxjvTcm86g07RPYeC7mCNk+29dPpY15ZAPRpAF7F0tircsC3wT9fHzNaKShEyK5LuI5Kg/uxsdy+Iw==} @@ -4316,6 +4288,7 @@ packages: transitivePeerDependencies: - '@aws-sdk/client-sso-oidc' - aws-crt + dev: false /@aws-sdk/credential-provider-web-identity@3.598.0(@aws-sdk/client-sts@3.600.0): resolution: {integrity: sha512-GV5GdiMbz5Tz9JO4NJtRoFXjW0GPEujA0j+5J/B723rTN+REHthJu48HdBKouHGhdzkDWkkh1bu52V02Wprw8w==} @@ -4341,14 +4314,15 @@ packages: '@smithy/property-provider': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false - /@aws-sdk/credential-provider-web-identity@3.609.0(@aws-sdk/client-sts@3.645.0): + /@aws-sdk/credential-provider-web-identity@3.609.0(@aws-sdk/client-sts@3.620.1): resolution: {integrity: sha512-U+PG8NhlYYF45zbr1km3ROtBMYqyyj/oK8NRp++UHHeuavgrP+4wJ4wQnlEaKvJBjevfo3+dlIBcaeQ7NYejWg==} engines: {node: '>=16.0.0'} peerDependencies: '@aws-sdk/client-sts': ^3.609.0 dependencies: - '@aws-sdk/client-sts': 3.645.0 + '@aws-sdk/client-sts': 3.620.1 '@aws-sdk/types': 3.609.0 '@smithy/property-provider': 3.1.3 '@smithy/types': 3.3.0 @@ -4365,6 +4339,7 @@ packages: '@smithy/property-provider': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/credential-provider-web-identity@3.621.0(@aws-sdk/client-sts@3.637.0): resolution: {integrity: sha512-w7ASSyfNvcx7+bYGep3VBgC3K6vEdLmlpjT7nSIHxxQf+WSdvy+HynwJosrpZax0sK5q0D1Jpn/5q+r5lwwW6w==} @@ -4389,6 +4364,7 @@ packages: '@smithy/property-provider': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/credential-providers@3.609.0(@aws-sdk/client-sso-oidc@3.645.0): resolution: {integrity: sha512-bJKMY4QwRVderh8R2s9kukoZhuNZew/xzwPa9DRRFVOIsznsS0faAdmAAFrKb8e06YyQq6DiZP0BfFyVHAXE2A==} @@ -4500,6 +4476,7 @@ packages: '@smithy/protocol-http': 4.1.0 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/middleware-host-header@3.620.0: resolution: {integrity: sha512-VMtPEZwqYrII/oUkffYsNWY9PZ9xpNJpMgmyU0rlDQ25O1c0Hk3fJmZRe6pEkAJ0omD7kLrqGl1DUjQVxpd/Rg==} @@ -4554,6 +4531,7 @@ packages: '@smithy/protocol-http': 4.1.0 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/middleware-recursion-detection@3.620.0: resolution: {integrity: sha512-nh91S7aGK3e/o1ck64sA/CyoFw+gAYj2BDOnoNa6ouyCrVJED96ZXWbhye/fz9SgmNUZR2g7GdVpiLpMKZoI5w==} @@ -4650,6 +4628,7 @@ packages: '@smithy/protocol-http': 4.1.0 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/middleware-user-agent@3.620.0: resolution: {integrity: sha512-bvS6etn+KsuL32ubY5D3xNof1qkenpbJXf/ugGXbg0n98DvDFQ/F+SMLxHgbnER5dsKYchNnhmtI6/FC3HFu/A==} @@ -4680,6 +4659,7 @@ packages: '@smithy/protocol-http': 4.1.0 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/region-config-resolver@3.598.0: resolution: {integrity: sha512-oYXhmTokSav4ytmWleCr3rs/1nyvZW/S0tdi6X7u+dLNL5Jee+uMxWGzgOrWK6wrQOzucLVjS4E/wA11Kv2GTw==} @@ -4703,6 +4683,7 @@ packages: '@smithy/util-config-provider': 3.0.0 '@smithy/util-middleware': 3.0.3 tslib: 2.6.3 + dev: false /@aws-sdk/region-config-resolver@3.614.0: resolution: {integrity: sha512-vDCeMXvic/LU0KFIUjpC3RiSTIkkvESsEfbVHiHH0YINfl8HnEqR5rj+L8+phsCeVg2+LmYwYxd5NRz4PHxt5g==} @@ -4779,6 +4760,7 @@ packages: '@smithy/shared-ini-file-loader': 3.1.4 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/token-providers@3.609.0(@aws-sdk/client-sso-oidc@3.645.0): resolution: {integrity: sha512-WvhW/7XSf+H7YmtiIigQxfDVZVZI7mbKikQ09YpzN7FeN3TmYib1+0tB+EE9TbICkwssjiFc71FEBEh4K9grKQ==} @@ -4800,7 +4782,7 @@ packages: peerDependencies: '@aws-sdk/client-sso-oidc': ^3.614.0 dependencies: - '@aws-sdk/client-sso-oidc': 3.620.1(@aws-sdk/client-sts@3.645.0) + '@aws-sdk/client-sso-oidc': 3.620.1(@aws-sdk/client-sts@3.620.1) '@aws-sdk/types': 3.609.0 '@smithy/property-provider': 3.1.3 '@smithy/shared-ini-file-loader': 3.1.4 @@ -4832,6 +4814,7 @@ packages: '@smithy/shared-ini-file-loader': 3.1.4 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/types@3.598.0: resolution: {integrity: sha512-742uRl6z7u0LFmZwDrFP6r1wlZcgVPw+/TilluDJmCAR8BgRw3IR+743kUXKBGd8QZDRW2n6v/PYsi/AWCDDMQ==} @@ -4885,6 +4868,16 @@ packages: tslib: 2.6.3 dev: false + /@aws-sdk/util-dynamodb@3.658.1(@aws-sdk/client-dynamodb@3.637.0): + resolution: {integrity: sha512-lzlnis+35a2OhGZlVJvM3/30iIVoP2cIv5Bkw1F2nkM6Pr+1NOd3XvYhCY1Ud5zWtV6HUSptzessvUPqJTMfjQ==} + engines: {node: '>=16.0.0'} + peerDependencies: + '@aws-sdk/client-dynamodb': ^3.658.1 + dependencies: + '@aws-sdk/client-dynamodb': 3.637.0 + tslib: 2.6.3 + dev: true + /@aws-sdk/util-endpoints@3.598.0: resolution: {integrity: sha512-Qo9UoiVVZxcOEdiOMZg3xb1mzkTxrhd4qSlg5QQrfWPJVx/QOg+Iy0NtGxPtHtVZNHZxohYwDwV/tfsnDSE2gQ==} engines: {node: '>=16.0.0'} @@ -4903,6 +4896,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-endpoints': 2.0.5 tslib: 2.6.3 + dev: false /@aws-sdk/util-endpoints@3.614.0: resolution: {integrity: sha512-wK2cdrXHH4oz4IomV/yrGkftU9A+ITB6nFL+rxxyO78is2ifHJpFdV4aqk4LSkXYPi6CXWNru/Dqc7yiKXgJPw==} @@ -4930,6 +4924,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-endpoints': 2.0.5 tslib: 2.6.3 + dev: false /@aws-sdk/util-format-url@3.609.0: resolution: {integrity: sha512-fuk29BI/oLQlJ7pfm6iJ4gkEpHdavffAALZwXh9eaY1vQ0ip0aKfRTiNudPoJjyyahnz5yJ1HkmlcDitlzsOrQ==} @@ -4992,6 +4987,7 @@ packages: '@smithy/node-config-provider': 3.1.4 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@aws-sdk/util-user-agent-node@3.614.0: resolution: {integrity: sha512-15ElZT88peoHnq5TEoEtZwoXTXRxNrk60TZNdpl/TUBJ5oNJ9Dqb5Z4ryb8ofN6nm9aFf59GVAerFDz8iUoHBA==} @@ -5932,6 +5928,7 @@ packages: '@smithy/util-config-provider': 3.0.0 '@smithy/util-middleware': 3.0.3 tslib: 2.6.3 + dev: false /@smithy/config-resolver@3.0.5: resolution: {integrity: sha512-SkW5LxfkSI1bUC74OtfBbdz+grQXYiPYolyu8VfpLIjEoN/sHVBlLeGXMQ1vX4ejkgfv6sxVbQJ32yF2cl1veA==} @@ -5955,6 +5952,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-middleware': 3.0.3 tslib: 2.6.3 + dev: false /@smithy/core@2.4.0: resolution: {integrity: sha512-cHXq+FneIF/KJbt4q4pjN186+Jf4ZB0ZOqEaZMBhT79srEyGDDBV31NqBRBjazz8ppQ1bJbDJMY9ba5wKFV36w==} @@ -5980,6 +5978,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/url-parser': 3.0.3 tslib: 2.6.3 + dev: false /@smithy/credential-provider-imds@3.2.0: resolution: {integrity: sha512-0SCIzgd8LYZ9EJxUjLXBmEKSZR/P/w6l7Rz/pab9culE/RWuqelAKGJvn5qUOl8BgX8Yj5HWM50A5hiB/RzsgA==} @@ -6043,6 +6042,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-base64': 3.0.0 tslib: 2.6.3 + dev: false /@smithy/fetch-http-handler@3.2.4: resolution: {integrity: sha512-kBprh5Gs5h7ug4nBWZi1FZthdqSM+T7zMmsZxx0IBvWUn7dK3diz2SHn7Bs4dQGFDk8plDv375gzenDoNwrXjg==} @@ -6113,6 +6113,7 @@ packages: '@smithy/protocol-http': 4.0.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/middleware-content-length@3.0.5: resolution: {integrity: sha512-ILEzC2eyxx6ncej3zZSwMpB5RJ0zuqH7eMptxC4KN3f+v9bqT8ohssKbhNR78k/2tWW+KS5Spw+tbPF4Ejyqvw==} @@ -6133,6 +6134,7 @@ packages: '@smithy/url-parser': 3.0.3 '@smithy/util-middleware': 3.0.3 tslib: 2.6.3 + dev: false /@smithy/middleware-endpoint@3.1.0: resolution: {integrity: sha512-5y5aiKCEwg9TDPB4yFE7H6tYvGFf1OJHNczeY10/EFF8Ir8jZbNntQJxMWNfeQjC1mxPsaQ6mR9cvQbf+0YeMw==} @@ -6173,6 +6175,7 @@ packages: '@smithy/util-retry': 3.0.3 tslib: 2.6.3 uuid: 9.0.1 + dev: false /@smithy/middleware-serde@3.0.3: resolution: {integrity: sha512-puUbyJQBcg9eSErFXjKNiGILJGtiqmuuNKEYNYfUD57fUl4i9+mfmThtQhvFXU0hCVG0iEJhvQUipUf+/SsFdA==} @@ -6196,6 +6199,7 @@ packages: '@smithy/shared-ini-file-loader': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/node-config-provider@3.1.4: resolution: {integrity: sha512-YvnElQy8HR4vDcAjoy7Xkx9YT8xZP4cBXcbJSgm/kxmiQu08DwUwj8rkGnyoJTpfl/3xYHH+d8zE+eHqoDCSdQ==} @@ -6215,6 +6219,7 @@ packages: '@smithy/querystring-builder': 3.0.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/node-http-handler@3.1.4: resolution: {integrity: sha512-+UmxgixgOr/yLsUxcEKGH0fMNVteJFGkmRltYFHnBMlogyFdpzn2CwqWmxOrfJELhV34v0WSlaqG1UtE1uXlJg==} @@ -6239,6 +6244,7 @@ packages: dependencies: '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/protocol-http@4.1.0: resolution: {integrity: sha512-dPVoHYQ2wcHooGXg3LQisa1hH0e4y0pAddPMeeUPipI1tEOqL6A4N0/G7abeq+K8wrwSgjk4C0wnD1XZpJm5aA==} @@ -6274,6 +6280,7 @@ packages: dependencies: '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/shared-ini-file-loader@3.1.4: resolution: {integrity: sha512-qMxS4hBGB8FY2GQqshcRUy1K6k8aBWP5vwm8qKkCT3A9K2dawUwOIJfqh9Yste/Bl0J2lzosVyrXDj68kLcHXQ==} @@ -6306,6 +6313,7 @@ packages: '@smithy/util-uri-escape': 3.0.0 '@smithy/util-utf8': 3.0.0 tslib: 2.6.3 + dev: false /@smithy/signature-v4@4.1.0: resolution: {integrity: sha512-aRryp2XNZeRcOtuJoxjydO6QTaVhxx/vjaR+gx7ZjaFgrgPRyZ3HCTbfwqYj6ZWEBHkCSUfcaymKPURaByukag==} @@ -6330,6 +6338,7 @@ packages: '@smithy/types': 3.3.0 '@smithy/util-stream': 3.0.5 tslib: 2.6.3 + dev: false /@smithy/smithy-client@3.2.0: resolution: {integrity: sha512-pDbtxs8WOhJLJSeaF/eAbPgXg4VVYFlRcL/zoNYA5WbG3wBL06CHtBSg53ppkttDpAJ/hdiede+xApip1CwSLw==} @@ -6420,6 +6429,7 @@ packages: '@smithy/types': 3.3.0 bowser: 2.11.0 tslib: 2.6.3 + dev: false /@smithy/util-defaults-mode-node@3.0.15: resolution: {integrity: sha512-KSyAAx2q6d0t6f/S4XB2+3+6aQacm3aLMhs9aLMqn18uYGUepbdssfogW5JQZpc6lXNBnp0tEnR5e9CEKmEd7A==} @@ -6444,6 +6454,7 @@ packages: '@smithy/smithy-client': 3.2.0 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/util-endpoints@2.0.4: resolution: {integrity: sha512-ZAtNf+vXAsgzgRutDDiklU09ZzZiiV/nATyqde4Um4priTmasDH+eLpp3tspL0hS2dEootyFMhu1Y6Y+tzpWBQ==} @@ -6452,6 +6463,7 @@ packages: '@smithy/node-config-provider': 3.1.3 '@smithy/types': 3.3.0 tslib: 2.6.3 + dev: false /@smithy/util-endpoints@2.0.5: resolution: {integrity: sha512-ReQP0BWihIE68OAblC/WQmDD40Gx+QY1Ez8mTdFMXpmjfxSyz2fVQu3A4zXRfQU9sZXtewk3GmhfOHswvX+eNg==} @@ -6509,6 +6521,7 @@ packages: '@smithy/util-hex-encoding': 3.0.0 '@smithy/util-utf8': 3.0.0 tslib: 2.6.3 + dev: false /@smithy/util-stream@3.1.3: resolution: {integrity: sha512-FIv/bRhIlAxC0U7xM1BCnF2aDRPq0UaelqBHkM2lsCp26mcBbgI0tCVTv+jGdsQLUmAMybua/bjDsSu8RQHbmw==} From ba7233f3dd7ad69c532089b70ff1e0883eba8e58 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 15:30:37 +0200 Subject: [PATCH 10/14] Fix import --- .../test/consumerServiceV1.test.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts index a2382a500a..dc1d07ac05 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts @@ -32,17 +32,13 @@ import { getMockTokenStatesClientPurposeEntry, buildDynamoDBTables, deleteDynamoDBTables, + readTokenStateEntriesByEserviceIdAndDescriptorId, } from "pagopa-interop-commons-test"; import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; +import { writeTokenStateEntry } from "pagopa-interop-commons-test"; import { handleMessageV1 } from "../src/consumerServiceV1.js"; import { readCatalogEntry, writeCatalogEntry } from "../src/utils.js"; -import { - config, - readTokenStateEntriesByEserviceIdAndDescriptorId, - sleep, - writeTokenStateEntry, -} from "./utils.js"; - +import { config, sleep } from "./utils.js"; describe("V1 events", async () => { if (!config) { fail(); From f5376ce552fe1b9fe4f0149d2ecb3484676f2e13 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 15:55:36 +0200 Subject: [PATCH 11/14] Refactor --- .../test/consumerServiceV2.test.ts | 2 +- .../test/utils.test.ts | 6 +---- .../src/setupTestContainersVitestGlobal.ts | 26 ++++++++++++------- .../tokenGenerationReadmodelDbConfig.ts | 4 --- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts index 2de1deed54..104c5cf158 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV2.test.ts @@ -48,7 +48,7 @@ describe("integration tests V2 events", async () => { fail(); } const dynamoDBClient = new DynamoDBClient({ - endpoint: `http://${config.tokenGenerationReadModelDbHost}:${config.tokenGenerationReadModelDbPort}`, + endpoint: `http://localhost:${config.tokenGenerationReadModelDbPort}`, }); beforeEach(async () => { await buildDynamoDBTables(dynamoDBClient); diff --git a/packages/catalog-platformstate-writer/test/utils.test.ts b/packages/catalog-platformstate-writer/test/utils.test.ts index 9491d34e17..58c834f1c4 100644 --- a/packages/catalog-platformstate-writer/test/utils.test.ts +++ b/packages/catalog-platformstate-writer/test/utils.test.ts @@ -49,11 +49,7 @@ describe("utils tests", async () => { const dynamoDBClient = new DynamoDBClient({ credentials: { accessKeyId: "key", secretAccessKey: "secret" }, region: "eu-central-1", - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - endpoint: `http://${config.tokenGenerationReadModelDbHost}:${ - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - config.tokenGenerationReadModelDbPort - }`, + endpoint: `http://localhost:${config.tokenGenerationReadModelDbPort}`, }); beforeEach(async () => { await buildDynamoDBTables(dynamoDBClient); diff --git a/packages/commons-test/src/setupTestContainersVitestGlobal.ts b/packages/commons-test/src/setupTestContainersVitestGlobal.ts index cb3d22e9ea..ca34f76461 100644 --- a/packages/commons-test/src/setupTestContainersVitestGlobal.ts +++ b/packages/commons-test/src/setupTestContainersVitestGlobal.ts @@ -16,6 +16,7 @@ import { S3Config, TokenGenerationReadModelDbConfig, } from "pagopa-interop-commons"; +import { z } from "zod"; import { TEST_MINIO_PORT, TEST_MONGO_DB_PORT, @@ -33,10 +34,18 @@ import { } from "./containerTestUtils.js"; import { PecEmailManagerConfigTest } from "./testConfig.js"; +const EnhancedTokenGenerationReadModelDbConfig = + TokenGenerationReadModelDbConfig.and( + z.object({ tokenGenerationReadModelDbPort: z.number() }) + ); +type EnhancedTokenGenerationReadModelDbConfig = z.infer< + typeof EnhancedTokenGenerationReadModelDbConfig +>; + declare module "vitest" { export interface ProvidedContext { readModelConfig?: ReadModelDbConfig; - tokenGenerationReadModelConfig?: TokenGenerationReadModelDbConfig; + tokenGenerationReadModelConfig?: EnhancedTokenGenerationReadModelDbConfig; eventStoreConfig?: EventStoreConfig; fileManagerConfig?: FileManagerConfig & LoggerConfig & S3Config; redisRateLimiterConfig?: RedisRateLimiterConfig; @@ -140,15 +149,12 @@ export function setupTestContainersVitestGlobal() { // Setting up the DynamoDB container if the config is provided if (tokenGenerationReadModelConfig.success) { startedDynamoDbContainer = await dynamoDBContainer().start(); - tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbPort = - startedDynamoDbContainer.getMappedPort(TEST_DYNAMODB_PORT); - tokenGenerationReadModelConfig.data.tokenGenerationReadModelDbHost = - startedDynamoDbContainer.getHost(); - - provide( - "tokenGenerationReadModelConfig", - tokenGenerationReadModelConfig.data - ); + + provide("tokenGenerationReadModelConfig", { + ...tokenGenerationReadModelConfig.data, + tokenGenerationReadModelDbPort: + startedDynamoDbContainer.getMappedPort(TEST_DYNAMODB_PORT), + }); } if (redisRateLimiterConfig.success) { diff --git a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts index 0b75478e70..e9ee8c01f7 100644 --- a/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts +++ b/packages/commons/src/config/tokenGenerationReadmodelDbConfig.ts @@ -2,14 +2,10 @@ import { z } from "zod"; export const TokenGenerationReadModelDbConfig = z .object({ - TOKEN_GENERATION_READMODEL_HOST: z.string().optional(), - TOKEN_GENERATION_READMODEL_PORT: z.coerce.number().min(1001).optional(), TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM: z.string(), TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION: z.string(), }) .transform((c) => ({ - tokenGenerationReadModelDbHost: c.TOKEN_GENERATION_READMODEL_HOST, - tokenGenerationReadModelDbPort: c.TOKEN_GENERATION_READMODEL_PORT, tokenGenerationReadModelTableNamePlatform: c.TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM, tokenGenerationReadModelTableNameTokenGeneration: From 20785712a14e15fe344f15a68b0a2d83b9bd9a55 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 16:39:47 +0200 Subject: [PATCH 12/14] Update error --- packages/client-assertion-validation/src/errors.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/client-assertion-validation/src/errors.ts b/packages/client-assertion-validation/src/errors.ts index 5d1a04bf55..b75dee4aa1 100644 --- a/packages/client-assertion-validation/src/errors.ts +++ b/packages/client-assertion-validation/src/errors.ts @@ -102,9 +102,8 @@ export function invalidClientAssertionFormat(): ApiError { export function unexpectedClientAssertionPayload( message: string ): ApiError { - const extraDetails = message ? ` - ${message}` : ""; return new ApiError({ - detail: "Unexpected client assertion payload" + extraDetails, + detail: `Unexpected client assertion payload: ${message}`, code: "unexpectedClientAssertionPayload", title: "Invalid client assertion payload", }); From 497ce628611a7110247ee82b3259af6c2955136d Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 16:43:29 +0200 Subject: [PATCH 13/14] Improve test --- packages/client-assertion-validation/test/validation.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/client-assertion-validation/test/validation.test.ts b/packages/client-assertion-validation/test/validation.test.ts index 5a463d4d64..8dde5d388c 100644 --- a/packages/client-assertion-validation/test/validation.test.ts +++ b/packages/client-assertion-validation/test/validation.test.ts @@ -397,7 +397,9 @@ describe("validation test", () => { digest: undefined, }, }); - expect(() => verifyClientAssertion(jws, undefined)).not.toThrow(); + + const verifiedClientAssertion = verifyClientAssertion(jws, undefined); + expect(verifiedClientAssertion.data?.payload.digest).toBeUndefined(); }); it("digestClaimNotFound", () => { From 63533350b7a2d7615b4904a63eb9db3d5a569dc3 Mon Sep 17 00:00:00 2001 From: Roberto Taglioni Date: Tue, 1 Oct 2024 17:03:24 +0200 Subject: [PATCH 14/14] Fix --- .../test/consumerServiceV1.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts index dc1d07ac05..9ba36ba2d5 100644 --- a/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts +++ b/packages/catalog-platformstate-writer/test/consumerServiceV1.test.ts @@ -44,9 +44,7 @@ describe("V1 events", async () => { fail(); } const dynamoDBClient = new DynamoDBClient({ - credentials: { accessKeyId: "key", secretAccessKey: "secret" }, - region: "eu-central-1", - endpoint: `http://${config.tokenGenerationReadModelDbHost}:${config.tokenGenerationReadModelDbPort}`, + endpoint: `http://localhost:${config.tokenGenerationReadModelDbPort}`, }); beforeEach(async () => { await buildDynamoDBTables(dynamoDBClient);