@envoy/envoy-integrations-sdk 1.3.4 → 1.4.0
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 +1 -1
- package/lib/EnvoyPluginStorage.js +12 -0
- package/lib/EnvoyPluginStoragePipeline.js +13 -0
- package/lib/axios.js +7 -0
- package/package.json +1 -1
- package/test/promises.test.js +82 -0
package/lib/EnvoyAPI.js
CHANGED
|
@@ -104,6 +104,18 @@ class EnvoyPluginStorage {
|
|
|
104
104
|
|
|
105
105
|
return this.pipeline().unset(key).executeSingle();
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Wrapper for single pipeline update.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} key
|
|
112
|
+
* @param {*} value
|
|
113
|
+
* @returns {Promise<PluginStorageItem>}
|
|
114
|
+
*/
|
|
115
|
+
update(key, value) {
|
|
116
|
+
|
|
117
|
+
return this.pipeline().update(key, value).executeSingle();
|
|
118
|
+
}
|
|
107
119
|
}
|
|
108
120
|
|
|
109
121
|
module.exports = EnvoyPluginStorage;
|
|
@@ -137,6 +137,19 @@ class EnvoyPluginStoragePipeline {
|
|
|
137
137
|
|
|
138
138
|
return this.addCommand({ action: 'unset', key });
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Updates a value for a storage item,
|
|
143
|
+
* and returns that item.
|
|
144
|
+
*
|
|
145
|
+
* @param {string} key
|
|
146
|
+
* @param value
|
|
147
|
+
* @returns {EnvoyPluginStoragePipeline}
|
|
148
|
+
*/
|
|
149
|
+
update(key, value) {
|
|
150
|
+
|
|
151
|
+
return this.addCommand({ action: 'update', key, value });
|
|
152
|
+
}
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
module.exports = EnvoyPluginStoragePipeline;
|
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
|
@@ -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
|
+
});
|