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

Code breaks when algorithm=MD5 key value pair occurs in response headers #15

Open
himanshu219 opened this issue May 28, 2019 · 1 comment

Comments

@himanshu219
Copy link

Sometimes some apis give algorithm=MD5 in the response headers without quotes which breaks the code with below traceback.

// console output of parts array
realm="MMS Public API"
 domain=""
 nonce="7hziqlF0xTs4PbKVmzPlEGq0yZRNiFuY"
 algorithm=MD5
/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107
      if (part.length > 2) {
               ^

TypeError: Cannot read property 'length' of null
    at HTTPDigest.parseChallenge [as _parseChallenge] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:107:16)
    at HTTPDigest.handleResponse [as _handleResponse] (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:39:26)
    at ClientRequest.<anonymous> (/Users/hpal/git/sumologic-mongodb-atlas/sumomongodbatlascollector/functions/mongodbatlascollector/sumoutils/node_modules/http-digest-client/http-digest-client.js:29:12)
    at Object.onceWrapper (events.js:285:13)
    at ClientRequest.emit (events.js:197:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:560:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:113:17)
    at TLSSocket.socketOnData (_http_client.js:447:20)
    at TLSSocket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)

at line number 106 using the following regex fixes the issue
var part = parts[i].match(/^\s*?([a-zA-Z0-0]+)="(.)"\s?$|^\s*?([a-zA-Z0-0]+)=(.)\s?$/);

@ma0dubois
Copy link

Hi,

@himanshu219 i think it's better to use this:

var part = parts[i].match(/^\s*?([a-zA-Z0-0]+)="?(.*)"?\s*?$/);
if (part && part.length > 2) {
    params[part[1]] = (part[2]).replace('"', '');
}

because with your suggestion, the group 1 and 2 can be undefined if the regex match your 2nd group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants