adapt existing tests

This commit is contained in:
Claus-Peter Huebner 2023-10-26 22:41:06 +02:00
parent 8a861b3fec
commit f2b755feb7
3 changed files with 25 additions and 19 deletions

View File

@ -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 {

View File

@ -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<unknown>
})
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',

View File

@ -53,21 +53,19 @@ export async function validateCommunities(): Promise<void> {
// 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(),