-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
94 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface PowebRouteOptions { | ||
readonly internetAddress: string; | ||
} |
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
import { NodeConnectionParams } from '@relaycorp/relaynet-core'; | ||
|
||
import { testDisallowedMethods } from '../../testUtils/fastify'; | ||
import { makePoWebTestServer } from './_test_utils'; | ||
import { CONTENT_TYPES } from './contentTypes'; | ||
import { InternetGatewayManager } from '../../node/InternetGatewayManager'; | ||
import { GATEWAY_INTERNET_ADDRESS } from '../../testUtils/awala'; | ||
|
||
jest.mock('../../utilities/exitHandling'); | ||
|
||
const ENDPOINT_URL = '/connection-params.der'; | ||
|
||
describe('connectionParams', () => { | ||
const getFixtures = makePoWebTestServer(); | ||
|
||
testDisallowedMethods(['HEAD', 'GET'], ENDPOINT_URL, async () => getFixtures().server); | ||
|
||
test('Should respond with connection parameters', async () => { | ||
const { server, dbConnection } = getFixtures(); | ||
const gatewayManager = await InternetGatewayManager.init(dbConnection); | ||
const gateway = await gatewayManager.getCurrent(); | ||
await gateway.makeInitialSessionKeyIfMissing(); | ||
|
||
const response = await server.inject({ method: 'GET', url: ENDPOINT_URL }); | ||
|
||
expect(response).toHaveProperty('statusCode', 200); | ||
expect(response).toHaveProperty('headers.content-type', CONTENT_TYPES.CONNECTION_PARAMS); | ||
const expectedParameters = new NodeConnectionParams( | ||
GATEWAY_INTERNET_ADDRESS, | ||
gateway.identityKeyPair.publicKey, | ||
(await gateway.keyStores.privateKeyStore.retrieveUnboundSessionPublicKey(gateway.id))!, | ||
); | ||
expect(response.rawPayload).toMatchObject(Buffer.from(await expectedParameters.serialize())); | ||
}); | ||
}); |
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,32 @@ | ||
import { NodeConnectionParams } from '@relaycorp/relaynet-core'; | ||
import { FastifyInstance } from 'fastify'; | ||
|
||
import { registerDisallowedMethods } from '../../utilities/fastify/server'; | ||
import { InternetGatewayManager } from '../../node/InternetGatewayManager'; | ||
import type { PowebRouteOptions } from './PowebRouteOptions'; | ||
import { CONTENT_TYPES } from './contentTypes'; | ||
|
||
const ENDPOINT_URL = '/connection-params.der'; | ||
|
||
export default async function registerRoutes( | ||
fastify: FastifyInstance, | ||
options: PowebRouteOptions, | ||
): Promise<void> { | ||
registerDisallowedMethods(['HEAD', 'GET'], ENDPOINT_URL, fastify); | ||
|
||
fastify.route({ | ||
method: ['HEAD', 'GET'], | ||
url: ENDPOINT_URL, | ||
async handler(_req, reply): Promise<void> { | ||
const gatewayManager = await InternetGatewayManager.init(fastify.mongoose); | ||
const gateway = await gatewayManager.getCurrent(); | ||
const params = new NodeConnectionParams( | ||
options.internetAddress, | ||
gateway.identityKeyPair.publicKey, | ||
(await gateway.keyStores.privateKeyStore.retrieveUnboundSessionPublicKey(gateway.id))!, | ||
); | ||
const paramsSerialised = await params.serialize(); | ||
reply.type(CONTENT_TYPES.CONNECTION_PARAMS).send(Buffer.from(paramsSerialised)); | ||
}, | ||
}); | ||
} |
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
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