From 3ee18ebce74ff778fad02e50a62e9e68bdee99c9 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Mon, 20 Apr 2020 17:54:58 -0500 Subject: [PATCH 1/2] fix: HTTP transport should take a URL --- lib/Connection.js | 4 +--- lib/Deprecated.js | 3 ++- lib/transports/httpTransport.js | 14 +++++++------- test/README.md | 2 ++ test/functional/config.js | 1 + 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index a616a267..490d3292 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -66,11 +66,9 @@ const availableTransports = { * @property {string} [database=*LOCAL] - The database to connect to. Default is ``*LOCAL``. * @property {string} username - The user to connect as. * @property {string} password - The user's password. - * @property {string} [host=localhost] - The hostname of the server. Default is ``localhost``. * @property {string} [ipc=*NA] - The key name/security route to XMLSERVICE job. Default is ``*NA``. * @property {string} [ctl=*here] - The control options for XMLSERVICE jobs. Default is ``*here``. - * @property {number} port=80 - The port on the server. Default is ``80``. - * @property {string} path=/ - The path to xmlcgi endpoint. Default is ``/``. + * @property {string} url - The url to the xmlcgi endpoint. E.g. ``http://localhost:80/cgi-bin/xmlcgi.pgm`` */ /** diff --git a/lib/Deprecated.js b/lib/Deprecated.js index 33d1a27c..9333f80c 100644 --- a/lib/Deprecated.js +++ b/lib/Deprecated.js @@ -564,8 +564,9 @@ class iConn { // pre v1.0 falls back to idb transport when host is not specified if (option.host) { options.transport = 'rest'; + // construct the url host:port/path + options.transportOptions.url = `http://${option.host}:${option.port || 80}${option.path || '/'}`; } - options.transportOptions = { ...options.transportOptions, ...option }; } this.connection = new Connection(options); diff --git a/lib/transports/httpTransport.js b/lib/transports/httpTransport.js index 7bc53582..af29e857 100644 --- a/lib/transports/httpTransport.js +++ b/lib/transports/httpTransport.js @@ -24,9 +24,7 @@ const httpCall = (config, xmlInput, done) => { password = null, ipc = '*NA', ctl = '*here', - host = 'localhost', - port = 80, - path = '/', + url = null, } = config; // perform some validation @@ -45,6 +43,11 @@ const httpCall = (config, xmlInput, done) => { return; } + if (!url || typeof password !== 'string') { + done('Provide a valid url', null); + return; + } + const parms = { db2: database, uid: username, @@ -58,9 +61,6 @@ const httpCall = (config, xmlInput, done) => { const queryString = Object.keys(parms).map((k) => `${k}=${encodeURIComponent(parms[k])}`).join('&'); const options = { - host, - port, - path, method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', @@ -68,7 +68,7 @@ const httpCall = (config, xmlInput, done) => { }, }; - const request = http.request(options, (response) => { + const request = http.request(url, options, (response) => { let xmlOutput = ''; response.on('data', (chunk) => { diff --git a/test/README.md b/test/README.md index 8219a2a5..b309e45d 100644 --- a/test/README.md +++ b/test/README.md @@ -38,6 +38,8 @@ Functional tests can be configured using the following enviornment variables. - `TKPATH` - The path to xmlcgi. Defaults to `/cgi-bin/xmlcgi.pgm` +- `TKURL` - The url to the xmlcgi endpoint. + - `TKPK` - The path to a private key file when using `ssh` transport. - `TKPHRASE` - The passphrase to decrypt the private key. diff --git a/test/functional/config.js b/test/functional/config.js index 1db87625..52a88823 100644 --- a/test/functional/config.js +++ b/test/functional/config.js @@ -15,6 +15,7 @@ const config = { host: process.env.TKHOST || 'localhost', port: process.env.TKPORT, path: process.env.TKPATH || '/cgi-bin/xmlcgi.pgm', + url: process.env.TKURL, privateKey, // passphrase is used by the ssh transport to decrypt the private key passphrase: process.env.TKPHRASE, From 0adde3831cdaf527a138404bc7bf39e5767a02e7 Mon Sep 17 00:00:00 2001 From: Abdirahim Musse <33973272+abmusse@users.noreply.github.com> Date: Wed, 22 Apr 2020 09:46:41 -0500 Subject: [PATCH 2/2] fixup! fix: HTTP transport should take a URL --- lib/transports/httpTransport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/transports/httpTransport.js b/lib/transports/httpTransport.js index af29e857..07fdaf95 100644 --- a/lib/transports/httpTransport.js +++ b/lib/transports/httpTransport.js @@ -43,7 +43,7 @@ const httpCall = (config, xmlInput, done) => { return; } - if (!url || typeof password !== 'string') { + if (!url || typeof url !== 'string') { done('Provide a valid url', null); return; }