Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ export class HttpClient implements IHttpClient {
password: exoptions.password,
workstation: exoptions.workstation || '',
domain: exoptions.domain || '',
});
}, { httpAgent: exoptions.httpAgent,
httpsAgent: exoptions.httpsAgent,
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove this locally, rebuild the project and run new tests, but for some reason tests still pass.
I would assume it should fail without it.
Do I understand it right? Could you please double check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have a look when I get a chance hopefully soon. It is entirely possible there is a bug in the tests :)

req = ntlmReq(options);
} else {
if (this.options.parseReponseAttachments) {
Expand Down
86 changes: 86 additions & 0 deletions test/security/NTLMSecurity.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,92 @@ 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