Skip to content
Open
29 changes: 23 additions & 6 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -238,6 +252,9 @@ export class HttpClient implements IHttpClient {
return callback(err);
},
);
// Instrumentation
//console.log("REQ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11");
//console.log(req);
return req;
}

Expand Down
23 changes: 23 additions & 0 deletions test/request-response-samples-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"handleNilAsNull": true
"handleNilAsNull": true,
"httpAgent": { "dummyHttpAgent": true },
"ntlm": true
}
85 changes: 85 additions & 0 deletions test/security/NTLMSecurity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down