Skip to content

Commit

Permalink
#409: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basmasking committed Oct 21, 2024
1 parent fb212da commit cc32ae3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/services/test/gateway/LocalGateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { describe, expect, it } from 'vitest';

import InvalidTrustKey from '../../src/gateway/errors/InvalidTrustKey';

import { LOCAL_GATEWAYS, REMOTE_WORKERS, VALUES } from './fixtures';
import { LOCAL_GATEWAYS, REMOTE_WORKERS } from './fixtures';

const publicGateway = LOCAL_GATEWAYS.PUBLIC;
const protectedGateway = LOCAL_GATEWAYS.PROTECTED;

const emptyWorker = REMOTE_WORKERS.EMPTY;
const trustedWorker = REMOTE_WORKERS.TRUSTED;
const untrustedWorker = REMOTE_WORKERS.UNTRUSTED;

describe('gateway/LocalGateway', () =>
{
Expand All @@ -23,14 +25,14 @@ describe('gateway/LocalGateway', () =>

it('should add a worker with a valid trust key to a protected gateway', () =>
{
const promise = protectedGateway.addWorker(emptyWorker, VALUES.TRUST_KEY);
const promise = protectedGateway.addWorker(trustedWorker);

expect(promise).resolves.toBeUndefined();
});

it('should not add a worker with an invalid trust key to a protected gateway', () =>
{
const promise = protectedGateway.addWorker(emptyWorker, 'INCORRECT_ACCESS_KEY');
const promise = protectedGateway.addWorker(untrustedWorker);

expect(promise).rejects.toEqual(new InvalidTrustKey());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LocalGateway from '../../../src/gateway/LocalGateway';
import { VALUES } from './values.fixture';

const url = VALUES.URL;
const trustKey = VALUES.TRUST_KEY;
const trustKey = VALUES.VALID_TRUST_KEY;

const publicGateway = new LocalGateway({ url });
const protectedGateway = new LocalGateway({ url, trustKey});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const remote = REMOTES.DUMMY;
const noProcedureNames = new Set<string>();
const emptyWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote });

const trustedWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote, trustKey: VALUES.VALID_TRUST_KEY });
const untrustedWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote, trustKey: VALUES.INVALID_TRUST_KEY });

const firstProcedureNames = new Set<string>(['first']);
const firstWorker = new RemoteWorker({ url, procedureNames: firstProcedureNames, remote });

Expand All @@ -38,6 +41,8 @@ const unhealthyWorker = new UnhealthyWorker({ url, procedureNames: noProcedureNa
export const REMOTE_WORKERS =
{
EMPTY: emptyWorker,
TRUSTED: trustedWorker,
UNTRUSTED: untrustedWorker,
FIRST: firstWorker,
SECOND: secondWorker,
HEALTHY: healthyWorker,
Expand Down
6 changes: 6 additions & 0 deletions packages/services/test/gateway/fixtures/remotes.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class DummyRemote implements Remote
throw new NotImplemented();
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
removeWorker(workerUrl: string, trustKey?: string): Promise<void>
{
throw new NotImplemented();
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async run(request: Request): Promise<Response>
{
Expand Down
3 changes: 2 additions & 1 deletion packages/services/test/gateway/fixtures/values.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
export const VALUES =
{
URL: 'http://localhost:80',
TRUST_KEY: 'MY_TRUSTED_ACCESS_KEY'
VALID_TRUST_KEY: 'MY_TRUSTED_ACCESS_KEY',
INVALID_TRUST_KEY: 'INCORRECT_ACCESS_KEY'
};

0 comments on commit cc32ae3

Please sign in to comment.