Skip to content
Merged
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
76 changes: 76 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"http-proxy": "^1.18.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.4",
Expand Down
75 changes: 75 additions & 0 deletions tests/e2e/proxy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const { expect } = require('chai');
const sinon = require('sinon');
const httpProxy = require('http-proxy');
const https = require('https');
const config = require('./utils/config');
const { DBSQLClient } = require('../..');

class HttpProxyMock {
constructor(target, port) {
this.requests = [];

this.config = {
protocol: 'http',
host: 'localhost',
port,
};

this.target = `https://${config.host}`;

this.proxy = httpProxy.createServer({
target: this.target,
agent: new https.Agent({
rejectUnauthorized: false,
}),
});

this.proxy.on('proxyRes', (proxyRes) => {
const req = proxyRes.req;
this.requests.push({
method: req.method?.toUpperCase(),
url: `${req.protocol}//${req.host}${req.path}`,
requestHeaders: { ...req.getHeaders() },
responseHeaders: proxyRes.headers,
});
});

this.proxy.listen(port);
console.log(`Proxy listening at ${this.config.host}:${this.config.port} -> ${this.target}`);
}

close() {
this.proxy.close(() => {
console.log(`Proxy stopped at ${this.config.host}:${this.config.port}`);
});
}
}

describe('Proxy', () => {
it('should use http proxy', async () => {
const proxy = new HttpProxyMock(`https://${config.host}`, 9090);
try {
const client = new DBSQLClient();
const clientConfig = client.getConfig();
sinon.stub(client, 'getConfig').returns(clientConfig);

const connection = await client.connect({
host: config.host,
path: config.path,
token: config.token,
proxy: proxy.config,
});

const session = await connection.openSession({
initialCatalog: config.database[0],
initialSchema: config.database[1],
});

expect(proxy.requests.length).to.be.gte(1);
expect(proxy.requests[0].method).to.be.eq('POST');
expect(proxy.requests[0].url).to.be.eq(`https://${config.host}${config.path}`);
} finally {
proxy.close();
}
});
});
2 changes: 1 addition & 1 deletion tests/e2e/timeouts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function openSession(socketTimeout, customConfig) {
});
}

describe('Data fetching', () => {
describe('Timeouts', () => {
const socketTimeout = 1; // minimum value to make sure any request will time out

it('should use default socket timeout', async () => {
Expand Down