From f2b755feb7ffee425a99a3a2af4f1d026cdcfc9c Mon Sep 17 00:00:00 2001 From: Claus-Peter Huebner Date: Thu, 26 Oct 2023 22:41:06 +0200 Subject: [PATCH] adapt existing tests --- .../src/federation/authenticateCommunities.ts | 7 ----- .../federation/validateCommunities.test.ts | 29 ++++++++++++++----- backend/src/federation/validateCommunities.ts | 8 ++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/backend/src/federation/authenticateCommunities.ts b/backend/src/federation/authenticateCommunities.ts index 88abc62f8..30831fc4a 100644 --- a/backend/src/federation/authenticateCommunities.ts +++ b/backend/src/federation/authenticateCommunities.ts @@ -47,13 +47,6 @@ export async function startCommunityAuthentication( homeCom.publicKey.toString('hex'), args.url, ) - const pubKeyBuf = Buffer.from(args.publicKey, 'hex') - logger.debug(`Authentication: url=`, args.url) - logger.debug(`Authentication: homeCom.PublicKey=`, homeCom.publicKey) - logger.debug(`Authentication: pubKeyBuf=`, pubKeyBuf) - logger.debug(`Authentication: pubKeyBufString=`, pubKeyBuf.toString('hex')) - logger.debug(`Authentication: publicKey=`, args.publicKey) - if (await client.openConnection(args)) { logger.info(`Authentication: successful initiated at community:`, foreignFedCom.endPoint) } else { diff --git a/backend/src/federation/validateCommunities.test.ts b/backend/src/federation/validateCommunities.test.ts index 68d2433d8..4f6339771 100644 --- a/backend/src/federation/validateCommunities.test.ts +++ b/backend/src/federation/validateCommunities.test.ts @@ -61,6 +61,7 @@ describe('validate Communities', () => { describe('with one Community of api 1_0 but missing pubKey response', () => { beforeEach(async () => { + jest.clearAllMocks() // eslint-disable-next-line @typescript-eslint/require-await jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -82,7 +83,7 @@ describe('validate Communities', () => { overwrite: ['end_point', 'last_announced_at'], }) .execute() - jest.clearAllMocks() + // jest.clearAllMocks() await validateCommunities() }) @@ -99,6 +100,7 @@ describe('validate Communities', () => { describe('with one Community of api 1_0 and not matching pubKey', () => { beforeEach(async () => { + jest.clearAllMocks() // eslint-disable-next-line @typescript-eslint/require-await jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -157,7 +159,7 @@ describe('validate Communities', () => { }) .execute() */ - jest.clearAllMocks() + // jest.clearAllMocks() await validateCommunities() }) @@ -171,7 +173,7 @@ describe('validate Communities', () => { ) }) it('logs not matching publicKeys', () => { - expect(logger.warn).toBeCalledWith( + expect(logger.debug).toBeCalledWith( 'Federation: received not matching publicKey:', 'somePubKey', expect.stringMatching('11111111111111111111111111111111'), @@ -180,6 +182,7 @@ describe('validate Communities', () => { }) describe('with one Community of api 1_0 and matching pubKey', () => { beforeEach(async () => { + jest.clearAllMocks() // eslint-disable-next-line @typescript-eslint/require-await jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -208,7 +211,7 @@ describe('validate Communities', () => { }) .execute() await DbFederatedCommunity.update({}, { verifiedAt: null }) - jest.clearAllMocks() + // jest.clearAllMocks() await validateCommunities() }) @@ -277,7 +280,7 @@ describe('validate Communities', () => { .execute() await DbFederatedCommunity.update({}, { verifiedAt: null }) - jest.clearAllMocks() + // jest.clearAllMocks() await validateCommunities() }) it('logs two communities found', () => { @@ -299,6 +302,18 @@ describe('validate Communities', () => { describe('with three Communities of api 1_0, 1_1 and 2_0', () => { let dbCom: DbFederatedCommunity beforeEach(async () => { + jest.clearAllMocks() + // eslint-disable-next-line @typescript-eslint/require-await + jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return { + data: { + getPublicKey: { + publicKey: '11111111111111111111111111111111', + }, + }, + } as Response + }) const variables3 = { publicKey: Buffer.from('11111111111111111111111111111111'), apiVersion: '2_0', @@ -319,7 +334,7 @@ describe('validate Communities', () => { where: { publicKey: variables3.publicKey, apiVersion: variables3.apiVersion }, }) await DbFederatedCommunity.update({}, { verifiedAt: null }) - jest.clearAllMocks() + // jest.clearAllMocks() await validateCommunities() }) it('logs three community found', () => { @@ -338,7 +353,7 @@ describe('validate Communities', () => { ) }) it('logs unsupported api for community with api 2_0 ', () => { - expect(logger.warn).toBeCalledWith( + expect(logger.debug).toBeCalledWith( 'Federation: dbCom with unsupported apiVersion', dbCom.endPoint, '2_0', diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index 6ee4f645a..69b69070a 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -53,21 +53,19 @@ export async function validateCommunities(): Promise { // eslint-disable-next-line camelcase if (client instanceof V1_0_FederationClient) { const pubKey = await client.getPublicKey() - logger.debug('Federation: nach getPublicKey()=', pubKey) - logger.debug('Federation: dbCom.publicKey=', dbCom.publicKey.toString()) if (pubKey && pubKey === dbCom.publicKey.toString()) { await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() }) - logger.info(`Federation: verified community with:`, dbCom.endPoint) + logger.debug(`Federation: verified community with:`, dbCom.endPoint) const pubComInfo = await client.getPublicCommunityInfo() if (pubComInfo) { await writeForeignCommunity(dbCom, pubComInfo) await startCommunityAuthentication(dbCom) logger.debug(`Federation: write publicInfo of community: name=${pubComInfo.name}`) } else { - logger.warn('Federation: missing result of getPublicCommunityInfo') + logger.debug('Federation: missing result of getPublicCommunityInfo') } } else { - logger.warn( + logger.debug( 'Federation: received not matching publicKey:', pubKey, dbCom.publicKey.toString(),