Skip to content

Commit cc32ae3

Browse files
committed
#409: updated tests
1 parent fb212da commit cc32ae3

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

packages/services/test/gateway/LocalGateway.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { describe, expect, it } from 'vitest';
33

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

6-
import { LOCAL_GATEWAYS, REMOTE_WORKERS, VALUES } from './fixtures';
6+
import { LOCAL_GATEWAYS, REMOTE_WORKERS } from './fixtures';
77

88
const publicGateway = LOCAL_GATEWAYS.PUBLIC;
99
const protectedGateway = LOCAL_GATEWAYS.PROTECTED;
1010

1111
const emptyWorker = REMOTE_WORKERS.EMPTY;
12+
const trustedWorker = REMOTE_WORKERS.TRUSTED;
13+
const untrustedWorker = REMOTE_WORKERS.UNTRUSTED;
1214

1315
describe('gateway/LocalGateway', () =>
1416
{
@@ -23,14 +25,14 @@ describe('gateway/LocalGateway', () =>
2325

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

2830
expect(promise).resolves.toBeUndefined();
2931
});
3032

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

3537
expect(promise).rejects.toEqual(new InvalidTrustKey());
3638
});

packages/services/test/gateway/fixtures/localGateways.fixture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import LocalGateway from '../../../src/gateway/LocalGateway';
44
import { VALUES } from './values.fixture';
55

66
const url = VALUES.URL;
7-
const trustKey = VALUES.TRUST_KEY;
7+
const trustKey = VALUES.VALID_TRUST_KEY;
88

99
const publicGateway = new LocalGateway({ url });
1010
const protectedGateway = new LocalGateway({ url, trustKey});

packages/services/test/gateway/fixtures/remoteWorkers.fixture.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const remote = REMOTES.DUMMY;
2626
const noProcedureNames = new Set<string>();
2727
const emptyWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote });
2828

29+
const trustedWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote, trustKey: VALUES.VALID_TRUST_KEY });
30+
const untrustedWorker = new RemoteWorker({ url, procedureNames: noProcedureNames, remote, trustKey: VALUES.INVALID_TRUST_KEY });
31+
2932
const firstProcedureNames = new Set<string>(['first']);
3033
const firstWorker = new RemoteWorker({ url, procedureNames: firstProcedureNames, remote });
3134

@@ -38,6 +41,8 @@ const unhealthyWorker = new UnhealthyWorker({ url, procedureNames: noProcedureNa
3841
export const REMOTE_WORKERS =
3942
{
4043
EMPTY: emptyWorker,
44+
TRUSTED: trustedWorker,
45+
UNTRUSTED: untrustedWorker,
4146
FIRST: firstWorker,
4247
SECOND: secondWorker,
4348
HEALTHY: healthyWorker,

packages/services/test/gateway/fixtures/remotes.fixture.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class DummyRemote implements Remote
3939
throw new NotImplemented();
4040
}
4141

42+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
43+
removeWorker(workerUrl: string, trustKey?: string): Promise<void>
44+
{
45+
throw new NotImplemented();
46+
}
47+
4248
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4349
async run(request: Request): Promise<Response>
4450
{

packages/services/test/gateway/fixtures/values.fixture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
export const VALUES =
33
{
44
URL: 'http://localhost:80',
5-
TRUST_KEY: 'MY_TRUSTED_ACCESS_KEY'
5+
VALID_TRUST_KEY: 'MY_TRUSTED_ACCESS_KEY',
6+
INVALID_TRUST_KEY: 'INCORRECT_ACCESS_KEY'
67
};

0 commit comments

Comments
 (0)