diff --git a/src/http.ts b/src/http.ts index 961b620d9..d340f7455 100644 --- a/src/http.ts +++ b/src/http.ts @@ -180,12 +180,26 @@ export class HttpClient implements IHttpClient { const options = this.buildRequest(rurl, data, exheaders, exoptions); let req: req.AxiosPromise; if (exoptions !== undefined && exoptions.ntlm) { - const ntlmReq = NtlmClient({ - username: exoptions.username, - password: exoptions.password, - workstation: exoptions.workstation || '', - domain: exoptions.domain || '', - }); + // Instrumeentation + console.log('HTTP requet() EXOPTIONS NTLM!!!!!!!!!!!!'); + console.log(exoptions); + console.log('HTTP requet() OPTIONS NTLM!!!!!!!!!!!!'); + console.log(options); + const ntlmReq = NtlmClient( + { + username: exoptions.username, + password: exoptions.password, + workstation: exoptions.workstation || '', + domain: exoptions.domain || '', + }, + // Change wanted in the OG PR: + //{ httpAgent: exoptions.httpAgent, httpsAgent: exoptions.httpsAgent }, + // A better change per axios-ntlm API? + //options, + ); + // Noisy quick instrumentation + console.log('ntlmReq!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11'); + console.log(ntlmReq); req = ntlmReq(options); } else { if (this.options.parseReponseAttachments) { @@ -238,6 +252,9 @@ export class HttpClient implements IHttpClient { return callback(err); }, ); + // Instrumentation + //console.log("REQ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11"); + //console.log(req); return req; } diff --git a/test/request-response-samples-test.js b/test/request-response-samples-test.js index 07d4a907d..60e4ed134 100644 --- a/test/request-response-samples-test.js +++ b/test/request-response-samples-test.js @@ -145,6 +145,16 @@ tests.forEach(function (test) { generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, responseHttpHeaders, attachmentParts, false); generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, responseHttpHeaders, attachmentParts, true); + + // NTLM + agent tests + wsdlOptions.ntlm = true; + wsdlOptions.httpAgent = () => {}; + options.ntlm = true; + options.httpsAgent = () => {}; + // console.log(wsdlOptions); + + generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, responseHttpHeaders, attachmentParts, false); + generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, responseHttpHeaders, attachmentParts, true); }); function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, responseHttpHeaders, attachmentParts, usePromises) { @@ -156,6 +166,10 @@ function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requ methodCaller = promiseCaller; } + if (wsdlOptions.ntlm || options.ntlm) { + name += ' (ntlm)'; + } + suite[name] = function (done) { if (requestXML) { // Override the expect request's keys to match @@ -210,6 +224,14 @@ function cbCaller(client, methodName, requestJSON, responseJSON, responseSoapHea requestJSON, function (err, json, body, soapHeader) { try { + // Instrumentation + //console.log(client); + console.log(client.httpClient); + //console.log(client.httpClient.options); + //console.log(client.httpClient._request); + //console.log(client.httpClient._request.options); + //console.log(client.httpClient._request._request); + console.log(client.httpClient._request.request); if (requestJSON) { if (err) { assert.notEqual('undefined: undefined', err.message); @@ -277,6 +299,7 @@ describe('Request Response Sampling', function () { server.listen(0, function (e) { if (e) return done(e); port = server.address().port; + console.log('PORT:' + port); done(); }); }); diff --git a/test/request-response-samples/Dummy__should_handle_nil_as_null/wsdl_options.json b/test/request-response-samples/Dummy__should_handle_nil_as_null/wsdl_options.json index 7b3d64f2f..2944c5789 100644 --- a/test/request-response-samples/Dummy__should_handle_nil_as_null/wsdl_options.json +++ b/test/request-response-samples/Dummy__should_handle_nil_as_null/wsdl_options.json @@ -1,3 +1,5 @@ { - "handleNilAsNull": true + "handleNilAsNull": true, + "httpAgent": { "dummyHttpAgent": true }, + "ntlm": true } diff --git a/test/security/NTLMSecurity.js b/test/security/NTLMSecurity.js index a343d2a22..9d5305c0d 100644 --- a/test/security/NTLMSecurity.js +++ b/test/security/NTLMSecurity.js @@ -27,6 +27,91 @@ describe('NTLMSecurity', function () { instance.defaults.should.have.property('ntlm', true); }); + it('should work with httpAgent and ntlm options together', function () { + var options = { + username: username, + password: password, + domain: domain, + workstation: workstation, + ntlm: true, + }; + + var events = require('events'); + var util = require('util'); + var stream = require('readable-stream'); + var duplexer = require('duplexer'); + var httpClient = require('../../lib/http.js').HttpClient; + + function CustomAgent(options, socket) { + var self = this; + events.EventEmitter.call(this); + self.requests = []; + self.maxSockets = 1; + self.proxyStream = socket; + self.options = options || {}; + self.proxyOptions = {}; + } + + util.inherits(CustomAgent, events.EventEmitter); + + CustomAgent.prototype.addRequest = function (req, options) { + req.onSocket(this.proxyStream); + }; + + var httpReqStream = new stream.PassThrough(); + var httpResStream = new stream.PassThrough(); + var socketStream = duplexer(httpReqStream, httpResStream); + + socketStream.cork = function () {}; + socketStream.uncork = function () {}; + socketStream.destroy = function () {}; + socketStream.setKeepAlive = function () {}; + + class MyHttpClient extends httpClient { + constructor(options, socket) { + super(options); + this.agent = new CustomAgent(options, socket); + } + } + + var client = new MyHttpClient(options, socketStream); + options.httpAgent = client.agent; + + var instance = new NTLMSecurity(options); + instance.defaults.should.have.property('username', options.username); + instance.defaults.should.have.property('password', options.password); + instance.defaults.should.have.property('domain', options.domain); + instance.defaults.should.have.property('workstation', options.workstation); + instance.defaults.should.have.property('ntlm', true); + instance.defaults.should.have.property('httpAgent', options.httpAgent); + + // Instrumentation + //console.log(instance); + }); + + it('should work with httpsAgent and ntlm options together', function () { + var ClientSSLSecurity = require('../../').ClientSSLSecurity; + var instance = new ClientSSLSecurity(null, null, null, { ntlm: true }); + + var firstOptions = { forever: true }; + var secondOptions = { forever: true }; + + instance.addOptions(firstOptions); + instance.addOptions(secondOptions); + + firstOptions.httpsAgent.should.equal(secondOptions.httpsAgent); + firstOptions.forever.should.equal(secondOptions.forever); + firstOptions.ntlm.should.equal(secondOptions.ntlm); + firstOptions.ntlm.should.equal(true); + instance.defaults.should.have.property('ntlm', true); + instance.agent.should.equal(firstOptions.httpsAgent); + + // Instrumentation + //console.log(firstOptions); + //console.log(secondOptions) + //console.log(instance); + }); + it('should accept valid variables', function () { var instance = new NTLMSecurity(username, password, domain, workstation); instance.defaults.should.have.property('username', username);