From ee8a338ec4e927932a64d233364f06e2dd37592f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 2 Feb 2023 23:49:35 +0100 Subject: [PATCH 1/6] fix logger on contributionLinkResolver --- .../resolver/ContributionLinkResolver.test.ts | 72 ++++++++----------- .../resolver/ContributionLinkResolver.ts | 42 +++++------ 2 files changed, 46 insertions(+), 68 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 0cf27bf33..46296e009 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -246,6 +246,7 @@ describe('Contribution Links', () => { }) it('returns an error if missing startDate', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -270,6 +271,7 @@ describe('Contribution Links', () => { }) it('returns an error if missing endDate', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -292,6 +294,7 @@ describe('Contribution Links', () => { }) it('returns an error if endDate is before startDate', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -317,6 +320,7 @@ describe('Contribution Links', () => { }) it('returns an error if name is an empty string', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -327,16 +331,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('The name must be initialized!')], + errors: [new GraphQLError('The name must be initialized')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('The name must be initialized!') + expect(logger.error).toBeCalledWith('The name must be initialized') }) it('returns an error if name is shorter than 5 characters', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -347,22 +352,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [ - new GraphQLError( - `The value of 'name' with a length of 3 did not fulfill the requested bounderies min=5 and max=100`, - ), - ], + errors: [new GraphQLError('The value of name is too short')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - `The value of 'name' with a length of 3 did not fulfill the requested bounderies min=5 and max=100`, - ) + expect(logger.error).toBeCalledWith('The value of name is too short', 3) }) it('returns an error if name is longer than 100 characters', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -373,22 +373,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [ - new GraphQLError( - `The value of 'name' with a length of 101 did not fulfill the requested bounderies min=5 and max=100`, - ), - ], + errors: [new GraphQLError('The value of name is too long')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - `The value of 'name' with a length of 101 did not fulfill the requested bounderies min=5 and max=100`, - ) + expect(logger.error).toBeCalledWith('The value of name is too long', 101) }) it('returns an error if memo is an empty string', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -399,16 +394,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('The memo must be initialized!')], + errors: [new GraphQLError('The memo must be initialized')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('The memo must be initialized!') + expect(logger.error).toBeCalledWith('The memo must be initialized') }) it('returns an error if memo is shorter than 5 characters', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -419,22 +415,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [ - new GraphQLError( - `The value of 'memo' with a length of 3 did not fulfill the requested bounderies min=5 and max=255`, - ), - ], + errors: [new GraphQLError('The value of memo is too short')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - `The value of 'memo' with a length of 3 did not fulfill the requested bounderies min=5 and max=255`, - ) + expect(logger.error).toBeCalledWith('The value of memo is too short', 3) }) it('returns an error if memo is longer than 255 characters', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -445,22 +436,17 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [ - new GraphQLError( - `The value of 'memo' with a length of 256 did not fulfill the requested bounderies min=5 and max=255`, - ), - ], + errors: [new GraphQLError('The value of memo is too long')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - `The value of 'memo' with a length of 256 did not fulfill the requested bounderies min=5 and max=255`, - ) + expect(logger.error).toBeCalledWith('The value of memo is too long', 256) }) it('returns an error if amount is not positive', async () => { + jest.clearAllMocks() await expect( mutate({ mutation: createContributionLink, @@ -471,15 +457,13 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('The amount=0 must be initialized with a positiv value!')], + errors: [new GraphQLError('The amount must be a positiv value')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith( - 'The amount=0 must be initialized with a positiv value!', - ) + expect(logger.error).toBeCalledWith('The amount must be a positiv value', new Decimal(0)) }) }) @@ -530,14 +514,14 @@ describe('Contribution Links', () => { }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('Contribution Link not found to given id.')], + errors: [new GraphQLError('Contribution Link not found')], }), ) }) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('Contribution Link not found to given id: -1') + expect(logger.error).toBeCalledWith('Contribution Link not found', -1) }) describe('valid id', () => { @@ -601,13 +585,13 @@ describe('Contribution Links', () => { mutate({ mutation: deleteContributionLink, variables: { id: -1 } }), ).resolves.toEqual( expect.objectContaining({ - errors: [new GraphQLError('Contribution Link not found to given id.')], + errors: [new GraphQLError('Contribution Link not found')], }), ) }) it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('Contribution Link not found to given id: -1') + expect(logger.error).toBeCalledWith('Contribution Link not found', -1) }) }) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 0a6bb971c..6a7a71391 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -20,6 +20,7 @@ import Paginated from '@arg/Paginated' // TODO: this is a strange construct import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver' +import LogError from '@/server/LogError' @Resolver() export class ContributionLinkResolver { @@ -39,35 +40,30 @@ export class ContributionLinkResolver { }: ContributionLinkArgs, ): Promise { isStartEndDateValid(validFrom, validTo) + // TODO: this should be enforced by the schema. if (!name) { - logger.error(`The name must be initialized!`) - throw new Error(`The name must be initialized!`) + throw new LogError('The name must be initialized') } - if ( - name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS || - name.length > CONTRIBUTIONLINK_NAME_MAX_CHARS - ) { - const msg = `The value of 'name' with a length of ${name.length} did not fulfill the requested bounderies min=${CONTRIBUTIONLINK_NAME_MIN_CHARS} and max=${CONTRIBUTIONLINK_NAME_MAX_CHARS}` - logger.error(`${msg}`) - throw new Error(`${msg}`) + if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) { + throw new LogError('The value of name is too short', name.length) } + if (name.length > CONTRIBUTIONLINK_NAME_MAX_CHARS) { + throw new LogError('The value of name is too long', name.length) + } + // TODO: this should be enforced by the schema. if (!memo) { - logger.error(`The memo must be initialized!`) - throw new Error(`The memo must be initialized!`) + throw new LogError('The memo must be initialized') } - if (memo.length < MEMO_MIN_CHARS || memo.length > MEMO_MAX_CHARS) { - const msg = `The value of 'memo' with a length of ${memo.length} did not fulfill the requested bounderies min=${MEMO_MIN_CHARS} and max=${MEMO_MAX_CHARS}` - logger.error(`${msg}`) - throw new Error(`${msg}`) + if (memo.length < MEMO_MIN_CHARS) { + throw new LogError('The value of memo is too short', memo.length) } - if (!amount) { - logger.error(`The amount must be initialized!`) - throw new Error('The amount must be initialized!') + if (memo.length > MEMO_MAX_CHARS) { + throw new LogError('The value of memo is too long', memo.length) } if (!new Decimal(amount).isPositive()) { - logger.error(`The amount=${amount} must be initialized with a positiv value!`) - throw new Error(`The amount=${amount} must be initialized with a positiv value!`) + throw new LogError('The amount must be a positiv value', amount) } + const dbContributionLink = new DbContributionLink() dbContributionLink.amount = amount dbContributionLink.name = name @@ -107,8 +103,7 @@ export class ContributionLinkResolver { async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { const contributionLink = await DbContributionLink.findOne(id) if (!contributionLink) { - logger.error(`Contribution Link not found to given id: ${id}`) - throw new Error('Contribution Link not found to given id.') + throw new LogError('Contribution Link not found', id) } await contributionLink.softRemove() logger.debug(`deleteContributionLink successful!`) @@ -134,8 +129,7 @@ export class ContributionLinkResolver { ): Promise { const dbContributionLink = await DbContributionLink.findOne(id) if (!dbContributionLink) { - logger.error(`Contribution Link not found to given id: ${id}`) - throw new Error('Contribution Link not found to given id.') + throw new LogError('Contribution Link not found', id) } dbContributionLink.amount = amount dbContributionLink.name = name From 5a78228af31269de4b6a9818cbf699689d6b427f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Feb 2023 00:16:53 +0100 Subject: [PATCH 2/6] remove EVENT_PROTOCOL_DISABLED from backend & bare_metal deployment --- backend/.env.dist | 3 --- backend/.env.template | 3 --- backend/src/config/index.ts | 7 +------ backend/src/event/EventProtocolEmitter.ts | 6 ------ deployment/bare_metal/.env.dist | 5 +---- 5 files changed, 2 insertions(+), 22 deletions(-) diff --git a/backend/.env.dist b/backend/.env.dist index ba5b89fa9..3e54b0566 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -55,9 +55,6 @@ EMAIL_CODE_REQUEST_TIME=10 # Webhook WEBHOOK_ELOPAGE_SECRET=secret -# EventProtocol -EVENT_PROTOCOL_DISABLED=false - # SET LOG LEVEL AS NEEDED IN YOUR .ENV # POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal # LOG_LEVEL=info diff --git a/backend/.env.template b/backend/.env.template index f73b87353..e75798325 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -54,9 +54,6 @@ EMAIL_CODE_REQUEST_TIME=$EMAIL_CODE_REQUEST_TIME # Webhook WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET -# EventProtocol -EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED - # Federation FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index d010b4ab0..63ea9c5b6 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -17,7 +17,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL || 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v14.2022-12-22', + EXPECTED: 'v15.2023-02-07', CURRENT: '', }, } @@ -99,11 +99,6 @@ const webhook = { WEBHOOK_ELOPAGE_SECRET: process.env.WEBHOOK_ELOPAGE_SECRET || 'secret', } -const eventProtocol = { - // global switch to enable writing of EventProtocol-Entries - EVENT_PROTOCOL_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === 'true' || false, -} - // This is needed by graphql-directive-auth process.env.APP_SECRET = server.JWT_SECRET diff --git a/backend/src/event/EventProtocolEmitter.ts b/backend/src/event/EventProtocolEmitter.ts index 9cde4939f..a87e8a256 100644 --- a/backend/src/event/EventProtocolEmitter.ts +++ b/backend/src/event/EventProtocolEmitter.ts @@ -1,14 +1,8 @@ import { Event } from '@/event/Event' import { backendLogger as logger } from '@/server/logger' import { EventProtocol } from '@entity/EventProtocol' -import CONFIG from '@/config' export const writeEvent = async (event: Event): Promise => { - if (CONFIG.EVENT_PROTOCOL_DISABLED) { - logger.info('EventProtocol is disabled', CONFIG.EVENT_PROTOCOL_DISABLED) - return null - } - logger.info('writeEvent', event) const dbEvent = new EventProtocol() dbEvent.type = event.type diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index e816c9236..9c9c7ac82 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -27,7 +27,7 @@ COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community" COMMUNITY_SUPPORT_MAIL=support@supportmail.com # backend -BACKEND_CONFIG_VERSION=v14.2022-12-22 +BACKEND_CONFIG_VERSION=v15.2023-02-07 JWT_EXPIRES_IN=10m GDT_API_URL=https://gdt.gradido.net @@ -56,9 +56,6 @@ EMAIL_CODE_REQUEST_TIME=10 WEBHOOK_ELOPAGE_SECRET=secret -# EventProtocol -EVENT_PROTOCOL_DISABLED=false - # Federation # if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen # on an hash created from this topic From 24ca1563b898c338b4870cc50489d7ed753c5f20 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Feb 2023 00:17:37 +0100 Subject: [PATCH 3/6] remove EVENT_PROTOCOL_DISABLED from dht-node --- dht-node/.env.dist | 3 --- dht-node/.env.template | 3 --- dht-node/src/config/index.ts | 7 +------ 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/dht-node/.env.dist b/dht-node/.env.dist index c1641ea98..09e25ccb6 100644 --- a/dht-node/.env.dist +++ b/dht-node/.env.dist @@ -8,9 +8,6 @@ DB_PASSWORD= DB_DATABASE=gradido_community TYPEORM_LOGGING_RELATIVE_PATH=typeorm.dht-node.log -# EventProtocol -EVENT_PROTOCOL_DISABLED=false - # SET LOG LEVEL AS NEEDED IN YOUR .ENV # POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal # LOG_LEVEL=info diff --git a/dht-node/.env.template b/dht-node/.env.template index eca7cb277..b31667fdb 100644 --- a/dht-node/.env.template +++ b/dht-node/.env.template @@ -8,9 +8,6 @@ DB_PASSWORD=$DB_PASSWORD DB_DATABASE=gradido_community TYPEORM_LOGGING_RELATIVE_PATH=$TYPEORM_LOGGING_RELATIVE_PATH -# EventProtocol -EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED - # Federation FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index 02cbb20e9..cb6fe7c77 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -9,7 +9,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL || 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v1.2023-01-01', + EXPECTED: 'v2.2023-02-07', CURRENT: '', }, } @@ -28,11 +28,6 @@ const database = { process.env.TYPEORM_LOGGING_RELATIVE_PATH || 'typeorm.dht-node.log', } -const eventProtocol = { - // global switch to enable writing of EventProtocol-Entries - EVENT_PROTOCOL_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === 'true' || false, -} - const federation = { FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || 'GRADIDO_HUB', FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, From 4d3ea26365ef873292207b4b10166abc969af850 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Feb 2023 00:17:49 +0100 Subject: [PATCH 4/6] remove comment on federation --- federation/src/config/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/federation/src/config/index.ts b/federation/src/config/index.ts index c2d81d2c8..588f52c60 100644 --- a/federation/src/config/index.ts +++ b/federation/src/config/index.ts @@ -52,10 +52,6 @@ const community = { process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.', } */ -// const eventProtocol = { -// global switch to enable writing of EventProtocol-Entries -// EVENT_PROTOCOL_DISABLED: process.env.EVENT_PROTOCOL_DISABLED === 'true' || false, -// } // This is needed by graphql-directive-auth // process.env.APP_SECRET = server.JWT_SECRET From 151f381d9405a03f4bdb196ccff61621f99404ee Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Feb 2023 00:29:07 +0100 Subject: [PATCH 5/6] fix config aggregation on dht-node & backend --- backend/src/config/index.ts | 1 - dht-node/src/config/index.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 63ea9c5b6..4cca9e0e2 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -134,7 +134,6 @@ const CONFIG = { ...email, ...loginServer, ...webhook, - ...eventProtocol, ...federation, } diff --git a/dht-node/src/config/index.ts b/dht-node/src/config/index.ts index cb6fe7c77..795925ee3 100644 --- a/dht-node/src/config/index.ts +++ b/dht-node/src/config/index.ts @@ -50,7 +50,6 @@ const CONFIG = { ...constants, ...server, ...database, - ...eventProtocol, ...federation, } From a04d4d39855b42200b201081d9fc4ffe027d1f03 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 Feb 2023 11:01:35 +0100 Subject: [PATCH 6/6] remove empty string check since we do a length check on memeo & name --- .../resolver/ContributionLinkResolver.test.ts | 42 ------------------- .../resolver/ContributionLinkResolver.ts | 8 ---- 2 files changed, 50 deletions(-) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts index 46296e009..49bca2c42 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.test.ts @@ -319,27 +319,6 @@ describe('Contribution Links', () => { ) }) - it('returns an error if name is an empty string', async () => { - jest.clearAllMocks() - await expect( - mutate({ - mutation: createContributionLink, - variables: { - ...variables, - name: '', - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('The name must be initialized')], - }), - ) - }) - - it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('The name must be initialized') - }) - it('returns an error if name is shorter than 5 characters', async () => { jest.clearAllMocks() await expect( @@ -382,27 +361,6 @@ describe('Contribution Links', () => { expect(logger.error).toBeCalledWith('The value of name is too long', 101) }) - it('returns an error if memo is an empty string', async () => { - jest.clearAllMocks() - await expect( - mutate({ - mutation: createContributionLink, - variables: { - ...variables, - memo: '', - }, - }), - ).resolves.toEqual( - expect.objectContaining({ - errors: [new GraphQLError('The memo must be initialized')], - }), - ) - }) - - it('logs the error thrown', () => { - expect(logger.error).toBeCalledWith('The memo must be initialized') - }) - it('returns an error if memo is shorter than 5 characters', async () => { jest.clearAllMocks() await expect( diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 6a7a71391..39f202848 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -40,20 +40,12 @@ export class ContributionLinkResolver { }: ContributionLinkArgs, ): Promise { isStartEndDateValid(validFrom, validTo) - // TODO: this should be enforced by the schema. - if (!name) { - throw new LogError('The name must be initialized') - } if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) { throw new LogError('The value of name is too short', name.length) } if (name.length > CONTRIBUTIONLINK_NAME_MAX_CHARS) { throw new LogError('The value of name is too long', name.length) } - // TODO: this should be enforced by the schema. - if (!memo) { - throw new LogError('The memo must be initialized') - } if (memo.length < MEMO_MIN_CHARS) { throw new LogError('The value of memo is too short', memo.length) }