-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disable fwding logic to primary in new stack
- Loading branch information
Showing
5 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
test/unit/old-client-redirect-disabled-in-universal-broker-stack.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import bodyParser from 'body-parser'; | ||
import { overloadHttpRequestWithConnectionDetailsMiddleware } from '../../lib/server/routesHandlers/httpRequestHandler'; | ||
import express from 'express'; | ||
import request from 'supertest'; | ||
import { connectionStatusHandler } from '../../lib/server/routesHandlers/connectionStatusHandler'; | ||
|
||
jest.mock('../../lib/server/socket', () => { | ||
const originalModule = jest.requireActual('../../lib/server/socket'); | ||
|
||
return { | ||
__esModule: true, | ||
...originalModule, | ||
getSocketConnections: () => { | ||
const map = new Map(); | ||
|
||
map.set('7fe7a57b-aa0d-416a-97fc-472061737e24', [ | ||
{ socket: {}, socketVersion: '1', metadata: { capabilities: {} } }, | ||
]); | ||
// map.set('7fe7a57b-aa0d-416a-97fc-472061737e26', [ | ||
// { metadata: {version: '123', filter: {}} }, | ||
// ]); | ||
return map; | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('node:os', () => { | ||
const originalModule = jest.requireActual('node:os'); | ||
|
||
return { | ||
__esModule: true, | ||
...originalModule, | ||
hostname: () => { | ||
return 'my-server-name-10-1'; | ||
}, | ||
}; | ||
}); | ||
|
||
describe('Testing older clients specific logic', () => { | ||
beforeAll(() => { | ||
process.env.BROKER_SERVER_MANDATORY_AUTH_ENABLED = 'true'; | ||
}); | ||
afterAll(() => { | ||
delete process.env.BROKER_SERVER_MANDATORY_AUTH_ENABLED; | ||
}); | ||
|
||
it('Testing the old client redirected to primary from secondary pods', async () => { | ||
const app = express(); | ||
app.use( | ||
bodyParser.raw({ | ||
type: (req) => | ||
req.headers['content-type'] !== | ||
'application/vnd.broker.stream+octet-stream', | ||
limit: '10mb', | ||
}), | ||
); | ||
app.all( | ||
'/broker/:token/*', | ||
overloadHttpRequestWithConnectionDetailsMiddleware, | ||
); | ||
|
||
const response = await request(app) | ||
.get('/broker/7fe7a57b-aa0d-416a-97fc-472061737e25/path') | ||
.set('Host', 'my-server-name-1.default.svc.cluster'); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
it('Testing the old client redirected to primary from secondary pods - POST request', async () => { | ||
const app = express(); | ||
app.use( | ||
bodyParser.raw({ | ||
type: (req) => | ||
req.headers['content-type'] !== | ||
'application/vnd.broker.stream+octet-stream', | ||
limit: '10mb', | ||
}), | ||
); | ||
app.all( | ||
'/broker/:token/*', | ||
overloadHttpRequestWithConnectionDetailsMiddleware, | ||
); | ||
|
||
const response = await request(app) | ||
.post('/broker/7fe7a57b-aa0d-416a-97fc-472061737e25/path') | ||
.set('Host', 'my-server-name-1.default.svc.cluster') | ||
.send({ test: 'value2' }); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
it('Testing the old client redirected to primary from secondary pods - get request', async () => { | ||
const app = express(); | ||
app.use( | ||
bodyParser.raw({ | ||
type: (req) => | ||
req.headers['content-type'] !== | ||
'application/vnd.broker.stream+octet-stream', | ||
limit: '10mb', | ||
}), | ||
); | ||
app.all( | ||
'/broker/:token/*', | ||
overloadHttpRequestWithConnectionDetailsMiddleware, | ||
); | ||
|
||
const response = await request(app) | ||
.get('/broker/7fe7a57b-aa0d-416a-97fc-472061737e25/file') | ||
.set('Host', 'my-server-name-1.default.svc.cluster'); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
|
||
it('Testing the connection-status old client redirected to primary from secondary pods', async () => { | ||
const app = express(); | ||
app.use( | ||
bodyParser.raw({ | ||
type: (req) => | ||
req.headers['content-type'] !== | ||
'application/vnd.broker.stream+octet-stream', | ||
limit: '10mb', | ||
}), | ||
); | ||
app.all('/connection-status/:token', connectionStatusHandler); | ||
|
||
const response = await request(app) | ||
.get('/connection-status/7fe7a57b-aa0d-416a-97fc-472061737e26') | ||
.set('Host', 'my-server-name-1.default.svc.cluster'); | ||
|
||
expect(response.status).toEqual(404); | ||
}); | ||
}); |