Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.universal.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.pre-prod.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.pre-prod.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltest10.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltest11.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltest12.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltest2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest4.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest5.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest6.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest7.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
1 change: 0 additions & 1 deletion config.universaltest8.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
}
Expand Down
1 change: 0 additions & 1 deletion config.universaltest9.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
},
"oauth": {
Expand Down
1 change: 0 additions & 1 deletion config.universaltestpool.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"common": {
"default": {
"BROKER_SERVER_URL": "https://broker.dev.snyk.io",
"BROKER_HA_MODE_ENABLED": "false",
"BROKER_DISPATCHER_BASE_URL": "https://api.dev.snyk.io"
}
},
Expand Down
8 changes: 7 additions & 1 deletion lib/hybrid-sdk/client/config/configHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ const isCredPoolingUsed = (config: Record<string, any>): boolean => {
};

export function highAvailabilityModeEnabled(config: any): boolean {
// high availability mode is disabled per default
// Universal broker always runs in HA mode
if (config.universalBrokerEnabled) {
logger.debug({ enabled: true }, 'Checking for HA mode.');
return true;
}

// Legacy broker reads from flag, disabled by default
let highAvailabilityModeEnabled = false;
const highAvailabilityModeEnabledValue = (config as Config)
.BROKER_HA_MODE_ENABLED;
Expand Down
18 changes: 7 additions & 11 deletions lib/hybrid-sdk/client/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ export const createWebSocketConnectionPairs = async (
`Cannot create websocket connection ${socketIdentifyingMetadata.friendlyName} without identifier.`,
);
}
let serverId: string | null = null;
if (clientOpts.config.BROKER_HA_MODE_ENABLED == 'true') {
serverId = await getServerId(
clientOpts.config,
socketIdentifyingMetadata.identifier,
socketIdentifyingMetadata.clientId,
);
}
let serverId = await getServerId(
clientOpts.config,
socketIdentifyingMetadata.identifier,
socketIdentifyingMetadata.clientId,
);

if (serverId === null) {
if (clientOpts.config.BROKER_HA_MODE_ENABLED == 'true') {
logger.warn({}, 'Could not receive server id from Broker Dispatcher.');
}
logger.warn({}, 'Could not receive server id from Broker Dispatcher.');
serverId = '';
} else {
logger.info(
Expand Down
6 changes: 6 additions & 0 deletions test/functional/healthcheck-universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,35 @@ import {
waitForUniversalBrokerClientsConnection,
} from '../setup/broker-server';
import { TestWebServer, createTestWebServer } from '../setup/test-web-server';
import { TestApiServer, createTestApiServer } from '../setup/test-api-server';
import { createUniversalBrokerClient } from '../setup/broker-universal-client';

const fixtures = path.resolve(__dirname, '..', 'fixtures');
const serverAccept = path.join(fixtures, 'server', 'filters.json');

describe('proxy requests originating from behind the broker client', () => {
let tws: TestWebServer;
let tas: TestApiServer;
let bs: BrokerServer;
let bc: BrokerClient;

beforeAll(async () => {
delete process.env.BROKER_SERVER_URL;
tws = await createTestWebServer();
tas = await createTestApiServer();
bs = await createBrokerServer({ filters: serverAccept });
process.env.SNYK_BROKER_CLIENT_CONFIGURATION__common__default__BROKER_SERVER_URL = `http://localhost:${bs.port}`;
process.env.API_BASE_URL = `http://localhost:${tas.port}`;
process.env.CLIENT_ID = 'clienid';
process.env.CLIENT_SECRET = 'clientsecret';
process.env.SKIP_REMOTE_CONFIG = 'true';
});

afterAll(async () => {
await tws.server.close();
await tas.server.close();
await closeBrokerServer(bs);
delete process.env.API_BASE_URL;
delete process.env.BROKER_SERVER_URL;
delete process.env
.SNYK_BROKER_CLIENT_CONFIGURATION__common__default__BROKER_SERVER_URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
waitForUniversalBrokerClientsConnection,
} from '../setup/broker-server';
import { TestWebServer, createTestWebServer } from '../setup/test-web-server';
import { TestApiServer, createTestApiServer } from '../setup/test-api-server';
import { createUniversalBrokerClient } from '../setup/broker-universal-client';

const fixtures = path.resolve(__dirname, '..', 'fixtures');
Expand All @@ -16,6 +17,7 @@ const clientAccept = path.join(fixtures, 'client', 'filters.json');

describe('proxy requests originating from behind the broker server', () => {
let tws: TestWebServer;
let tas: TestApiServer;
let bs: BrokerServer;
let bc: BrokerClient;

Expand All @@ -28,9 +30,10 @@ describe('proxy requests originating from behind the broker server', () => {
beforeAll(async () => {
const PORT = 9999;
tws = await createTestWebServer();
tas = await createTestApiServer();
process.env.RESPONSE_DATA_HIDDEN_ENABLED = 'true';
bs = await createBrokerServer({ filters: serverAccept, port: PORT });
process.env.API_BASE_URL = `http://localhost:${bs.port}`;
process.env.API_BASE_URL = `http://localhost:${tas.port}`;
process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED = 'true';
process.env.UNIVERSAL_BROKER_ENABLED = 'true';
process.env.SERVICE_ENV = 'universaltest7';
Expand All @@ -53,8 +56,10 @@ describe('proxy requests originating from behind the broker server', () => {
afterAll(async () => {
spyLogWarn.mockReset();
await tws.server.close();
await tas.server.close();
await closeBrokerClient(bc);
await closeBrokerServer(bs);
delete process.env.API_BASE_URL;
delete process.env.BROKER_SERVER_URL;
delete process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED;
delete process.env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
waitForUniversalBrokerClientsConnection,
} from '../setup/broker-server';
import { TestWebServer, createTestWebServer } from '../setup/test-web-server';
import { TestApiServer, createTestApiServer } from '../setup/test-api-server';
import { createUniversalBrokerClient } from '../setup/broker-universal-client';

const fixtures = path.resolve(__dirname, '..', 'fixtures');
Expand All @@ -17,6 +18,7 @@ const clientAccept = path.join(fixtures, 'client', 'filters.json');

describe('proxy requests originating from behind the broker server with pooled credentials', () => {
let tws: TestWebServer;
let tas: TestApiServer;
let bs: BrokerServer;
let bc: BrokerClient;
let brokerTokens: string[];
Expand All @@ -33,9 +35,10 @@ describe('proxy requests originating from behind the broker server with pooled c

const PORT = 9999;
tws = await createTestWebServer();
tas = await createTestApiServer();
process.env.RESPONSE_DATA_HIDDEN_ENABLED = 'true';
bs = await createBrokerServer({ port: PORT, filters: serverAccept });
process.env.API_BASE_URL = `http://localhost:${bs.port}`;
process.env.API_BASE_URL = `http://localhost:${tas.port}`;
process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED = 'true';
process.env.UNIVERSAL_BROKER_ENABLED = 'true';
process.env.SERVICE_ENV = 'universaltestpool';
Expand All @@ -55,15 +58,17 @@ describe('proxy requests originating from behind the broker server with pooled c
process.env.SNYK_FILTER_RULES_PATHS__gitlab = clientAccept;
process.env['SNYK_FILTER_RULES_PATHS__azure-repos'] = clientAccept;
process.env['SNYK_FILTER_RULES_PATHS__jira-bearer-auth'] = clientAccept;
const connectionPromise = waitForUniversalBrokerClientsConnection(bs, 4);
bc = await createUniversalBrokerClient();
({ brokerTokens, metadataArray } =
await waitForUniversalBrokerClientsConnection(bs, 2));
({ brokerTokens, metadataArray } = await connectionPromise);
});

afterAll(async () => {
await tws.server.close();
await tas.server.close();
await closeBrokerClient(bc);
await closeBrokerServer(bs);
delete process.env.API_BASE_URL;
delete process.env.BROKER_SERVER_URL;
delete process.env.GITHUB_TOKEN;
delete process.env.GITHUB_TOKEN_POOL;
Expand All @@ -88,7 +93,7 @@ describe('proxy requests originating from behind the broker server with pooled c
});

it('successfully broker on endpoint that forwards requests with basic auth, using first credential', async () => {
const url = `http://localhost:${bs.port}/broker/${brokerTokens[0]}/basic-auth`;
const url = `http://localhost:${bs.port}/broker/brokertoken1/basic-auth`;

const response = await axiosClient.get(url, { timeout: 5000 });
const status = response.status;
Expand All @@ -101,23 +106,23 @@ describe('proxy requests originating from behind the broker server with pooled c
});

it('successfully broker on endpoint that forwards requests with token auth in origin, using first credential', async () => {
const url = `http://localhost:${bs.port}/broker/${brokerTokens[0]}/echo-headers/github-token-in-origin`;
const url = `http://localhost:${bs.port}/broker/brokertoken1/echo-headers/github-token-in-origin`;

const response = await axiosClient.post(url, {});
expect(response.status).toEqual(200);
expect(response.data.authorization).toEqual('token githubToken1');
});

it('successfully broker on endpoint that forwards requests with token auth in origin, using first credential again', async () => {
const url = `http://localhost:${bs.port}/broker/${brokerTokens[0]}/echo-headers/github`;
const url = `http://localhost:${bs.port}/broker/brokertoken1/echo-headers/github`;

const response = await axiosClient.post(url, {});
expect(response.status).toEqual(200);
expect(response.data.authorization).toEqual('token githubToken');
});

it('successfully broker on endpoint that forwards requests with token auth in origin, using token pool', async () => {
const url = `http://localhost:${bs.port}/broker/${brokerTokens[0]}/echo-headers/github-pool`;
const url = `http://localhost:${bs.port}/broker/brokertoken1/echo-headers/github-pool`;

const response = await axiosClient.post(url, {});
expect(response.status).toEqual(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
waitForUniversalBrokerClientsConnection,
} from '../setup/broker-server';
import { TestWebServer, createTestWebServer } from '../setup/test-web-server';
import { TestApiServer, createTestApiServer } from '../setup/test-api-server';
import { createUniversalBrokerClient } from '../setup/broker-universal-client';

import * as dispatcher from '../../lib/hybrid-sdk/server/infra/dispatcher';
Expand All @@ -20,6 +21,7 @@ const clientAccept = path.join(fixtures, 'client', 'filters.json');

describe('client send termination signal to broker server', () => {
let tws: TestWebServer;
let tas: TestApiServer;
let bs: BrokerServer;
let bc: BrokerClient;
const spyClientDisconnected = jest.spyOn(dispatcher, 'clientDisconnected');
Expand All @@ -36,11 +38,12 @@ describe('client send termination signal to broker server', () => {
beforeAll(async () => {
const PORT = 9999;
tws = await createTestWebServer();
tas = await createTestApiServer();
process.env.RESPONSE_DATA_HIDDEN_ENABLED = 'true';
bs = await createBrokerServer({ filters: serverAccept, port: PORT });

process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED = 'true';
process.env.API_BASE_URL = `http://localhost:${bs.port}`;
process.env.API_BASE_URL = `http://localhost:${tas.port}`;
process.env.UNIVERSAL_BROKER_ENABLED = 'true';
process.env.SERVICE_ENV = 'universaltest';
process.env.BROKER_TOKEN_1 = 'brokertoken1';
Expand Down Expand Up @@ -79,8 +82,10 @@ describe('client send termination signal to broker server', () => {
spyAddClientIdToTerminationMap.mockReset();
spyProcessExit.mockReset();
await tws.server.close();
await tas.server.close();
await closeBrokerClient(bc);
await closeBrokerServer(bs);
delete process.env.API_BASE_URL;
delete process.env.BROKER_SERVER_URL;
delete process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED;
delete process.env
Expand Down
7 changes: 6 additions & 1 deletion test/functional/server-client-universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
waitForUniversalBrokerClientsConnection,
} from '../setup/broker-server';
import { TestWebServer, createTestWebServer } from '../setup/test-web-server';
import { TestApiServer, createTestApiServer } from '../setup/test-api-server';
import { createUniversalBrokerClient } from '../setup/broker-universal-client';

const fixtures = path.resolve(__dirname, '..', 'fixtures');
Expand All @@ -16,6 +17,7 @@ const clientAccept = path.join(fixtures, 'client', 'filters.json');

describe('proxy requests originating from behind the broker server', () => {
let tws: TestWebServer;
let tas: TestApiServer;
let bs: BrokerServer;
let bc: BrokerClient;

Expand All @@ -28,11 +30,12 @@ describe('proxy requests originating from behind the broker server', () => {
beforeAll(async () => {
const PORT = 9999;
tws = await createTestWebServer();
tas = await createTestApiServer();
process.env.RESPONSE_DATA_HIDDEN_ENABLED = 'true';
bs = await createBrokerServer({ filters: serverAccept, port: PORT });

process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED = 'true';
process.env.API_BASE_URL = `http://localhost:${bs.port}`;
process.env.API_BASE_URL = `http://localhost:${tas.port}`;
process.env.UNIVERSAL_BROKER_ENABLED = 'true';
process.env.SERVICE_ENV = 'universaltest';
process.env.BROKER_TOKEN_1 = 'brokertoken1';
Expand Down Expand Up @@ -67,8 +70,10 @@ describe('proxy requests originating from behind the broker server', () => {
afterAll(async () => {
spyLogWarn.mockReset();
await tws.server.close();
await tas.server.close();
await closeBrokerClient(bc);
await closeBrokerServer(bs);
delete process.env.API_BASE_URL;
delete process.env.BROKER_SERVER_URL;
delete process.env.SNYK_BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED;
delete process.env
Expand Down
Loading