all tests finished

This commit is contained in:
Claus-Peter Hübner 2022-12-22 23:40:43 +01:00
parent f264b02b25
commit c1c6aa285d
2 changed files with 94 additions and 18 deletions

View File

@ -240,20 +240,19 @@ describe('federation', () => {
{ api: 'v1_0', url: 'url3' }, { api: 'v1_0', url: 'url3' },
{ api: 'v1_0', url: 'url4' }, { api: 'v1_0', url: 'url4' },
{ api: 'v1_0', url: 'url5' }, { api: 'v1_0', url: 'url5' },
{ api: 'v1_0', url: 'url6' },
] ]
await socketEventMocks.data(Buffer.from(JSON.stringify(jsonArray))) await socketEventMocks.data(Buffer.from(JSON.stringify(jsonArray)))
}) })
it('logs the received data', () => { it('logs the received data', () => {
expect(logger.info).toBeCalledWith( expect(logger.info).toBeCalledWith(
'data: [{"api":"v1_0","url":"too much versions at the same time test"},{"api":"v1_0","url":"url2"},{"api":"v1_0","url":"url3"},{"api":"v1_0","url":"url4"},{"api":"v1_0","url":"url5"},{"api":"v1_0","url":"url6"}]', 'data: [{"api":"v1_0","url":"too much versions at the same time test"},{"api":"v1_0","url":"url2"},{"api":"v1_0","url":"url3"},{"api":"v1_0","url":"url4"},{"api":"v1_0","url":"url5"}]',
) )
}) })
it('logs a warning of too much apiVersion-Definitions', () => { it('logs a warning of too much apiVersion-Definitions', () => {
expect(logger.warn).toBeCalledWith( expect(logger.warn).toBeCalledWith(
`received totaly wrong or too much apiVersions-Definition JSON-String:${JSON.stringify( `received totaly wrong or too much apiVersions-Definition JSON-String: ${JSON.stringify(
jsonArray, jsonArray,
)}`, )}`,
) )
@ -566,7 +565,6 @@ describe('federation', () => {
}) })
}) })
/*
describe('with receiving data of exact max allowed buffer length', () => { describe('with receiving data of exact max allowed buffer length', () => {
let jsonArray: any[] let jsonArray: any[]
let result: DbCommunity[] = [] let result: DbCommunity[] = []
@ -589,24 +587,20 @@ describe('federation', () => {
api: 'valid api4', api: 'valid api4',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich', url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
}, },
{
api: 'valid api5',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
},
] ]
await socketEventMocks.data(Buffer.from(JSON.stringify(jsonArray))) await socketEventMocks.data(Buffer.from(JSON.stringify(jsonArray)))
result = await DbCommunity.find() result = await DbCommunity.find()
}) })
afterAll(async () => { afterAll(async () => {
// await cleanDB() await cleanDB()
}) })
it('has five Communty entries in database', () => { it('has five Communty entries in database', () => {
expect(result).toHaveLength(5) expect(result).toHaveLength(4)
}) })
it(`has an entry with max content length for api and url`, () => { it(`has an entry 'valid api1' with max content length for api and url`, () => {
expect(result).toEqual( expect(result).toEqual(
expect.arrayContaining([ expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
@ -614,7 +608,58 @@ describe('federation', () => {
publicKey: expect.any(Buffer), publicKey: expect.any(Buffer),
apiVersion: 'valid api1', apiVersion: 'valid api1',
endPoint: endPoint:
'this is a valid url definition with the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmigasmilchdirek menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofrierts', 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
lastAnnouncedAt: expect.any(Date),
createdAt: expect.any(Date),
updatedAt: null,
}),
]),
)
})
it(`has an entry 'valid api2' with max content length for api and url`, () => {
expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(Number),
publicKey: expect.any(Buffer),
apiVersion: 'valid api2',
endPoint:
'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
lastAnnouncedAt: expect.any(Date),
createdAt: expect.any(Date),
updatedAt: null,
}),
]),
)
})
it(`has an entry 'valid api3' with max content length for api and url`, () => {
expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(Number),
publicKey: expect.any(Buffer),
apiVersion: 'valid api3',
endPoint:
'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
lastAnnouncedAt: expect.any(Date),
createdAt: expect.any(Date),
updatedAt: null,
}),
]),
)
})
it(`has an entry 'valid api4' with max content length for api and url`, () => {
expect(result).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(Number),
publicKey: expect.any(Buffer),
apiVersion: 'valid api4',
endPoint:
'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
lastAnnouncedAt: expect.any(Date), lastAnnouncedAt: expect.any(Date),
createdAt: expect.any(Date), createdAt: expect.any(Date),
updatedAt: null, updatedAt: null,
@ -623,7 +668,40 @@ describe('federation', () => {
) )
}) })
}) })
*/
describe('with receiving data longer than max allowed buffer length', () => {
let jsonArray: any[]
beforeEach(async () => {
jest.clearAllMocks()
jsonArray = [
{
api: 'Xvalid api1',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
},
{
api: 'valid api2',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
},
{
api: 'valid api3',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
},
{
api: 'valid api4',
url: 'this is a valid url definition with exact the max allowed length of two hundert and fiftyfive characters. and here begins the fill characters with no sense of content kuhwarmiga menschhabicheinhungerdassichnichtweiswoichheutnachtschlafensollsofriertesmich',
},
]
await socketEventMocks.data(Buffer.from(JSON.stringify(jsonArray)))
})
it('logs the received data', () => {
expect(logger.warn).toBeCalledWith(
`received more than max allowed length of data buffer: ${
JSON.stringify(jsonArray).length
} against 1141 max allowed`,
)
})
})
describe('with proper data', () => { describe('with proper data', () => {
let result: DbCommunity[] = [] let result: DbCommunity[] = []

View File

@ -49,10 +49,9 @@ export const startDHT = async (topic: string): Promise<void> => {
socket.on('data', async (data: Buffer) => { socket.on('data', async (data: Buffer) => {
try { try {
// console.log(`data.len=${data.length}, ${data.toString('ascii')}`) if (data.length > 1141) {
if (data.length > 1426) {
logger.warn( logger.warn(
`received more than max allowed length of data buffer: ${data.length} / 1426`, `received more than max allowed length of data buffer: ${data.length} against 1141 max allowed`,
) )
return return
} }
@ -102,12 +101,11 @@ export const startDHT = async (topic: string): Promise<void> => {
overwrite: ['end_point', 'last_announced_at'], overwrite: ['end_point', 'last_announced_at'],
}) })
.execute() .execute()
// console.log(`upserted...`, variables)
logger.info(`federation community upserted successfully...`) logger.info(`federation community upserted successfully...`)
} }
} else { } else {
logger.warn( logger.warn(
`received totaly wrong or too much apiVersions-Definition JSON-String:${JSON.stringify( `received totaly wrong or too much apiVersions-Definition JSON-String: ${JSON.stringify(
recApiVersions, recApiVersions,
)}`, )}`,
) )