From 5dd337e96c73430296db2bda44b682d28df48c9e Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Mon, 13 Oct 2025 18:03:37 +0200 Subject: [PATCH] fix const 10 minutes not 10 hours (._.);, update logging --- .../src/federation/authenticateCommunities.ts | 2 +- .../CommunityHandshakeStateLogic.test.ts | 22 +++++++++++++++++++ shared/src/const/index.ts | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 core/src/logic/CommunityHandshakeStateLogic.test.ts diff --git a/backend/src/federation/authenticateCommunities.ts b/backend/src/federation/authenticateCommunities.ts index 340705437..c548be8e7 100644 --- a/backend/src/federation/authenticateCommunities.ts +++ b/backend/src/federation/authenticateCommunities.ts @@ -59,7 +59,7 @@ export async function startCommunityAuthentication( if (existingState) { const stateLogic = new CommunityHandshakeStateLogic(existingState) // retry on timeout or failure - if (!await stateLogic.isTimeoutUpdate()) { + if (!(await stateLogic.isTimeoutUpdate())) { // authentication with community and api version is still in progress and it is not timeout yet methodLogger.debug('existingState, so we exit here', new CommunityHandshakeStateLoggingView(existingState)) return diff --git a/core/src/logic/CommunityHandshakeStateLogic.test.ts b/core/src/logic/CommunityHandshakeStateLogic.test.ts new file mode 100644 index 000000000..52d11d8fb --- /dev/null +++ b/core/src/logic/CommunityHandshakeStateLogic.test.ts @@ -0,0 +1,22 @@ +import { CommunityHandshakeState } from 'database' +import { CommunityHandshakeStateLogic } from './CommunityHandshakeState.logic' +import { CommunityHandshakeStateType } from 'database' +import { FEDERATION_AUTHENTICATION_TIMEOUT_MS } from 'shared' + +describe('CommunityHandshakeStateLogic', () => { + it('isTimeout', () => { + const state = new CommunityHandshakeState() + state.updatedAt = new Date(Date.now() - FEDERATION_AUTHENTICATION_TIMEOUT_MS * 2) + state.status = CommunityHandshakeStateType.START_AUTHENTICATION + const logic = new CommunityHandshakeStateLogic(state) + expect(logic.isTimeout()).toEqual(true) + }) + + it('isTimeout return false', () => { + const state = new CommunityHandshakeState() + state.updatedAt = new Date(Date.now()) + state.status = CommunityHandshakeStateType.START_AUTHENTICATION + const logic = new CommunityHandshakeStateLogic(state) + expect(logic.isTimeout()).toEqual(false) + }) +}) \ No newline at end of file diff --git a/shared/src/const/index.ts b/shared/src/const/index.ts index 549991c61..97fe8f306 100644 --- a/shared/src/const/index.ts +++ b/shared/src/const/index.ts @@ -3,4 +3,4 @@ export const SECONDS_PER_YEAR_GREGORIAN_CALENDER = 31556952.0 export const LOG4JS_BASE_CATEGORY_NAME = 'shared' export const REDEEM_JWT_TOKEN_EXPIRATION = '10m' // 10 minutes -export const FEDERATION_AUTHENTICATION_TIMEOUT_MS = 60 * 60 * 1000 * 10 \ No newline at end of file +export const FEDERATION_AUTHENTICATION_TIMEOUT_MS = 60 * 1000 * 10 \ No newline at end of file