|
1 | 1 | const sinon = require('sinon'); |
2 | 2 | const formatDate = require("date-fns").format; |
3 | 3 | const subDate = require("date-fns").sub; |
| 4 | +const https = require('https'); |
| 5 | +const ProxyAgent = require('proxy-agent'); |
4 | 6 | const ClientRequest = require('_http_client').ClientRequest; |
5 | 7 | const Q = require('q'); |
6 | 8 | const cloudinary = require("../../../../cloudinary"); |
@@ -124,7 +126,7 @@ describe("api", function () { |
124 | 126 | ]).finally(function () {}); |
125 | 127 | }); |
126 | 128 | after(function () { |
127 | | - var config = cloudinary.config(); |
| 129 | + var config = cloudinary.config(true); |
128 | 130 | this.timeout(TIMEOUT.LONG); |
129 | 131 | if (config.keep_test_products) { |
130 | 132 | return Promise.resolve(); |
@@ -1335,4 +1337,29 @@ describe("api", function () { |
1335 | 1337 | expect(resource.access_mode).to.be('public'); |
1336 | 1338 | })); |
1337 | 1339 | }); |
| 1340 | + describe("proxy support", function () { |
| 1341 | + const mocked = helper.mockTest(); |
| 1342 | + it("should support proxy for api calls", function () { |
| 1343 | + cloudinary.config({api_proxy: "https://myuser:[email protected]"}); |
| 1344 | + cloudinary.v2.api.resources({}); |
| 1345 | + sinon.assert.calledWith(mocked.request, sinon.match( |
| 1346 | + arg => arg.agent instanceof ProxyAgent |
| 1347 | + )); |
| 1348 | + }); |
| 1349 | + it("should prioritize custom agent", function () { |
| 1350 | + cloudinary.config({api_proxy: "https://myuser:[email protected]"}); |
| 1351 | + const custom_agent = https.Agent() |
| 1352 | + cloudinary.v2.api.resources({agent: custom_agent}); |
| 1353 | + sinon.assert.calledWith(mocked.request, sinon.match( |
| 1354 | + arg => arg.agent === custom_agent |
| 1355 | + )); |
| 1356 | + }); |
| 1357 | + it("should support api_proxy as options key", function () { |
| 1358 | + cloudinary.config({}); |
| 1359 | + cloudinary.v2.api.resources({api_proxy: "https://myuser:[email protected]"}); |
| 1360 | + sinon.assert.calledWith(mocked.request, sinon.match( |
| 1361 | + arg => arg.agent instanceof ProxyAgent |
| 1362 | + )); |
| 1363 | + }); |
| 1364 | + }) |
1338 | 1365 | }); |
0 commit comments