mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
additional test with matching pubKey
This commit is contained in:
parent
fc822332dc
commit
7d5b8b9b62
@ -59,7 +59,7 @@ describe('validate Communities', () => {
|
|||||||
expect(logger.debug).toBeCalledWith(`Federation: found 0 dbCommunities`)
|
expect(logger.debug).toBeCalledWith(`Federation: found 0 dbCommunities`)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with one Community of api 1_0', () => {
|
describe('with one Community of api 1_0 and not matching pubKey', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/require-await
|
// eslint-disable-next-line @typescript-eslint/require-await
|
||||||
jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => {
|
jest.spyOn(GraphQLClient.prototype, 'rawRequest').mockImplementation(async () => {
|
||||||
@ -73,7 +73,9 @@ describe('validate Communities', () => {
|
|||||||
} as Response<unknown>
|
} as Response<unknown>
|
||||||
})
|
})
|
||||||
const variables1 = {
|
const variables1 = {
|
||||||
publicKey: Buffer.from('11111111111111111111111111111111'),
|
publicKey: Buffer.from(
|
||||||
|
'1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
|
),
|
||||||
apiVersion: '1_0',
|
apiVersion: '1_0',
|
||||||
endPoint: 'http//localhost:5001/api/',
|
endPoint: 'http//localhost:5001/api/',
|
||||||
lastAnnouncedAt: new Date(),
|
lastAnnouncedAt: new Date(),
|
||||||
@ -106,7 +108,60 @@ describe('validate Communities', () => {
|
|||||||
expect(logger.warn).toBeCalledWith(
|
expect(logger.warn).toBeCalledWith(
|
||||||
'Federation: received not matching publicKey:',
|
'Federation: received not matching publicKey:',
|
||||||
'somePubKey',
|
'somePubKey',
|
||||||
expect.stringMatching('11111111111111111111111111111111'),
|
expect.stringMatching('1111111111111111111111111111111111111111111111111111111111111111'),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
describe('with one Community of api 1_0 and matching pubKey', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
// 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: '1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as Response<unknown>
|
||||||
|
})
|
||||||
|
const variables1 = {
|
||||||
|
publicKey: Buffer.from(
|
||||||
|
'1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
|
),
|
||||||
|
apiVersion: '1_0',
|
||||||
|
endPoint: 'http//localhost:5001/api/',
|
||||||
|
lastAnnouncedAt: new Date(),
|
||||||
|
}
|
||||||
|
await DbFederatedCommunity.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(DbFederatedCommunity)
|
||||||
|
.values(variables1)
|
||||||
|
.orUpdate({
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
conflict_target: ['id', 'publicKey', 'apiVersion'],
|
||||||
|
overwrite: ['end_point', 'last_announced_at'],
|
||||||
|
})
|
||||||
|
.execute()
|
||||||
|
await DbFederatedCommunity.update({}, { verifiedAt: null })
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await validateCommunities()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('logs one community found', () => {
|
||||||
|
expect(logger.debug).toBeCalledWith(`Federation: found 1 dbCommunities`)
|
||||||
|
})
|
||||||
|
it('logs requestGetPublicKey for community api 1_0 ', () => {
|
||||||
|
expect(logger.info).toBeCalledWith(
|
||||||
|
'Federation: getPublicKey from endpoint',
|
||||||
|
'http//localhost:5001/api/1_0/',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
it('logs community pubKey verified', () => {
|
||||||
|
expect(logger.info).toHaveBeenNthCalledWith(
|
||||||
|
3,
|
||||||
|
'Federation: verified community with',
|
||||||
|
'http//localhost:5001/api/',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -119,13 +174,15 @@ describe('validate Communities', () => {
|
|||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
getPublicKey: {
|
getPublicKey: {
|
||||||
publicKey: '11111111111111111111111111111111',
|
publicKey: '1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as Response<unknown>
|
} as Response<unknown>
|
||||||
})
|
})
|
||||||
const variables2 = {
|
const variables2 = {
|
||||||
publicKey: Buffer.from('11111111111111111111111111111111'),
|
publicKey: Buffer.from(
|
||||||
|
'1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
|
),
|
||||||
apiVersion: '1_1',
|
apiVersion: '1_1',
|
||||||
endPoint: 'http//localhost:5001/api/',
|
endPoint: 'http//localhost:5001/api/',
|
||||||
lastAnnouncedAt: new Date(),
|
lastAnnouncedAt: new Date(),
|
||||||
@ -141,6 +198,7 @@ describe('validate Communities', () => {
|
|||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
|
await DbFederatedCommunity.update({}, { verifiedAt: null })
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
await validateCommunities()
|
await validateCommunities()
|
||||||
})
|
})
|
||||||
@ -164,7 +222,9 @@ describe('validate Communities', () => {
|
|||||||
let dbCom: DbFederatedCommunity
|
let dbCom: DbFederatedCommunity
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const variables3 = {
|
const variables3 = {
|
||||||
publicKey: Buffer.from('11111111111111111111111111111111'),
|
publicKey: Buffer.from(
|
||||||
|
'1111111111111111111111111111111111111111111111111111111111111111',
|
||||||
|
),
|
||||||
apiVersion: '2_0',
|
apiVersion: '2_0',
|
||||||
endPoint: 'http//localhost:5001/api/',
|
endPoint: 'http//localhost:5001/api/',
|
||||||
lastAnnouncedAt: new Date(),
|
lastAnnouncedAt: new Date(),
|
||||||
@ -182,6 +242,7 @@ describe('validate Communities', () => {
|
|||||||
dbCom = await DbFederatedCommunity.findOneOrFail({
|
dbCom = await DbFederatedCommunity.findOneOrFail({
|
||||||
where: { publicKey: variables3.publicKey, apiVersion: variables3.apiVersion },
|
where: { publicKey: variables3.publicKey, apiVersion: variables3.apiVersion },
|
||||||
})
|
})
|
||||||
|
await DbFederatedCommunity.update({}, { verifiedAt: null })
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
await validateCommunities()
|
await validateCommunities()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -45,7 +45,7 @@ export async function validateCommunities(): Promise<void> {
|
|||||||
const pubKey = await client.getPublicKey()
|
const pubKey = await client.getPublicKey()
|
||||||
if (pubKey && pubKey === dbCom.publicKey.toString()) {
|
if (pubKey && pubKey === dbCom.publicKey.toString()) {
|
||||||
await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
|
await DbFederatedCommunity.update({ id: dbCom.id }, { verifiedAt: new Date() })
|
||||||
logger.info('Federation: verified community', dbCom)
|
logger.info('Federation: verified community with', dbCom.endPoint)
|
||||||
} else {
|
} else {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
'Federation: received not matching publicKey:',
|
'Federation: received not matching publicKey:',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user