@tetrascience-npm/ts-connectors-sdk 3.2.0 → 4.0.0-beta.182.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +42 -3
- package/dist/api-tests/auth-token.test.js +25 -37
- package/dist/api-tests/auth-token.test.js.map +1 -1
- package/dist/api-tests/aws-timeout.test.d.ts +2 -0
- package/dist/api-tests/aws-timeout.test.d.ts.map +1 -0
- package/dist/api-tests/aws-timeout.test.js +251 -0
- package/dist/api-tests/aws-timeout.test.js.map +1 -0
- package/dist/api-tests/fixture/config.d.ts +4 -0
- package/dist/api-tests/fixture/config.d.ts.map +1 -1
- package/dist/api-tests/fixture/config.js +1 -0
- package/dist/api-tests/fixture/config.js.map +1 -1
- package/dist/api-tests/fixture/data-app-api.d.ts +60 -0
- package/dist/api-tests/fixture/data-app-api.d.ts.map +1 -0
- package/dist/api-tests/fixture/data-app-api.js +89 -0
- package/dist/api-tests/fixture/data-app-api.js.map +1 -0
- package/dist/api-tests/fixture/fixture.d.ts +1 -0
- package/dist/api-tests/fixture/fixture.d.ts.map +1 -1
- package/dist/api-tests/fixture/test-proxy-server.d.ts +74 -0
- package/dist/api-tests/fixture/test-proxy-server.d.ts.map +1 -0
- package/dist/api-tests/fixture/test-proxy-server.js +240 -0
- package/dist/api-tests/fixture/test-proxy-server.js.map +1 -0
- package/dist/src/auth/aws-client-provider.d.ts +2 -0
- package/dist/src/auth/aws-client-provider.d.ts.map +1 -1
- package/dist/src/auth/aws-env-client-provider.d.ts +7 -2
- package/dist/src/auth/aws-env-client-provider.d.ts.map +1 -1
- package/dist/src/auth/aws-env-client-provider.js +9 -6
- package/dist/src/auth/aws-env-client-provider.js.map +1 -1
- package/dist/src/auth/aws-refresh-client-provider.d.ts +8 -2
- package/dist/src/auth/aws-refresh-client-provider.d.ts.map +1 -1
- package/dist/src/auth/aws-refresh-client-provider.js +9 -6
- package/dist/src/auth/aws-refresh-client-provider.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/tdp-client.d.ts +46 -10
- package/dist/src/tdp-client.d.ts.map +1 -1
- package/dist/src/tdp-client.js +128 -40
- package/dist/src/tdp-client.js.map +1 -1
- package/dist/test/auth/aws-env-client-provider.test.js +6 -2
- package/dist/test/auth/aws-env-client-provider.test.js.map +1 -1
- package/dist/test/auth/aws-refresh-client-provider.test.js +6 -2
- package/dist/test/auth/aws-refresh-client-provider.test.js.map +1 -1
- package/dist/test/tdp-client.test.js +350 -7
- package/dist/test/tdp-client.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -53,6 +53,8 @@ const lib_storage_1 = require("@aws-sdk/lib-storage");
|
|
|
53
53
|
const node_http_handler_1 = require("@smithy/node-http-handler");
|
|
54
54
|
const aws_sdk_client_mock_1 = require("aws-sdk-client-mock");
|
|
55
55
|
const axios_1 = __importDefault(require("axios"));
|
|
56
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
57
|
+
const proxy_agent_1 = require("proxy-agent");
|
|
56
58
|
const constants_1 = require("../src/constants");
|
|
57
59
|
const uuid_1 = require("uuid");
|
|
58
60
|
const manifest = __importStar(require("../src/manifest"));
|
|
@@ -77,6 +79,14 @@ jest.mock('@aws-sdk/lib-storage', () => ({
|
|
|
77
79
|
describe('TDPClient', () => {
|
|
78
80
|
const axiosCreateSpy = jest.spyOn(axios_1.default, 'create');
|
|
79
81
|
beforeEach(() => {
|
|
82
|
+
// Delete CONNECTOR_TOKEN to prevent Logger from enabling CloudWatch buffering.
|
|
83
|
+
// When CloudWatch is enabled, Logger creates in-memory buffers and recurring timers
|
|
84
|
+
// that are never cleaned up between tests, causing memory leaks.
|
|
85
|
+
delete process.env.CONNECTOR_TOKEN;
|
|
86
|
+
// Delete OUTBOUND_COMMAND_QUEUE to prevent test behavior from varying based on environment.
|
|
87
|
+
// When set, this can trigger different code paths or resource allocation patterns
|
|
88
|
+
// that may accumulate memory across tests.
|
|
89
|
+
delete process.env.OUTBOUND_COMMAND_QUEUE;
|
|
80
90
|
sqsClientMock.reset();
|
|
81
91
|
s3ClientMock.reset();
|
|
82
92
|
mockUploadFileRequestSchemaParse.mockReset();
|
|
@@ -131,11 +141,16 @@ describe('TDPClient', () => {
|
|
|
131
141
|
connectorId: 'test-connector-id',
|
|
132
142
|
tdpEndpoint: 'https://tdp.example.com',
|
|
133
143
|
});
|
|
134
|
-
const
|
|
135
|
-
.
|
|
136
|
-
|
|
144
|
+
const mockHandlers = {
|
|
145
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
146
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
147
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
148
|
+
};
|
|
149
|
+
const createProxyAWSNodeHttpHandlersSpy = jest
|
|
150
|
+
.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers')
|
|
151
|
+
.mockReturnValue(mockHandlers);
|
|
137
152
|
yield tdpClient.init();
|
|
138
|
-
expect(
|
|
153
|
+
expect(createProxyAWSNodeHttpHandlersSpy).toHaveBeenCalled();
|
|
139
154
|
expect(tdpClient['awsClientProvider']).toBeInstanceOf(src_1.AwsRefreshClientProvider);
|
|
140
155
|
expect(tdpClient['authTokenProvider']).toBeInstanceOf(src_1.UserSuppliedAuthTokenProvider);
|
|
141
156
|
expect(tdpClient['authTokenProvider']).toEqual(expect.objectContaining({
|
|
@@ -197,7 +212,12 @@ describe('TDPClient', () => {
|
|
|
197
212
|
connectorId: 'test-connector-id',
|
|
198
213
|
tdpEndpoint: 'https://tdp.example.com',
|
|
199
214
|
});
|
|
200
|
-
|
|
215
|
+
const mockHandlers = {
|
|
216
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
217
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
218
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
219
|
+
};
|
|
220
|
+
jest.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers').mockReturnValue(mockHandlers);
|
|
201
221
|
yield tdpClient.init();
|
|
202
222
|
// First, should load local certs for AWS bootstrap
|
|
203
223
|
expect(loadCertificatesFromLocalVolumeSpy).toHaveBeenCalled();
|
|
@@ -206,6 +226,57 @@ describe('TDPClient', () => {
|
|
|
206
226
|
// AWS should be initialized
|
|
207
227
|
expect(tdpClient['isAwsInitialized']).toBe(true);
|
|
208
228
|
}));
|
|
229
|
+
it('should store deployment certificates on the instance during Priority 1 init', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
230
|
+
jest.spyOn(certificates, 'loadCertificatesFromLocalVolume').mockResolvedValue(['local-deploy-cert']);
|
|
231
|
+
const tdpClient = new src_1.TDPClient({
|
|
232
|
+
orgSlug: 'test-org',
|
|
233
|
+
awsRegion: 'us-west-2',
|
|
234
|
+
connectorId: 'test-connector-id',
|
|
235
|
+
tdpEndpoint: 'https://tdp.example.com',
|
|
236
|
+
authToken: 'direct-auth-token',
|
|
237
|
+
});
|
|
238
|
+
yield tdpClient.init();
|
|
239
|
+
expect(tdpClient.tdpDeploymentCertificates).toEqual(['local-deploy-cert']);
|
|
240
|
+
}));
|
|
241
|
+
it('should store deployment certificates on the instance during Priority 2 init (full S3 load)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
+
process.env.CONNECTOR_TOKEN = 'test-connector-token';
|
|
243
|
+
process.env.SKIP_CLOUDWATCH = 'true';
|
|
244
|
+
jest.spyOn(certificates, 'loadCertificatesFromLocalVolume').mockResolvedValue(['local-cert']);
|
|
245
|
+
jest.spyOn(certificates, 'loadTdpCertificates').mockResolvedValue(['s3-full-cert']);
|
|
246
|
+
const tdpClient = new src_1.TDPClient({
|
|
247
|
+
orgSlug: 'test-org',
|
|
248
|
+
awsRegion: 'us-west-2',
|
|
249
|
+
connectorId: 'test-connector-id',
|
|
250
|
+
tdpEndpoint: 'https://tdp.example.com',
|
|
251
|
+
});
|
|
252
|
+
jest.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers').mockReturnValue({
|
|
253
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
254
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
255
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
256
|
+
});
|
|
257
|
+
yield tdpClient.init();
|
|
258
|
+
// Should have the full S3 load, not just local certs
|
|
259
|
+
expect(tdpClient.tdpDeploymentCertificates).toEqual(['s3-full-cert']);
|
|
260
|
+
}));
|
|
261
|
+
it('should store empty deployment certificates when no certs are found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
262
|
+
jest.spyOn(certificates, 'loadCertificatesFromLocalVolume').mockResolvedValue([]);
|
|
263
|
+
const tdpClient = new src_1.TDPClient({
|
|
264
|
+
orgSlug: 'test-org',
|
|
265
|
+
awsRegion: 'us-west-2',
|
|
266
|
+
connectorId: 'test-connector-id',
|
|
267
|
+
tdpEndpoint: 'https://tdp.example.com',
|
|
268
|
+
authToken: 'direct-auth-token',
|
|
269
|
+
});
|
|
270
|
+
yield tdpClient.init();
|
|
271
|
+
expect(tdpClient.tdpDeploymentCertificates).toEqual([]);
|
|
272
|
+
}));
|
|
273
|
+
it('should return empty deployment certificates before init is called', () => {
|
|
274
|
+
const tdpClient = new src_1.TDPClient({
|
|
275
|
+
orgSlug: 'test-org',
|
|
276
|
+
tdpEndpoint: 'https://tdp.example.com',
|
|
277
|
+
});
|
|
278
|
+
expect(tdpClient.tdpDeploymentCertificates).toEqual([]);
|
|
279
|
+
});
|
|
209
280
|
it('should initialize AwsEnvClientProvider and AwsSecretAuthTokenProvider for AWS env flow (Priority 3)', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
281
|
// Clear CONNECTOR_TOKEN to trigger Priority 3 path
|
|
211
282
|
delete process.env.CONNECTOR_TOKEN;
|
|
@@ -217,7 +288,12 @@ describe('TDPClient', () => {
|
|
|
217
288
|
tdpEndpoint: 'https://tdp.example.com',
|
|
218
289
|
jwtTokenParameter: '/test/jwt-param',
|
|
219
290
|
});
|
|
220
|
-
|
|
291
|
+
const mockHandlers = {
|
|
292
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
293
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
294
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
295
|
+
};
|
|
296
|
+
jest.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers').mockReturnValue(mockHandlers);
|
|
221
297
|
yield tdpClient.init();
|
|
222
298
|
// Should use AwsEnvClientProvider
|
|
223
299
|
expect(tdpClient['awsClientProvider']).toBeInstanceOf(src_1.AwsEnvClientProvider);
|
|
@@ -228,6 +304,41 @@ describe('TDPClient', () => {
|
|
|
228
304
|
// JWT should be retrieved from SSM
|
|
229
305
|
expect(tdpClient['jwt']).toBe('jwt-secret');
|
|
230
306
|
}));
|
|
307
|
+
it('should only initialize AWS once when concurrent operations trigger lazy init', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
308
|
+
delete process.env.CONNECTOR_TOKEN;
|
|
309
|
+
jest.spyOn(certificates, 'loadCertificatesFromLocalVolume').mockResolvedValue([]);
|
|
310
|
+
const tdpClient = new src_1.TDPClient({
|
|
311
|
+
orgSlug: 'test-org',
|
|
312
|
+
awsRegion: 'us-west-2',
|
|
313
|
+
connectorId: 'test-connector-id',
|
|
314
|
+
tdpEndpoint: 'https://tdp.example.com',
|
|
315
|
+
authToken: 'direct-auth-token',
|
|
316
|
+
});
|
|
317
|
+
const mockHandlers = {
|
|
318
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
319
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
320
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
321
|
+
};
|
|
322
|
+
jest.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers').mockReturnValue(mockHandlers);
|
|
323
|
+
yield tdpClient.init();
|
|
324
|
+
// Verify AWS is NOT initialized yet (deferred due to authToken)
|
|
325
|
+
expect(tdpClient['isAwsInitialized']).toBe(false);
|
|
326
|
+
expect(tdpClient['awsClientProvider']).toBeUndefined();
|
|
327
|
+
// Spy on the private doInitAws method to count invocations
|
|
328
|
+
const doInitAwsSpy = jest.spyOn(tdpClient, 'doInitAws');
|
|
329
|
+
// Trigger multiple concurrent calls to assertAwsInitialized (simulating concurrent uploads)
|
|
330
|
+
const concurrentCalls = [
|
|
331
|
+
tdpClient.assertAwsInitialized(),
|
|
332
|
+
tdpClient.assertAwsInitialized(),
|
|
333
|
+
tdpClient.assertAwsInitialized(),
|
|
334
|
+
];
|
|
335
|
+
yield Promise.all(concurrentCalls);
|
|
336
|
+
// doInitAws should only be called once despite concurrent calls
|
|
337
|
+
expect(doInitAwsSpy).toHaveBeenCalledTimes(1);
|
|
338
|
+
// AWS should now be initialized
|
|
339
|
+
expect(tdpClient['isAwsInitialized']).toBe(true);
|
|
340
|
+
expect(tdpClient['awsClientProvider']).toBeInstanceOf(src_1.AwsEnvClientProvider);
|
|
341
|
+
}));
|
|
231
342
|
it('should use custom authTokenProvider when provided in AWS env flow', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
232
343
|
delete process.env.CONNECTOR_TOKEN;
|
|
233
344
|
jest.spyOn(certificates, 'loadTdpCertificates').mockResolvedValue([]);
|
|
@@ -239,7 +350,12 @@ describe('TDPClient', () => {
|
|
|
239
350
|
tdpEndpoint: 'https://tdp.example.com',
|
|
240
351
|
authTokenProvider: customAuthTokenProvider,
|
|
241
352
|
});
|
|
242
|
-
|
|
353
|
+
const mockHandlers = {
|
|
354
|
+
s3Handler: new node_http_handler_1.NodeHttpHandler(),
|
|
355
|
+
sqsHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
356
|
+
genericHandler: new node_http_handler_1.NodeHttpHandler(),
|
|
357
|
+
};
|
|
358
|
+
jest.spyOn(tdpClient, 'createProxyAWSNodeHttpHandlers').mockReturnValue(mockHandlers);
|
|
243
359
|
yield tdpClient.init();
|
|
244
360
|
// Should use the custom auth token provider
|
|
245
361
|
expect(tdpClient['authTokenProvider']).toBe(customAuthTokenProvider);
|
|
@@ -916,6 +1032,55 @@ describe('TDPClient', () => {
|
|
|
916
1032
|
],
|
|
917
1033
|
});
|
|
918
1034
|
}));
|
|
1035
|
+
it('should include TDP deployment certificates when includeAdditionalCertificates is true', () => {
|
|
1036
|
+
const client = new src_1.TDPClient();
|
|
1037
|
+
client._tdpDeploymentCertificates = ['deploy-cert-1', 'deploy-cert-2'];
|
|
1038
|
+
jest.spyOn(client, 'certificates', 'get').mockImplementation(() => []);
|
|
1039
|
+
client.assertProxyInitialized = jest.fn(() => true);
|
|
1040
|
+
client.logger = { debug: jest.fn(), info: jest.fn() };
|
|
1041
|
+
client.createProxyAgentsForBaseUrl({
|
|
1042
|
+
baseUrl: 'https://example.com',
|
|
1043
|
+
includeAdditionalCertificates: true,
|
|
1044
|
+
});
|
|
1045
|
+
expect(client.logger.info).toHaveBeenCalledWith('Using 2 TDP deployment certificates');
|
|
1046
|
+
});
|
|
1047
|
+
it('should include TDP deployment certificates when includeAdditionalCertificates is a string array', () => {
|
|
1048
|
+
const client = new src_1.TDPClient();
|
|
1049
|
+
client._tdpDeploymentCertificates = ['deploy-cert-1'];
|
|
1050
|
+
jest.spyOn(client, 'certificates', 'get').mockImplementation(() => []);
|
|
1051
|
+
client.assertProxyInitialized = jest.fn(() => true);
|
|
1052
|
+
client.logger = { debug: jest.fn(), info: jest.fn() };
|
|
1053
|
+
client.createProxyAgentsForBaseUrl({
|
|
1054
|
+
baseUrl: 'https://example.com',
|
|
1055
|
+
includeAdditionalCertificates: ['extra-cert'],
|
|
1056
|
+
});
|
|
1057
|
+
expect(client.logger.info).toHaveBeenCalledWith('Using 1 TDP deployment certificates');
|
|
1058
|
+
expect(client.logger.info).toHaveBeenCalledWith('Using 1 additional certificates');
|
|
1059
|
+
});
|
|
1060
|
+
it('should NOT include TDP deployment certificates when includeAdditionalCertificates is false', () => {
|
|
1061
|
+
const client = new src_1.TDPClient();
|
|
1062
|
+
client._tdpDeploymentCertificates = ['deploy-cert-1'];
|
|
1063
|
+
client.assertProxyInitialized = jest.fn(() => true);
|
|
1064
|
+
client.logger = { debug: jest.fn(), info: jest.fn() };
|
|
1065
|
+
client.createProxyAgentsForBaseUrl({
|
|
1066
|
+
baseUrl: 'https://example.com',
|
|
1067
|
+
includeAdditionalCertificates: false,
|
|
1068
|
+
});
|
|
1069
|
+
expect(client.logger.info).not.toHaveBeenCalledWith(expect.stringContaining('TDP deployment certificates'));
|
|
1070
|
+
});
|
|
1071
|
+
it('should handle empty deployment certificates gracefully', () => {
|
|
1072
|
+
const client = new src_1.TDPClient();
|
|
1073
|
+
// _tdpDeploymentCertificates defaults to [] in constructor
|
|
1074
|
+
jest.spyOn(client, 'certificates', 'get').mockImplementation(() => []);
|
|
1075
|
+
client.assertProxyInitialized = jest.fn(() => true);
|
|
1076
|
+
client.logger = { debug: jest.fn(), info: jest.fn() };
|
|
1077
|
+
client.createProxyAgentsForBaseUrl({
|
|
1078
|
+
baseUrl: 'https://example.com',
|
|
1079
|
+
includeAdditionalCertificates: true,
|
|
1080
|
+
});
|
|
1081
|
+
// Should not log deployment certs when there are none
|
|
1082
|
+
expect(client.logger.info).not.toHaveBeenCalledWith(expect.stringContaining('TDP deployment certificates'));
|
|
1083
|
+
});
|
|
919
1084
|
});
|
|
920
1085
|
describe('sanitizeConfig', () => {
|
|
921
1086
|
it("removes risky keys like headers, data, and auth from the config's axios config", () => {
|
|
@@ -1233,6 +1398,14 @@ describe('TDPClient', () => {
|
|
|
1233
1398
|
tdpClient.createAxiosInstanceWithCertificatesAndHeaders(tdpEndpoint, orgSlug, jwt, certificates);
|
|
1234
1399
|
expect(tdpClient.createProxyAgentsForBaseUrl).toHaveBeenCalledWith(expect.objectContaining({ includeAdditionalCertificates: certificates }));
|
|
1235
1400
|
});
|
|
1401
|
+
it('should use includeAdditionalCertificates: true when certificates param is omitted', () => {
|
|
1402
|
+
tdpClient.createAxiosInstanceWithCertificatesAndHeaders(tdpEndpoint, orgSlug, jwt);
|
|
1403
|
+
expect(tdpClient.createProxyAgentsForBaseUrl).toHaveBeenCalledWith(expect.objectContaining({ includeAdditionalCertificates: true }));
|
|
1404
|
+
});
|
|
1405
|
+
it('should use includeAdditionalCertificates: true when certificates param is undefined', () => {
|
|
1406
|
+
tdpClient.createAxiosInstanceWithCertificatesAndHeaders(tdpEndpoint, orgSlug, jwt, undefined);
|
|
1407
|
+
expect(tdpClient.createProxyAgentsForBaseUrl).toHaveBeenCalledWith(expect.objectContaining({ includeAdditionalCertificates: true }));
|
|
1408
|
+
});
|
|
1236
1409
|
it('should set the correct headers', () => {
|
|
1237
1410
|
const axiosCreateSpy = jest.spyOn(axios_1.default, 'create');
|
|
1238
1411
|
tdpClient.createAxiosInstanceWithCertificatesAndHeaders(tdpEndpoint, orgSlug, jwt, certificates);
|
|
@@ -1314,5 +1487,175 @@ describe('TDPClient', () => {
|
|
|
1314
1487
|
}));
|
|
1315
1488
|
}));
|
|
1316
1489
|
});
|
|
1490
|
+
describe('AWS Timeout Configuration', () => {
|
|
1491
|
+
it('should create three separate handlers for S3, SQS, and generic AWS services', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1492
|
+
const tdpClient = new src_1.TDPClient({
|
|
1493
|
+
orgSlug: 'tetrascience',
|
|
1494
|
+
awsRegion: 'us-east-2',
|
|
1495
|
+
connectorId: 'test-connector-id',
|
|
1496
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1497
|
+
});
|
|
1498
|
+
yield tdpClient.init();
|
|
1499
|
+
const handlers = tdpClient.createProxyAWSNodeHttpHandlers();
|
|
1500
|
+
expect(handlers).toHaveProperty('s3Handler');
|
|
1501
|
+
expect(handlers).toHaveProperty('sqsHandler');
|
|
1502
|
+
expect(handlers).toHaveProperty('genericHandler');
|
|
1503
|
+
expect(handlers.s3Handler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1504
|
+
expect(handlers.sqsHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1505
|
+
expect(handlers.genericHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1506
|
+
}));
|
|
1507
|
+
it('should configure handlers with appropriate timeout values', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1508
|
+
const tdpClient = new src_1.TDPClient({
|
|
1509
|
+
orgSlug: 'tetrascience',
|
|
1510
|
+
awsRegion: 'us-east-2',
|
|
1511
|
+
connectorId: 'test-connector-id',
|
|
1512
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1513
|
+
});
|
|
1514
|
+
yield tdpClient.init();
|
|
1515
|
+
const handlers = tdpClient.createProxyAWSNodeHttpHandlers();
|
|
1516
|
+
// Verify all three handlers are created
|
|
1517
|
+
expect(handlers.s3Handler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1518
|
+
expect(handlers.sqsHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1519
|
+
expect(handlers.genericHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1520
|
+
// Verify that the handlers are distinct instances (not the same object)
|
|
1521
|
+
expect(handlers.s3Handler).not.toBe(handlers.sqsHandler);
|
|
1522
|
+
expect(handlers.s3Handler).not.toBe(handlers.genericHandler);
|
|
1523
|
+
expect(handlers.sqsHandler).not.toBe(handlers.genericHandler);
|
|
1524
|
+
// Note: The actual timeout values are configured in createProxyAWSNodeHttpHandlers():
|
|
1525
|
+
// - S3 handler: connectionTimeout: 10000ms, socketTimeout: 10000ms
|
|
1526
|
+
// - SQS handler: requestTimeout: 20000ms, throwOnRequestTimeout: true
|
|
1527
|
+
// - Generic handler: requestTimeout: 120000ms, throwOnRequestTimeout: true
|
|
1528
|
+
//
|
|
1529
|
+
// These values are not publicly accessible from the NodeHttpHandler instances,
|
|
1530
|
+
// but the timeout behavior is tested in the integration tests (api-tests/aws-timeout.test.ts).
|
|
1531
|
+
}));
|
|
1532
|
+
});
|
|
1533
|
+
describe('createAwsClient()', () => {
|
|
1534
|
+
it('should throw if called before init()', () => {
|
|
1535
|
+
const tdpClient = new src_1.TDPClient({
|
|
1536
|
+
orgSlug: 'tetrascience',
|
|
1537
|
+
awsRegion: 'us-east-2',
|
|
1538
|
+
connectorId: 'test-connector-id',
|
|
1539
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1540
|
+
});
|
|
1541
|
+
expect(() => tdpClient.createAwsClient(s3.S3Client)).toThrow('AWS not initialized. Call init() first.');
|
|
1542
|
+
});
|
|
1543
|
+
it('should return a client of the requested type with the configured region', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1544
|
+
const tdpClient = new src_1.TDPClient({
|
|
1545
|
+
orgSlug: 'tetrascience',
|
|
1546
|
+
awsRegion: 'us-east-2',
|
|
1547
|
+
connectorId: 'test-connector-id',
|
|
1548
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1549
|
+
});
|
|
1550
|
+
yield tdpClient.init();
|
|
1551
|
+
const client = tdpClient.createAwsClient(s3.S3Client);
|
|
1552
|
+
expect(client).toBeInstanceOf(s3.S3Client);
|
|
1553
|
+
}));
|
|
1554
|
+
it('should apply overrides when provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1555
|
+
const tdpClient = new src_1.TDPClient({
|
|
1556
|
+
orgSlug: 'tetrascience',
|
|
1557
|
+
awsRegion: 'us-east-2',
|
|
1558
|
+
connectorId: 'test-connector-id',
|
|
1559
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1560
|
+
});
|
|
1561
|
+
yield tdpClient.init();
|
|
1562
|
+
const client = tdpClient.createAwsClient(s3.S3Client, { region: 'eu-west-1' });
|
|
1563
|
+
expect(client).toBeInstanceOf(s3.S3Client);
|
|
1564
|
+
yield expect(client.config.region()).resolves.toBe('eu-west-1');
|
|
1565
|
+
}));
|
|
1566
|
+
it('should not pass credentials when using AwsEnvClientProvider', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1567
|
+
const tdpClient = new src_1.TDPClient({
|
|
1568
|
+
orgSlug: 'tetrascience',
|
|
1569
|
+
awsRegion: 'us-east-2',
|
|
1570
|
+
connectorId: 'test-connector-id',
|
|
1571
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1572
|
+
});
|
|
1573
|
+
yield tdpClient.init();
|
|
1574
|
+
expect(tdpClient['awsClientProvider']).toBeInstanceOf(src_1.AwsEnvClientProvider);
|
|
1575
|
+
expect(tdpClient['awsClientProvider'].getCredentialsProvider()).toBeUndefined();
|
|
1576
|
+
}));
|
|
1577
|
+
});
|
|
1578
|
+
describe('IAM_PROXY support', () => {
|
|
1579
|
+
let tdpClient;
|
|
1580
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
1581
|
+
delete process.env.IAM_PROXY;
|
|
1582
|
+
tdpClient = new src_1.TDPClient({
|
|
1583
|
+
orgSlug: 'tetrascience',
|
|
1584
|
+
awsRegion: 'us-east-2',
|
|
1585
|
+
connectorId: 'test-connector-id',
|
|
1586
|
+
authTokenProvider: new src_1.PredefinedAuthTokenProvider('test-token'),
|
|
1587
|
+
});
|
|
1588
|
+
yield tdpClient.init();
|
|
1589
|
+
}));
|
|
1590
|
+
afterEach(() => {
|
|
1591
|
+
delete process.env.IAM_PROXY;
|
|
1592
|
+
});
|
|
1593
|
+
it('should use ProxyAgent when IAM_PROXY is not set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1594
|
+
const handlers = tdpClient.createProxyAWSNodeHttpHandlers();
|
|
1595
|
+
expect(handlers.s3Handler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1596
|
+
expect(handlers.sqsHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1597
|
+
expect(handlers.genericHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1598
|
+
// configProvider resolves synchronously for plain-object options
|
|
1599
|
+
const s3Config = yield handlers.s3Handler.configProvider;
|
|
1600
|
+
expect(s3Config.httpAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1601
|
+
expect(s3Config.httpsAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1602
|
+
const sqsConfig = yield handlers.sqsHandler.configProvider;
|
|
1603
|
+
expect(sqsConfig.httpAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1604
|
+
expect(sqsConfig.httpsAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1605
|
+
const genericConfig = yield handlers.genericHandler.configProvider;
|
|
1606
|
+
expect(genericConfig.httpAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1607
|
+
expect(genericConfig.httpsAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1608
|
+
}));
|
|
1609
|
+
it('should use HttpsProxyAgent when IAM_PROXY is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1610
|
+
process.env.IAM_PROXY = 'http://iam-proxy.example.com:8080';
|
|
1611
|
+
const handlers = tdpClient.createProxyAWSNodeHttpHandlers();
|
|
1612
|
+
expect(handlers.s3Handler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1613
|
+
expect(handlers.sqsHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1614
|
+
expect(handlers.genericHandler).toBeInstanceOf(node_http_handler_1.NodeHttpHandler);
|
|
1615
|
+
const s3Config = yield handlers.s3Handler.configProvider;
|
|
1616
|
+
expect(s3Config.httpAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1617
|
+
expect(s3Config.httpsAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1618
|
+
const sqsConfig = yield handlers.sqsHandler.configProvider;
|
|
1619
|
+
expect(sqsConfig.httpAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1620
|
+
expect(sqsConfig.httpsAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1621
|
+
const genericConfig = yield handlers.genericHandler.configProvider;
|
|
1622
|
+
expect(genericConfig.httpAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1623
|
+
expect(genericConfig.httpsAgent).toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1624
|
+
}));
|
|
1625
|
+
it('should not use HttpsProxyAgent when IAM_PROXY is unset', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1626
|
+
delete process.env.IAM_PROXY;
|
|
1627
|
+
const handlers = tdpClient.createProxyAWSNodeHttpHandlers();
|
|
1628
|
+
const s3Config = yield handlers.s3Handler.configProvider;
|
|
1629
|
+
expect(s3Config.httpAgent).not.toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1630
|
+
expect(s3Config.httpsAgent).not.toBeInstanceOf(https_proxy_agent_1.HttpsProxyAgent);
|
|
1631
|
+
expect(s3Config.httpAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1632
|
+
expect(s3Config.httpsAgent).toBeInstanceOf(proxy_agent_1.ProxyAgent);
|
|
1633
|
+
}));
|
|
1634
|
+
});
|
|
1635
|
+
describe('shouldRejectUnauthorized', () => {
|
|
1636
|
+
const envBackup = process.env;
|
|
1637
|
+
afterEach(() => {
|
|
1638
|
+
process.env = Object.assign({}, envBackup);
|
|
1639
|
+
});
|
|
1640
|
+
it('should be importable from the public SDK API', () => {
|
|
1641
|
+
expect(typeof src_1.shouldRejectUnauthorized).toBe('function');
|
|
1642
|
+
});
|
|
1643
|
+
it('should return true when NODE_TLS_REJECT_UNAUTHORIZED is not set', () => {
|
|
1644
|
+
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
|
|
1645
|
+
expect((0, src_1.shouldRejectUnauthorized)()).toBe(true);
|
|
1646
|
+
});
|
|
1647
|
+
it('should return false when NODE_TLS_REJECT_UNAUTHORIZED is "0"', () => {
|
|
1648
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
1649
|
+
expect((0, src_1.shouldRejectUnauthorized)()).toBe(false);
|
|
1650
|
+
});
|
|
1651
|
+
it('should return false when NODE_TLS_REJECT_UNAUTHORIZED is "false"', () => {
|
|
1652
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 'false';
|
|
1653
|
+
expect((0, src_1.shouldRejectUnauthorized)()).toBe(false);
|
|
1654
|
+
});
|
|
1655
|
+
it('should return true when NODE_TLS_REJECT_UNAUTHORIZED is "1"', () => {
|
|
1656
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
|
|
1657
|
+
expect((0, src_1.shouldRejectUnauthorized)()).toBe(true);
|
|
1658
|
+
});
|
|
1659
|
+
});
|
|
1317
1660
|
});
|
|
1318
1661
|
//# sourceMappingURL=tdp-client.test.js.map
|