@envoy/envoy-integrations-sdk 1.3.4 → 1.3.5

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/lib/EnvoyAPI.js CHANGED
@@ -536,7 +536,7 @@ class EnvoyAPI {
536
536
  method: error.request?.method ?? error.options?.method,
537
537
  stack: error.stack,
538
538
  }
539
- return Promise.reject(safeError)
539
+ throw safeError;
540
540
  }
541
541
  }
542
542
 
package/lib/axios.js CHANGED
@@ -10,12 +10,19 @@ function createAxiosClient(config) {
10
10
  (error) => {
11
11
  const safeError = {
12
12
  code: error.code,
13
+ response: {
14
+ code: error.response?.code,
15
+ status: error.response?.status,
16
+ statusText: error.response?.statusText,
17
+ data: error.response?.data,
18
+ },
13
19
  message: error.message,
14
20
  name: error.name,
15
21
  baseURL: error.request?.baseURL ?? error.config?.baseURL,
16
22
  url: error.request?.url ?? error.config?.url,
17
23
  method: error.request?.method ?? error.config?.method,
18
24
  stack: error.stack,
25
+ data: error.data,
19
26
  }
20
27
  return Promise.reject(safeError);
21
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envoy/envoy-integrations-sdk",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,82 @@
1
+ const request = require('request-promise-native');
2
+ const EnvoyAPI = require('../lib/EnvoyAPI');
3
+
4
+ describe('request-promise-native', () => {
5
+ it('default client should leak credentials in error', async () => {
6
+ const client = request.defaults({
7
+ headers: {
8
+ Authorization: 'Bearer 1234',
9
+ },
10
+ });
11
+ try {
12
+ await client('http://localhost:3000/axios-error');
13
+ } catch (error) {
14
+ expect(error.options).toBeDefined();
15
+ const errorStr = JSON.stringify(error);
16
+ expect(errorStr).toContain('Bearer 1234');
17
+ }
18
+ });
19
+
20
+ it('should sanitize requests error response', async () => {
21
+ const client = request.defaults({
22
+ headers: {
23
+ Authorization: 'Bearer 1234',
24
+ },
25
+ });
26
+ try {
27
+ await client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
28
+ } catch (error) {
29
+ expect(error.options).toBeUndefined();
30
+ expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
31
+ expect(error.name).toBe('RequestError');
32
+ const errorStr = JSON.stringify(error);
33
+ expect(errorStr).not.toContain('Bearer 1234');
34
+ }
35
+ });
36
+
37
+ it('should return rejected promise and leak credentials', () => {
38
+ const client = request.defaults({
39
+ headers: {
40
+ Authorization: 'Bearer 1234',
41
+ },
42
+ });
43
+ const response = client('http://localhost:3000/axios-error');
44
+ response.then((data) => {
45
+ expect(false).toBe(true);
46
+ }).catch((error) => {
47
+ expect(error.options).toBeDefined();
48
+ const errorStr = JSON.stringify(error);
49
+ expect(errorStr).toContain('Bearer 1234');
50
+ });
51
+ });
52
+
53
+ it('should return rejected promise', () => {
54
+ const client = request.defaults({
55
+ headers: {
56
+ Authorization: 'Bearer 1234',
57
+ },
58
+ });
59
+ const response = client('http://localhost:3000/axios-error').catch(EnvoyAPI.safeRequestsError);
60
+ response.then((data) => {
61
+ expect(false).toBe(true);
62
+ }).catch((error) => {
63
+ expect(error.message).toBe('Error: connect ECONNREFUSED 127.0.0.1:3000');
64
+ expect(error.name).toBe('RequestError');
65
+ const errorStr = JSON.stringify(error);
66
+ expect(errorStr).not.toContain('Bearer 1234');
67
+ });
68
+ });
69
+
70
+ it('should make a successful request', async () => {
71
+ const response = await request('https://httpstat.us/200').catch(EnvoyAPI.safeRequestsError);
72
+ expect(response).toBe('200 OK');
73
+ });
74
+
75
+ it('should throw an error', async () => {
76
+ try {
77
+ await request('https://httpstat.us/500').catch(EnvoyAPI.safeRequestsError);
78
+ } catch (error) {
79
+ expect(error.message).toBe('500 - "500 Internal Server Error"');
80
+ }
81
+ });
82
+ });