Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding initial NTLM support (from https://github.com/vision10/node-soap) #887

Merged
merged 13 commits into from
May 10, 2018

Conversation

insanityinside
Copy link
Contributor

@insanityinside insanityinside commented Oct 12, 2016

Pulling in changes from @vision10 https://github.com/vision10/node-soap (via @r24y https://github.com/r24y/node-soap/ who did some cleanup) into one clean package for a pull request.

This is a revised version of pull #885.

Cleaned up version of #776 and #741, syntax altered to match project. I've tested it against a live NTLM SOAP server, and it seems to work perfectly. Added basic instructions to the README with respect to syntax usage with the other security types, and regenerated TOC.

There is currently a check in http.js in HttpClient.prototype.request which has an if/else for the ntlm property. I suspect there's a better way to do this, but it's how it was done in the original code. Suggestions and pointers welcome, or move code around as appropriate. The code may need refactoring, but it seems reasonable enough to work with for now, and does seem to be functioning correctly.

Also requires tests implementing.

@coveralls
Copy link

coveralls commented Oct 12, 2016

Coverage Status

Coverage decreased (-0.7%) to 92.451% when pulling 2087e05 on microchip:master into 7841b64 on vpulim:master.

@coveralls
Copy link

coveralls commented Oct 31, 2016

Coverage Status

Coverage decreased (-0.7%) to 92.466% when pulling 9782794 on microchip:master into 0b1df30 on vpulim:master.

@coveralls
Copy link

coveralls commented Nov 1, 2016

Coverage Status

Coverage decreased (-0.7%) to 92.466% when pulling 9d062af on microchip:master into 0b1df30 on vpulim:master.

@jsdevel
Copy link
Collaborator

jsdevel commented Nov 1, 2016

@microchip is there a way to add a test?

@insanityinside
Copy link
Contributor Author

I'll take a look. Should be theoretically possible.

@vision10
Copy link
Contributor

vision10 commented Nov 2, 2016

I don't know how to make the test but i can provide anything needed for it

@ryaninvents
Copy link

@microchip thanks so much for helping merge these changes in!

As far as testing, mockrequire looks like it could help here. Feel free to look into it; I may have time to look at this at some point, but probably not for another week or so.

@aijanai
Copy link

aijanai commented Feb 20, 2017

guys, are there news for this?

@insanityinside
Copy link
Contributor Author

@aijanai I've not had chance to do any more with this at work at the moment I'm afraid :(

@coveralls
Copy link

coveralls commented Feb 20, 2017

Coverage Status

Coverage decreased (-0.7%) to 92.383% when pulling b3f3582 on microchip:master into bc6992a on vpulim:master.

@aijanai
Copy link

aijanai commented Feb 20, 2017

@microchip

yes yes, it's perfectly ok, but can it just be merged as it is?
The problem is that there is no sane NTLM support for node anywhere. Packages lying around on NPM are just broken, incomplete or undocumented.

Since this is not breaking anything, could we please just get over the 0.7% coverage drop and release it to the public?

@insanityinside
Copy link
Contributor Author

@aijanai For what it's worth, I'm using the fork I made above in production, and it seems to be working perfectly fine. Haven't tested the latest merges yet, but there's no good reason they wouldn't work.

@aijanai
Copy link

aijanai commented Feb 21, 2017

Uhm. Then there must be something I am seriously doing wrong because it keeps crashing with:

events.js:176
    domain.enter();
           ^

TypeError: domain.enter is not a function
    at Request.emit (events.js:176:12)
    at IncomingMessage.<anonymous> (/home/ai_ja_nai/wd-soap-proxy-lambda/node_modules/request/request.js:998:12)
    at emitOne (events.js:96:13)
    at IncomingMessage.emit (events.js:188:7)
    at IncomingMessage.Readable.read (_stream_readable.js:381:10)
    at flow (_stream_readable.js:761:34)
    at resume_ (_stream_readable.js:743:3)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

My dependencies are:

 "dependencies": {
    "soap": "^0.18.0",
    "soap-ntlm-2": "^0.9.4"
  },
  "devDependencies": {
    "node-soap": "vision10/node-soap"
  },

The code is just this simple 50 lines test script:

var url = process.env.URL
var username = process.env.USER
var password = process.env.PASSWORD
var domain = process.env.DOMAIN

var options = {
      wsdl_options: {
                ntlm: true,
                username: username,
                password: password,
                workstation: "",
                domain: domain
            }
}

var soap = require('soap')

soap.createClient(url, options, function(err, client, body) {
  if(err){
    console.log("ERROR")
    console.log(err)
    return
  }

  client.setSecurity(new soap.NtlmSecurity(options.wsdl_options))

  console.log(client.describe())
})

I took it from the GitHub website and NPM page. Is this how it is supposed to look like?
Many thanks for any help

@insanityinside
Copy link
Contributor Author

@aijanai Wouldn't you need to change the dependency to be microchip/node-soap to use the NTLM merged code? As I said, current code is untested, but I can't see anything that'd immediately break it. (Please note my fork is entirely unsupported, I merged in code changes someone else had made and tidied up a bit, that's it.)

@vision10
Copy link
Contributor

you need to require

var soap = require('soap-ntlm-2'),

not the original soap

@coveralls
Copy link

coveralls commented Apr 3, 2017

Coverage Status

Coverage decreased (-0.7%) to 92.436% when pulling 10a1fa0 on microchip:master into 14aa52c on vpulim:master.

@coveralls
Copy link

coveralls commented Sep 6, 2017

Coverage Status

Coverage decreased (-0.7%) to 92.47% when pulling b92509e on microchip:master into 01d8585 on vpulim:master.

Copy link
Contributor

@herom herom left a comment

Choose a reason for hiding this comment

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

Please, add tests for the new features 👍

lib/http.js Outdated
return callback(err);
}
// if result is stream
if( typeof res.body != 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use !== for strict checl

var _ = require('lodash');

function NTLMSecurity(username, password, domain, workstation) {
if (typeof username == "object") {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use ===

package.json Outdated
@@ -14,6 +14,8 @@
"ejs": "~2.5.5",
"finalhandler": "^1.0.3",
"lodash": "^3.10.1",
"optional": "^0.1.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

where do we need this dependency?

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 have no idea, it came with the original modification. Happy to remove it if it's not used.

}

NTLMSecurity.prototype.addHeaders = function (headers) {
headers.Connection = 'keep-alive';
Copy link
Contributor

Choose a reason for hiding this comment

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

so, is it intentional, that the method addHeaders does not add headers anywhere but sets a Connection property on the (hopefully available) headers param (Object)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks that way, it's in the original code. It works the same way as in BearerSecurity, which I'd guess is what this code is based on.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I see.... hmmm.....

};

NTLMSecurity.prototype.addOptions = function (options) {
_.merge(options, this.defaults);
Copy link
Contributor

Choose a reason for hiding this comment

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

if you call it this way, only options will be mutated, but this.defaults will stay "like it is" - is this really the behaviour you/we want?

@insanityinside
Copy link
Contributor Author

I'm happy to clean up the code where mentioned, but to be honest, it should probably be refactored in order to be properly testable. I currently don't have the time to do it (or the knowledge of this setup, I'm just fixing up what's already here!)

If I get chance to at some point, I'll happily do it, but in the meantime, if anyone can refactor it, I welcome pull requests.

@coveralls
Copy link

coveralls commented Sep 7, 2017

Coverage Status

Coverage decreased (-0.7%) to 92.47% when pulling 6ffce76 on microchip:master into 01d8585 on vpulim:master.

@leonfs
Copy link

leonfs commented Oct 5, 2017

Any idea when this could get merged?

@coveralls
Copy link

coveralls commented Oct 5, 2017

Coverage Status

Coverage decreased (-0.4%) to 93.267% when pulling 5aefa9d on insanityinside:master into 9ea32e2 on vpulim:master.

@herom
Copy link
Contributor

herom commented Oct 6, 2017

@leonfs

Any idea when this could get merged?

We need at least a few tests for the new features in order to merge the PR (see our guidelines on Submitting a Pull Request). As @insanityinside said in his previous comment

I currently don't have the time to do it (or the knowledge of this setup, I'm just fixing up what's already here!)... I welcome pull requests.

A PR over at his fork in order to get things cleaned up and tested is very much appreciated 😺

@benthepoet
Copy link

Just opened a PR at the @insanityinside fork to fix linting issues and added a handful of tests.

@insanityinside
Copy link
Contributor Author

@benthepoet I'll take a look at merging it this evening, then see if I can bring the codebase up to date and merge up. I've not tested it in a bit, but I've got test apps I can run with the updated code.

Fixed linting issues and added unit tests for NTLMSecurity

Haven't had chance to test this yet or rebase it on the live branch, but pulling it in is probably a good start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants